AWS |
lambdaタグが付けられた新着投稿 - Qiita |
【FlutterWeb + AWS API Gateway + Lambda + DynamoDB】FlutterWebでAPIを呼び出した時にXMLHttpRequestエラーが発生した際の対処 |
https://qiita.com/falcon0912/items/144cc621f9502cf25de5
|
OPTIONSの選択は必須※例では自分が作成したAPIはPOST及びGETができるため両方選択している選択後、「CORSを有効にして既存のCORSヘッダーを置換」を選択するLambdaのレスポンスのReturnにHeaderを追加するdeflambdahandlereventcontexttryresponseputdataeventdynamoDBへ値を入れる変数returnstatusCoderesponseResponseMetadataHTTPStatusCodeheadersContentTypeapplicationjsonAccessControlAllowOriginこのヘッダーを追加するbodyresponseexceptExceptionasereturnedefputdataeventあくまで例なので自身のコードに合わせてくださいresponsetableputitemItemaaaeventaaa上記のようにヘッダーを追加し、Lambda内、APIGateway内でテストした後に、FlutterWeb側でもAPIを呼ぶと成功しました。 |
2021-09-19 23:41:39 |
AWS |
lambdaタグが付けられた新着投稿 - Qiita |
Pythonの無名関数(ラムダ式) |
https://qiita.com/Tomo-master1/items/1d553008034aa52b679b
|
足し算を行う関数での例calcadd関数を定義defcalcaddabreturnabそれを実行calcmulticalcmultilambdaというキーワードを使って、その場で関数を記述する無名関数として書くと、このコードは、次のように書けます。 |
2021-09-19 23:30:27 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
ABC183 C - Travel から学んだ |
https://qiita.com/AKpirion/items/4f5eb1d1594b29d93a92
|
行列Tから以下のように値を取り出して足し合わせてKと一致する組み合わせをカウントすれば良い。 |
2021-09-19 23:46:13 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
サイシードプログラミングコンテスト2021(ABC219) A~D問題 ものすごく丁寧でわかりやすい解説 python 灰色~茶色コーダー向け #AtCoder |
https://qiita.com/sano192/items/c5a4b2b936a7c0e6fd70
|
XYなのでdp→dpdpとします以上を実装すると以下のようになります。 |
2021-09-19 23:33:08 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
Pythonの無名関数(ラムダ式) |
https://qiita.com/Tomo-master1/items/1d553008034aa52b679b
|
足し算を行う関数での例calcadd関数を定義defcalcaddabreturnabそれを実行calcmulticalcmultilambdaというキーワードを使って、その場で関数を記述する無名関数として書くと、このコードは、次のように書けます。 |
2021-09-19 23:30:27 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
#0 TypeScriptでTA○IR○Nを作ってみた ~環境構築編~ |
https://qiita.com/sts11142/items/90ac4af41ac7eb0b14ff
|
今回は最近学習をしているTypeScriptのアウトプットのために、とあるパーティー用ゲームを作ってみようと思います。 |
2021-09-19 23:51:28 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
LaravelでControllerからViewに値が渡せない |
https://teratail.com/questions/360348?rss=all
|
LaravelでControllerからViewに値が渡せないちょっと困ったことが起こっており、投稿させていただきました。 |
2021-09-19 23:46:41 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
UGUI上にキャラクターが表示されない |
https://teratail.com/questions/360347?rss=all
|
UGUI上にキャラクターが表示されないRPGのメインメニュー画面で、アニメーションを付けたキャラクターを表示したいです。 |
2021-09-19 23:44:04 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
DjangoアプリをEC2にデプロイしたい |
https://teratail.com/questions/360346?rss=all
|
一方、nginxは過去にインストールしており、nginxnbspvを実行するとnginxnbspversionnbspnginxと表示されたのですが、Linuxサーバーには入れてないけどどうしたらいいかと途方にくれています。 |
2021-09-19 23:42:20 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
マルチエージェントシミュレーションの初期値の設定について |
https://teratail.com/questions/360345?rss=all
|
|
2021-09-19 23:40:28 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Python 二重[]をリスト内包表記で[]にしたい |
https://teratail.com/questions/360344?rss=all
|
Python二重をリスト内包表記でにしたい、実行するとnbspnbspとなり「」といった、を外す方法がないかや、また「」の場合どこに置けばいいかご教授お願い致します。 |
2021-09-19 23:36:07 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Visual Studio Codeでの依存性追加の方法 |
https://teratail.com/questions/360343?rss=all
|
VisualStudioCodeでの依存性追加の方法前提・実現したいことVisualnbspStudionbspCodeでJavaの開発の学習をしています。 |
2021-09-19 23:11:29 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
React 関数の書き方で質問があります |
https://teratail.com/questions/360342?rss=all
|
|
2021-09-19 23:04:41 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Flutter minSdkVersion 16→21 変更時のエラーについて |
https://teratail.com/questions/360341?rss=all
|
androidnbspstudio |
2021-09-19 23:01:57 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
Rails form_select が急にsyntax error になった時のデバッグ |
https://qiita.com/Kanji-Ishii/items/e2d427afbcdf2bd65b64
|
今まで普通に動いていたformselectが急にシンタックスエラーを吐いたのでデバッグしました。 |
2021-09-19 23:49:16 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
orderメソッドを使用して順番を入れ替える! |
https://qiita.com/TAKAHIRO__k/items/6a7e05027a59a935c132
|
orderメソッドを使用して順番を入れ替える結論orderメソッドを使用すれば投稿順を最新や古い物など並べ替えられるという事もっと細かく具体的にいうと、そもそもorderメソッドは、ActiveRecordメソッドですテーブルから取得してきた、複数のレコード情報を持つインスタンスの並び順を変更するメソッドのことですorderメソッドの記述複数のレコード情報を取得する文に続けて以下のように記述しますインスタンスモデル名order並び替えの基準となるカラム名並び順では、この並び順とはASC昇順とDESC降順の種類がありますちなみに種の略は、ASCAscending小さいものから大きいものになる。 |
2021-09-19 23:19:12 |
Linux |
Ubuntuタグが付けられた新着投稿 - Qiita |
Ubuntu コマンド入門 |
https://qiita.com/TakanoTaiga/items/99dc784c932c4171d47f
|
どのフォルダーを開くか的なイメージでOKデスクトップにあるファイルを実行したいならデスクトップのディレクトリに行く必要がある。 |
2021-09-19 23:25:29 |
AWS |
AWSタグが付けられた新着投稿 - Qiita |
【AWS】EC2にMacのターミナルからSSH接続する方法 |
https://qiita.com/wizaqua/items/c8566884260f235760f5
|
今回接続するECはAmazonLinuxです。 |
2021-09-19 23:06:52 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
WindowsでHadoopをビルドしてみる。 |
https://qiita.com/ElCondor24/items/b2d36d80bc7f0f309ac0
|
取得したファイルをWindowsのエクスプローラで以下のパスに配置してください。 |
2021-09-19 23:44:45 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
Node.js使ってdocker-composeでReact環境構築 |
https://qiita.com/Bashi50/items/8086e27c8e356e786227
|
↓Reactの公式ページQuickStartReact起動dockercomposeupを実行するとdockercomposeのcommandshccdreacttestampampyarnstartが実行されるのでreactのアプリを開発サーバーで起動させてくれます。 |
2021-09-19 23:24:48 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
Rails form_select が急にsyntax error になった時のデバッグ |
https://qiita.com/Kanji-Ishii/items/e2d427afbcdf2bd65b64
|
今まで普通に動いていたformselectが急にシンタックスエラーを吐いたのでデバッグしました。 |
2021-09-19 23:49:16 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
railsチュートリアル第五章 スタイルシート |
https://qiita.com/masatom86650860/items/de6672c5fd66d301cf07
|
lightgrayこの機能を使って、SCSSを次のように書き直すことができるlightgrayhcolorlightgrayfootercolorlightgraylightgrayのような変数名は、のような値よりも分かりやすいたとえその変数が繰り返し使われないとしても、変数名を与えることは多くの場合有用ですSassでも同様の変数が使えるようになります。 |
2021-09-19 23:44:29 |
技術ブログ |
Developers.IO |
Amazon CloudWatch SyntheticsでBasic認証が設定されたWebサイトを監視する |
https://dev.classmethod.jp/articles/monitor-websites-with-basic-authentication-with-amazon-cloudwatch-synthetics/
|
amazon |
2021-09-19 14:51:11 |
海外TECH |
DEV Community |
What Happens in Google Summer of Code Final Evaluations |
https://dev.to/rohanlekhwani/what-happens-in-google-summer-of-code-final-evaluations-g9p
|
What Happens in Google Summer of Code Final EvaluationsThe final fence to jump before being called a GSoCer Aiming to be called one Read on For the past months I have been working on the Poll App Mega Extensions project at Rocket Chat as a part of Google Summer of Code I had successfully passed my First Evaluations from my mentor Ramkumar KB The final evaluations are more involved Rocket Chat has a “GSoC Tradition of having students present their projects before the entire Rocket Chat team mentors and other GSoCers I ll also be revealing my proposal pages at the end of this blog post Finally I ll touch upon the future work required within the Poll App in case you re a GSoC aspirant and want to work on it GSoC Final EvaluationsThe first thing GSoC Final evaluations form will ask you is to provide a work product link This can be either in the form of a GitHub Gist a repository or a blog post In all it should summarize your work done PRs and issues opened merged or closed and your experience within the months of GSoC Here s the link to my report ーRohan Lekhwani GSoC Report The next section within the evaluation form is about your GSoC experience This involves questions like “were you able to meet all your goals your favorite and most challenging parts about GSoC number of hours dedicated The data here is probably used by Google to evaluate the popularity and areas of improvement within their program The organization section includes questions as a feedback to Google about the organization I m pretty sure Google uses this section to filter out organizations the next GSoC season from the ones who didn t receive a good feedback The following section is regarding your Growth which focuses whether GSoC helped you get a job or an internship did it improve your programming skills anything else you learned from your GSoC experience The final section includes the “Everything Else section It forms a miscellaneous section asking you whether you d like to be a mentor the next GSoC season any feedback for your organization your answer to this question will be shared with your organization any advice for future GSoC aspirants and suggestions for future GSoCs Both student and mentor evaluations questions can be found here The ones listed here were almost exactly worded as the ones mentioned in the evaluation form Rocket Chat s GSoC TraditionRocket Chat has maintained a streak of getting selected into GSoC since with projects at the least This year Rocket Chat broke records with their highest number of projects getting selected ーa whopping projects In parallel with GSoC final evaluations Rocket Chat organizes an internal “Demo Presentation for all students These presentations are attended by almost the entire Rocket Chat engineering team including the CEO Gabriel Engel and CTO Rodrigo Nascimento It was a real fun experience to showcase my work in front of the community The only question everyone had on mind was “When will it be on the Marketplace xD The entire recording can be viewed at Rocket Chat s YouTube channel Here s the video link In case you re interested in checking out the presentation I ve made it publicly accessible here And Voila I was able to surpass my planned proposal by even including an additonal feature not mentioned earlier ーLate Retrieval of Live Polls Result Google also mentioned since previous year a lot of students were requesting for a completion certificate it ll be provisioning them along with a super secret link to be on Google s watchlist for opportunities If you ve been following along in this blog series you would know I have been maintaining a GitHub Kanban board for my project progress Here s how it looks now Speaking of PRs I ranked up by a position on the GSoC Contribution Leaderboard which Rocket Chat maintains every year at gsoc rocket chat I m ranked th of all the people who contributed The board doesn t include RCGitHub and RCCommunity repositories which if accounted for rank me first Future WorkIt s truly amazing to see all your PRs merged within the main codebase We are currently on track to release Poll App out to the world on Rocket Chat s Marketplace I planned a lot of features as extra deliverables which can be seen in my proposal shared below A super important future work for a GSoC aspirant would be to expand the additional Poll modes feature into templates for Retro Daily Standup All Hands etc This is similar to what Polly offers Another useful feature would be the poll summary feature allowing users to see their configurations before posting the Poll This would result in a lesser number of incorrect and misconfigured polls created As PromisedGSoC aspirant Here s something for you I wrote two proposals for GSoC one was pages and the other one which got selected is pages Apart from that I also created Figma designs for both the projects shared below Poll App Mega Extensions Proposal LinkPoll App Mega Extensions Figma Designs LinkCommunity Collaboration Improvements Proposal LinkCommunity Collaboration Improvements Designs LinkPlanning to apply to the upcoming GSoC Comment your questions doubts or reach out to me Hurray This forms my final bi weekly blog about my GSoC journey at Rocket Chat I ll be continuously writing about what I code and build so if you haven t yet ーhit that follow button on DEV and Medium My previous blog in this sereis was about GSoC Coding Phase go check it out now ーit includes an unexpected climax when you feel everything s going smooth GSoC Coding Phase Challenge Is an UnderstatementLike what I do Help me pull my next all nighter Consider buying me a coffee Rohan Lekhwani is an open source contributor and enthusiast You can connect with him on LinkedIn GitHub Twitter and his website |
2021-09-19 14:22:20 |
海外TECH |
DEV Community |
Sort tables (almost) instantly with Ruby on Rails and StimulusReflex |
https://dev.to/davidcolbyatx/sort-tables-almost-instantly-with-ruby-on-rails-and-stimulusreflex-32d1
|
Sort tables almost instantly with Ruby on Rails and StimulusReflexToday we re going to use Ruby on Rails and StimulusReflex to build a table that sorts itself each time a user clicks on a header column Sorting will occur without a page turn in less than ms won t require any custom JavaScript and we ll build the whole thing with regular old ERB templates and a little bit of Ruby The end result will be very fast efficient simple to reason about and easy to extend as new functionality is required It ll be pretty fancy When we re finished it will work like this You can view the finished product on Heroku or find the full source on Github Before we get dive in the work in this article is inspired by the more full featured Beast Mode StimulusReflex demo application We ll be building a simpler application moving through the implementation step by step but the Beast Mode codebase was vital as I began thinking about how to solve this problem Reviewing that code base is highly recommended as you begin thinking about how to build more scalable production ready code with StimulusReflex This article will be most useful to folks who are familiar with Ruby on Rails you will not need any previous experience with Stimulus or StimulusReflex to follow along If you ve never worked with Rails before some concepts here may be a little tough to follow Let s get started SetupAs usual we ll start with a brand new Rails application with Tailwind and StimulusReflex installed Tailwind is not a requirement but it helps us make our table look a little nicer and the extra setup time is worth the cost If you d like to skip the copy pasting setup steps you can clone down the example repo and skip ahead to the Building the Table section The main branch of the example repo is pinned to the end of the setup process and ready for you to start writing code If you re going to follow along with the setup first from your terminal rails new player sorting Tcd player sortingbundle add stimulus reflexbundle add fakerrake stimulus reflex installrails g model Team name stringrails g scaffold Player name string team references seasons integerrails db migrateAssuming you ve got Rails and Yarn installed this will produce a brand new Rails application at the time of this writing install StimulusReflex and scaffold up the Team and Player models that we ll use to build our sortable table If you don t care to use Tailwind for this article feel free to skip past this next section Tailwind is a convenient way to make things look presentable but if you just want to focus on sorting the table without any styling Tailwind is not necessary If you want to install Tailwind start in your terminal yarn add tailwindcss latest postcss latest autoprefixer latestnpx tailwindcss initmkdir app javascript stylesheetstouch app javascript stylesheets application scssAnd then update tailwind config js module exports purge app html erb app helpers rb app javascript js app javascript vue app javascript react darkMode false theme extend variants extend plugins And postcss config js module exports plugins require tailwindcss tailwind config js require postcss import require postcss flexbugs fixes require postcss preset env autoprefixer flexbox no stage Next we ll update app javascripts stylesheets application scss to import Tailwind import tailwindcss base import tailwindcss components import tailwindcss utilities And then include that stylesheet in app javascripts packs application js import stylesheets application scss Finally update the application layout to include the stylesheet generated by webpacker lt stylesheet pack tag application data turbolinks track reload media all gt Whew We re through the setup and ready to start building Building the tableFirst up let s get our bearings The core of our application is the Players resource We are going to construct a table that displays all of the players in our database with the players name their team s name and their seasons played as columns We ll only use the Team model created during setup in the context of Players so we don t need a controller or views for teams We ll start by moving the table from the players index view to a partial From your terminal touch app views players players html erbAnd fill that partial in with lt div id players class shadow overflow hidden rounded border b border gray gt lt table class min w full bg white gt lt thead class bg gray text white gt lt tr gt lt th id players name class text left py px uppercase font semibold text sm hover cursor pointer gt lt span gt Name lt span gt lt th gt lt th id players team class text left py px uppercase font semibold text sm hover cursor pointer gt lt span gt Team lt span gt lt th gt lt th id players seasons class text left py px uppercase font semibold text sm hover cursor pointer gt lt span gt Seasons lt span gt lt th gt lt tr gt lt thead gt lt tbody class text gray gt lt players each do player gt lt tr gt lt td class text left py px gt lt player name gt lt td gt lt td class text left py px gt lt player team name gt lt td gt lt td class text left py px gt lt player seasons gt lt td gt lt tr gt lt end gt lt tbody gt lt table gt lt div gt Most of the markup here is Tailwind classes for styling the table The functionally important pieces are the ids set on the wrapper div players and the ids set on the table header cells These ids will be used later to update the DOM when the user clicks to sort the table Next update the index view to use the new partial lt div class max w xl mx auto mt gt lt render players players players gt lt div gt With these changes in place we have a nice looking table ready to display the players in the database but we don t have any players Since we re going to be sorting let s make sure the database has plenty of data in it Copy this into db seeds rb Dallas Mavericks LA Clippers LA Lakers San Antonio Spurs Boston Celtics Miami Heat New Orleans Pelicans each do name Team create name name end times do Player create name Faker Name name team Team find Team pluck id sample seasons rand endAnd then from your terminal rails db seedNow start up your Rails server and head to localhost players If all has gone well you should see a table populated with randomly generated players Next up we ll build our sorting mechanism with StimulusReflex Sorting with StimulusReflexTo sort the table we re going to create a reflex class with a single action sort When the user clicks on a table header we ll call the reflex action to sort the players and update the DOM We ll start by generating a new Reflex From your terminal rails g stimulus reflex TableThis generator creates both a reflex in app reflexes and a related Stimulus controller in app javascripts controllers For this article we won t make any modifications to the Stimulus controller Instead we ll focus on the reflex found at app reflexes table reflex rbFill that reflex in with class TableReflex lt ApplicationReflex def sort players Player order element dataset column element dataset direction morph players render partial players locals players players endendThe first line of sort is a standard Rails ActiveRecord query In it we retrieve all of the players from the database ordered by attributes sent from the DOM when the reflex action is triggered Reflex actions have access to a variety of properties In our case the property we re interested in is element element is a representation of the DOM element that triggered the reflex and it includes all of the data attributes set on that element accessible via element dataset This means that in reflex actions we can always access data attributes from the element that triggered the reflex as if we were working with that element in JavaScript Handy For our purposes we care about two data elements that don t yet exist in the DOM ーcolumn and direction The ActiveRecord query to retrieve and order players uses those values to know which column to order the results by and in which direction ascending or descending the results should be ordered After we ve retrieved the ordered list of players from the database we use a selector morph to update the DOM replacing the content of the players partial we created earlier with the updated list of players Our reflex is built but there s no way for a user to trigger the reflex Let s add that next In the players partial update the header row like this lt tr gt lt th id players name class text left py px uppercase font semibold text sm hover cursor pointer data reflex click gt Table sort data column name data direction asc gt lt span gt Name lt span gt lt th gt lt th id players team class text left py px uppercase font semibold text sm hover cursor pointer data reflex click gt Table sort data column teams name data direction asc gt lt span gt Team lt span gt lt th gt lt th id players seasons class text left py px uppercase font semibold text sm hover cursor pointer data reflex click gt Table sort data column seasons data direction asc gt lt span gt Seasons lt span gt lt th gt lt tr gt Here we ve updated each header cell with the three data attributes we need for the reflex to be triggered and to run successfully First data reflex is used to tell StimulusReflex that this element should trigger a reflex when some action occurs In our case it will be called on click Each cell also gets a unique data column value which we use to sort the players result by the matching database column Finally each header cell also starts with a direction of asc which is used to set the direction of the order query Let s look at the Reflex code again and review what s happening now that we ve updated the DOM to call this reflex def sort players Player order element dataset column element dataset direction morph players render partial players locals players players endThe sort method we ve defined matches the name of the data reflex on each header cell When the header cell is clicked this reflex will run The header cell that that the user clicks will be passed to the reflex as element giving us access to the element s data attributes which we access through element dataset Once the value of players is set by the database query we use a selector morph to tell the browser to update the element with the id of players with the content of the players partial using the updated reordered list of players This is the magic of StimulusReflex in action With just a couple of data attributes and a few lines of simple Ruby code our users can now click on a table header and in lt ms they ll see a table sorted to match their request Refresh the page and try it out for yourself If all has gone well clicking on a header cell should sort the table by that column in ascending order While this is nice we have a few more items to address before our work is complete Next up we ll address an error with the order query and then finish this article by modifying the sort reflex to allow users to sort in both ascending and descending order and display visual feedback to indicate what column is being sorted Fixing an ordering errorFirst sharp eyed readers might have noticed that sorting by the team name column doesn t work yet Each header cell s column data attribute matches a column in the database so we can generate the order query dynamically This works fine for the name and season because those columns live on the Players table ActiveRecord knows how to order by name and seasons without any extra effort For the team name column we re passing teams name to the order call in our query which ActiveRecord trips over with an error like this The text will vary depending on the database adapter you re using Reflex Table sort failed SQLite SQLException no such column teams nameWe can fix this by updating the query slightly players Player includes team order element dataset column element dataset direction Here we added includes team to the existing order query making the Teams table accessible in the order clause and fixing the “no such column error that was thrown when attempting to sort by team name Note that joins instead of includes would also fix the error but since we need to use team name when we render the players partial to display each player s team includes is the better choice Before moving on you ll notice that we are using user accessible values to generate a SQL query ーanyone can modify data attributes in their browser s dev tools Prior to Rails this could have opened up our application to SQL injection however since Rails Rails will raise an error automatically if anything but a table column name a sort direction are passed in to order Adding descending orderingWith the work we ve done so far sorting the table works great as long as the user only wants to sort in ascending A Z order Since the sort direction is read from a data attribute that is always “asc there is no way to sort in descending Z A order Let s add that functionality next Before jumping in to the code let s outline the desired user experience When a user clicks on a column header the table should be sorted by that column in ascending order When the user clicks on the same column header again the table should be sorted by that column in descending order And then we alternate forever between ascending and descending on subsequent clicks Sorting by a different column should always sort in ascending order on the first click Here s a gif of what we re aiming for To achieve the desired user experience we need to track the next sort direction for each header cell so that when the sort reflex is called the right direction can be sent to the order query To do this we re going to take advantage of CableReady s tight integration with StimulusReflex We ll update the sort reflex to include a cable ready operation that changes the direction data attribute of the element that triggered the reflex To do this update TableReflex like this def sort snip set sort directionendprivatedef next direction direction direction asc desc asc enddef set sort direction cable ready set dataset property selector element id name direction value next direction element dataset direction endHere we ve added two private methods to the TableReflex class next direction is a simple helper method that takes the current value of direction and returns the next value set sort direction is more interesting In it we use CableReady s set dataset property operation to set the value of the element s direction data attribute to the value of next direction Finally we call set sort direction in the sort reflex which adds the set dataset property operation to the queue each time the sort reflex runs With this in place refresh and click on the same column multiple times to see that each click reorders the table toggling between ascending and descending order Order of operations Not just for math classBefore moving on it is important to pause and think about how this code works When a reflex includes CableReady operations a specific order of operations is always followed First broadcasted CableReady operations execute Next StimulusReflex morphs execute Finally CableReady operations that are not broadcasted execute that s our set dataset property operation Because the StimulusReflex morph runs before the CableReady operation each table header cell has its direction data attribute reset to asc when sort is triggered This behavior lets us “reset sort directions when moving between columns without having to add logic in the partial Immediately after the StimulusReflex morph set dataset property runs and updates the value of direction on the currently active sort column If we appended broadcast to the set dataset property operation the direction property would be updated before the StimulusReflex morph causing the CableReady update to be overwritten by the morph breaking the ability to sort in descending order This order of operations is important to understand and helps unlock a new level of functionality within reflexes Before moving on now that we understand the order of operations in reflex actions we can use that knowledge to make a small optimization to the sort reflex We know that every time the reflex runs each header cell will have its data direction value set to asc before the active sort column is updated by the CableReady set dataset property operation Since the value of data direction is already asc if the next sort direction is asc set dataset property won t do anything useful Let s update sort to skip the CableReady operation in that case def sort snip set sort direction if next direction element dataset direction desc endNow set sort direction will only be run when necessary simplifying our DOM updates at the cost of slightly more complexity in our ruby code Let s finish up our sortable table implementation by adding a visual indicator to the table when sorting is active Sort direction visualsTo indicate which column is being sorted and in which direction we ll draw a triangle with CSS with an upward pointing triangle indicating ascending order and a downward triangle indicating descending order Only the column that is being used for sorting will display the icon When we re finished the indicator will look like this Let s start with the CSS We ll insert the CSS directly into our main application scss file to keep things simple sort position absolute top px left rem width height border left px solid transparent border right px solid transparent sort desc border top px solid fff sort asc border bottom px solid fff We ll use the base sort class along with a dynamic sort asc or sort desc to display the sort indicator If you re interested in how this CSS works this is a nice introduction to drawing shapes with CSS With the CSS ready next we ll create a partial to render the indicator from your terminal touch app views players sort indicator html erbAnd fill that in with lt div class relative gt lt span class sort sort lt direction gt gt lt span gt lt div gt Nothing fancy here just appending the local direction variable to the class name to ensure our triangle points in the right direction We ll finish up by updating the sort reflex to insert the sort indicator into the DOM again relying on a CableReady operation that runs immediately after the StimulusReflex morph class TableReflex lt ApplicationReflex def sort snip insert indicator end private snip def insert indicator cable ready prepend selector element id html render partial players sort indicator locals direction element dataset direction endendHere we added another private method to the reflex to handle inserting the sort indicator when the sort reflex is called insert indicator uses CableReady s prepend operation to insert the content of the sort indicator partial into the DOM before the target element s first child With this in place we can refresh the page and see the sort indicator added each time the sort reflex runs pointing up for ascending sorts and down for descending sorts An implementation noteDuring this article I made a choice to use cable ready operations to add the sort indicator and update the data attribute Instead of cable ready operations another approach would be to assign instance or local variables for things like active column and next direction during the sort reflex We could then read those variables when rendering the players partial using them to render the sort indicator and set the next sort direction This approach would allow us to eliminate the cable ready operations however doing so would complicate the view Either approach is fine my personal preference is to rely on the very fast cable ready operations to simplify the view Using cable ready also has the added benefit of letting us talk more about how StimulusReflex works which is a bonus in a tutorial article like this one As you spend more time with StimulusReflex experiment with different approaches and find what works best for you Wrapping upToday we built a sortable table interface with Ruby on Rails StimulusReflex and CableReady Our table is fast updates efficiently is easy to extend and is no where near production ready yet What we built today was part one of a two part series Next up we ll extend the sortable table by adding filtering and pagination getting closer to the full featured implementation seen in Beast Mode While there are numerous ways to implement a sortable table interface for Rails developers StimulusReflex is worthy of strong consideration SR s fast efficient mechanisms for updating and re rendering the DOM including bypassing ActionDispatch s overhead with selector morphs allow us to sort and render the updated table extremely quickly with minimal code complexity or additional mental overhead Its tight integrations with CableReady and Stimulus combine into an extremely powerful tool in any Rails developers kit To go further into StimulusReflex and CableReady Spend time reviewing the Beast Mode codebaseReview StimulusReflex patterns for thoughtfully designed solutions in StimulusReflex including filterable for working with complex sorting and filtering requirementsJoin the StimulusReflex discord and connect with other folks building cool stuff with StimulusReflex CableReady and RailsThat s all for today as always thanks for reading |
2021-09-19 14:03:38 |
海外TECH |
DEV Community |
What is Machine Learning and How it Works |
https://dev.to/codewithshahan/what-is-machine-learning-and-how-it-works-5010
|
What is Machine Learning and How it WorksMachine Learning which is a subset of A I or Artificial Intelligence It s one of the trending topics in the world these days and it s going to have a lot of application in the future ️What is Machine Learning Machine learning is the study of computer algorithms that can improve automatically through experience and by the use of data It is a branch of artificial intelligence based on the idea that systems can learn from data identify patterns and make decisions with minimal human intervention Here is a real example Imagine I asked you to write a program to scan an image until if it s a cat or a dog If you want to build this program or software using traditional programming techniques your program is going to get overly complex You will have to come up with lots of rules to look for a specific curves edges and colors in an image to tell if it s a cat or a dog But if I give you a black and white photo your rules may not work This may break your program and you ll have to rewrite them with different rules or I give you a picture of a cat or a dog from different angle that you did not predict before So solving this problem using traditional programming techniques is going to get overly complex or sometimes impossible Now to make the matter worse What if in the future I ask you to extend this program such that it supports three kinds of animals CatsDogs or HorsesOnce again you ll have to rewrite all those rules That s not gonna work So machine learning is a technique to solve these kind of problems How Machine Learning Works First we build a model or an engine and give it lots and lots of data For example we give thousands or tens of thousands of pictures of cats and dogs in this engine Our engine will then find and learn patterns in the input data So we can give it a new picture of a cat that it hasn t seen before and ask it Is it a cat or a dog or a horse It would tell us with a certain level of accuracy the more input data we give it the more accurate our engine is going to be Uses of Machine LearningMachine learning is used in internet search engines email filters to sort out spam websites to make personalized recommendations banking software to detect unusual transactions and lots of apps on our phones such as voice recognition Also Machine learning has other applications in self driving cars robotics language processing vision processing forecasting things like stock market trends and the weather games on so on Vision Computer vision is the process of understanding digital images analyzing and extraction of data from the real world to produce information Forecasting It involves taking models fit on historical data and using them to predict future observations i e to smooth or remove noise Conclusion Machine Learning is a branch of artificial intelligence that provides computer systems the ability to automatically learn and improve from experience without being explicitly programmed So that s the basic idea of machine learning Machine Learning in seconds If you like my article and this explanation video make sure to subscribe to my Youtube Channel to help me create more content like this Feel free to leave a comment Follow me on TwitterGithub |
2021-09-19 14:03:01 |
Apple |
AppleInsider - Frontpage News |
MacBook Pro & AirPods 3 still expected in 2021, new AirPods Pro in 2022 |
https://appleinsider.com/articles/21/09/19/macbook-pro-airpods-3-still-expected-in-2021-while-airpods-pro-update-set-for-2022?utm_medium=rss
|
MacBook Pro amp AirPods still expected in new AirPods Pro in Apple is still planning to bring out new Macs and AirPods before the end of a report claims but users may have to wait until for other major product debuts to occur Apple s California Streaming event saw the introduction of the iPhone range as well as updates to the iPad iPad mini and Apple Watch Series With those launches in progress attention now draws to what Apple will unveil next In Sunday s Bloomberg Power On newsletter Mark Gurman claims there are still some products set to be unveiled in with new MacBook Pro models and AirPods anticipated to launch soon Apple is rumored to be employing a two event strategy for following s three events Read more |
2021-09-19 14:59:57 |
海外TECH |
Engadget |
Cadillac's inaugural Lyriq EV sold out of reservations in 19 minutes |
https://www.engadget.com/cadillac-lyriq-debut-edition-ev-sold-out-141406753.html?src=rss
|
Cadillac x s inaugural Lyriq EV sold out of reservations in minutesCadillac didn t have any problems finding buyers for its Lyriq EV once reservations opened As Electreklearned GM s luxury badge sold out of reservations for the Lyriq s Debut Edition in minutes The brand didn t say how many people paid the fee but it s clear there was at least some pent up demand for the upscale electric crossover More Debut Edition models will be available through dealers in summer Deposits don t always translate to final sales when the fee is refundable Some people may reserve a car only to back out when it comes time to make the final purchase For context though VW took eight hours to sell a quot few thousand quot units of the ID First Edition The overall number might be small but minutes is extremely quick The sellout wasn t completely unexpected While the Lyriq is still an expensive EV with a nearly starting price it promises a healthy plus miles of range kW fast charging and a sprawling inch infotainment display There s also a clear pattern of strong demand for EVs from familiar names Ford for instance is boosting F Lightning production after demand far outstripped early manufacturing targets There s clearly an audience for EV like these even if they re still far from dominating their combustion engine counterparts That was fast Every all electric LYRIQ Debut Edition has now been reserved To learn more about LYRIQ visit pic twitter com vOKUbkMrーCadillac Cadillac September |
2021-09-19 14:14:06 |
ニュース |
BBC News - Home |
Aukus: Australia defends role in security pact amid French condemnation |
https://www.bbc.co.uk/news/world-australia-58616759?at_medium=RSS&at_campaign=KARANGA
|
agreement |
2021-09-19 14:05:51 |
ニュース |
BBC News - Home |
Only Fools and Horses actor John Challis dies aged 79 |
https://www.bbc.co.uk/news/uk-58617114?at_medium=RSS&at_campaign=KARANGA
|
horses |
2021-09-19 14:54:29 |
ニュース |
BBC News - Home |
Lib Dems: Give parents Covid catch-up vouchers to spend |
https://www.bbc.co.uk/news/uk-politics-58614679?at_medium=RSS&at_campaign=KARANGA
|
conference |
2021-09-19 14:45:51 |
ニュース |
BBC News - Home |
BBC 'extremely sorry' over loss of murdered girl's clothes |
https://www.bbc.co.uk/news/uk-58615829?at_medium=RSS&at_campaign=KARANGA
|
bashir |
2021-09-19 14:50:38 |
北海道 |
北海道新聞 |
鈴木優磨が今季初ゴール ベルギー1部リーグ |
https://www.hokkaido-np.co.jp/article/591026/
|
初ゴール |
2021-09-19 23:02:00 |
北海道 |
北海道新聞 |
バレー中垣内監督退任へ 男子日本代表 |
https://www.hokkaido-np.co.jp/article/591025/
|
中垣内祐一 |
2021-09-19 23:02:00 |
コメント
コメントを投稿