投稿時間:2021-11-11 02:41:52 RSSフィード2021-11-11 02:00 分まとめ(45件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… スクエニ、「ファイナルファンタジーV」のピクセルリマスター版を配信開始 https://taisy0.com/2021/11/11/148574.html 開始 2021-11-10 16:26:08
AWS AWS Game Tech Blog Enabling Quest 2 AR/VR on EC2 with NICE DCV https://aws.amazon.com/blogs/gametech/enabling-quest-2-ar-vr-on-ec2-with-nice-dcv/ Enabling Quest AR VR on EC with NICE DCVAs AR VR becomes more prevalent companies are starting to work within the cloud to develop test and deliver real time AR VR environments for their customers To meet this demand AR VR companies must ensure that they have a performant solution for headset users AWS provides multiple avenues to achieve this kind of solution by utilizing HPC infrastructure … 2021-11-10 16:57:52
AWS lambdaタグが付けられた新着投稿 - Qiita AWS(api gateway, lambda, SES, S3)を用いてお問い合わせフォーム付きウェブサイトを作成する https://qiita.com/NNNiNiNNN/items/b524fe3fe69e6de839de SESへのメールアドレスへの登録lambdaを用いてメールの送信用の関数を作成今回はPythonで行ったapigatewayへのlambda関数の登録apiを叩くためのwebサイトの作成作成したwebサイトをS上にアップロードし、公開する。 2021-11-11 01:00:50
js JavaScriptタグが付けられた新着投稿 - Qiita 今から始めるRedux x React x TypeScript https://qiita.com/it_tsumugi/items/e917ab8e984f802ed69b reducerリデューサーactionを受け取り、actionの内容に対応したstateへの変更を行う関数dispatchreducerにactionを渡すための関数selectorstateから必要なデータを抽出し、加工する処理をする関数ReactRedux公式がだしているReact用のreduxライブラリReduxToolkit公式が出しているReduxのベストプラクティスが詰まっているライブラリsliceスライスreduxtoolkitのcreateSlice関数によって生成されるreducerとactioncreatorを含むオブジェクトimmutablilityイミュータビリティデータを変更するのではなく、新しいデータを生成することでのみデータを入れ替えることが出来る性質immerimmutabaleなコードを楽に書けるライブラリReduxを学ぶ必要性Reduxは年月現在Reactで最も使われている状態管理ライブラリです。 2021-11-11 01:52:16
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) 【Laravel】config:cacheしてしまって500エラーを解消したい。 https://teratail.com/questions/368750?rss=all 【Laravel】configcacheしてしまってエラーを解消したい。 2021-11-11 01:29:22
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) IDを付けずにオブジェクトを操作 https://teratail.com/questions/368749?rss=all 2021-11-11 01:17:11
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) linux環境下におけるPythonインストール時に利用するフォルダの役割について知りたい。 https://teratail.com/questions/368748?rss=all linux環境下におけるPythonインストール時に利用するフォルダの役割について知りたい。 2021-11-11 01:06:52
AWS AWSタグが付けられた新着投稿 - Qiita AWS(api gateway, lambda, SES, S3)を用いてお問い合わせフォーム付きウェブサイトを作成する https://qiita.com/NNNiNiNNN/items/b524fe3fe69e6de839de SESへのメールアドレスへの登録lambdaを用いてメールの送信用の関数を作成今回はPythonで行ったapigatewayへのlambda関数の登録apiを叩くためのwebサイトの作成作成したwebサイトをS上にアップロードし、公開する。 2021-11-11 01:00:50
海外TECH Ars Technica The Toyota RAV4 Prime is a pleasing plug-in hybrid SUV https://arstechnica.com/?p=1811823 hybrid 2021-11-10 16:24:05
海外TECH Ars Technica Scientists extend and straighten iconic climate “hockey stick” https://arstechnica.com/?p=1811732 history 2021-11-10 16:00:29
海外TECH MakeUseOf 7 Habits That Will Boost Your Writing Productivity https://www.makeuseof.com/habits-that-boost-writing-productivity/ productivity 2021-11-10 16:45:37
海外TECH MakeUseOf Visual Studio Code vs. Atom: Which Text Editor Is Right for You? https://www.makeuseof.com/tag/visual-studio-code-vs-atom/ editor 2021-11-10 16:30:23
海外TECH MakeUseOf Monitor Calibration Made Easy With These 5 Online Tools https://www.makeuseof.com/tag/5-online-tools-calibrate-monitor/ calibration 2021-11-10 16:30:23
海外TECH MakeUseOf How to Request a Refund on a Discord Purchase https://www.makeuseof.com/discord-how-to-get-refund/ How to Request a Refund on a Discord PurchaseRegret a Discord purchase Don t worry it s easy to get a refund but you ll need to act quickly Here s how to refund anything on Discord 2021-11-10 16:30:22
海外TECH MakeUseOf Apple M1 vs. M1 Pro vs. M1 Max: How Fast Are Apple's New Chips? https://www.makeuseof.com/apple-m1-vs-m1-pro-vs-m1-max/ original 2021-11-10 16:15:22
海外TECH DEV Community Tutorial on Chartist.js and custom tooltips. https://dev.to/jringeisen/tutorial-on-chartistjs-and-custom-tooltips-2lje Tutorial on Chartist js and custom tooltips The Chartist JavaScript library provides a high level API to draw charts in various ways It makes it easy to create the most common types of charts and with its simple configuration options you can get beautiful results quickly In this tutorial we ll create a chart from scratch step by step You can also take a look at the codesandbox example for this tutorial to see the final result This tutorial assumes that you have some basic knowledge of HTML and JavaScript but no prior experience with Chartist js SetupTo get Chartist working with your project you ll need to import the Chartist js files lt link rel stylesheet href cdn jsdelivr net chartist js latest chartist min css gt lt script src cdn jsdelivr net chartist js latest chartist min js gt lt script gt Make sure to add these between the lt head gt lt head gt tag The charts will render as SVG which means they scale infinitely and can be printed or animated for use in infographics or presentations Next you ll need to add the following snippet of code in the body of your html lt div class ct chart gt lt div gt And finally you ll need the javascript var data A labels array that can contain any sort of values labels Mon Tue Wed Thu Fri Our series array that contains series objects or in this case series data arrays series Create a new line chart object where as first parameter we pass in a selector that is resolving to our chart container element The Second parameter is the actual data object new Chartist Line ct chart data This is the bare minimum of what you need to start working with Chartist pretty simple right I was recently working on a project where I needed a tooltip to display every time I hovered over a point and it needed to display the series data Chartist has a tooltip plugin but I found this plugin to have a lot of issues and it didn t work well for me so I decided to implement my own tooltip Let s discuss customizing our chart and then I will cover how to create and customize a tooltip Customizing ChartistHere is what we re going to build A stats card that displays a chart of daily user signups To build this I m using Tailwindcss for styling you can build your own classes and use those but I love Tailwind so I m using it The HTML lt div class relative w mx auto mt h bg white rounded md overflow hidden overflow y scroll shadow gt lt div class p w full gt Daily Users lt div gt lt div class absolute w full ct chart gt This part is important We will cover this when we customize the tooltip lt div class hidden absolute inline block chartist tooltip bg white text xs shadow text center px py rounded md w gt lt span class chartist tooltip meta gt lt span gt lt br gt lt span class chartist tooltip value gt lt span gt lt div gt lt div gt lt div gt Our series or chart data var data series meta value meta value The meta and value will display in the tooltip The value is what s used to create the line on the chart Next are the chart options var options extends the chart the full width of the div fullWidth true removes any padding chartPadding options for the x axis axisX the chart was display outside the card to fix that we move it up with the offset offset turns off the grid showGrid false turns off the labels showLabel false options for the y axis axisY no offset was needed so we set it to offset turns off the grid showGrid false turns off the labels showLabel false Handeling the tooltip new Chartist Line ct chart data options on draw function data We only want the tooltip to apply to the point if data type point What want the tooltip to display on mouseenter so we listen for that event data element node addEventListener mouseenter e gt I m getting the tooltip by its class name const tooltip document getElementsByClassName chartist tooltip This is how we re setting the position of the tooltip This will set the top of the tool tip tooltip style top data y px This will set the left of the tooltip What this does is if you re on the right side of the card the tooltip display left of the cursor if you re on the left side of the card the tooltip displays right of the cursor tooltip style left data x gt data x px data x px Here we re removing the hidden class so that the tooltip will display tooltip classList remove hidden This gets the tooltip meta div const meta document getElementsByClassName chartist tooltip meta This sets the data for the meta information on the tooltip meta innerHTML data meta This gets the tooltip value div const value document getElementsByClassName chartist tooltip value This sets the data for the value value innerHTML data value y data value y view data value y views here we re listening for when the mouse leaves and when it does we add the class hidden to hide the tooltip data element node addEventListener mouseleave e gt const tooltip document getElementsByClassName chartist tooltip tooltip classList add hidden Conclusion and SummaryChartist js is a javascript library that makes it simple to create beautiful charts using HTML canvas without requiring any knowledge of how JavaScript works under the hood With Chartist you can get away with only knowing basic HTML and CSS syntax while your data automatically turns into professional looking charts While Chartists doesn t have any pre made chart types built in you can always customize one to fit your needs by combining multiple elements in unique ways 2021-11-10 16:44:47
海外TECH DEV Community Building a Dot Matrix Animator https://dev.to/fitzgeraldkd/building-a-dot-matrix-animator-4edm Building a Dot Matrix AnimatorWhenever I start learning a new skill I like to come up with a project I can use to apply the skill test my knowledge and push myself to find areas where I need to improve As helpful as tutorials and walkthroughs are I find that I always get the most experience when I can struggle through a project I start from scratch and apply the knowledge I ve learned without explicit instructions I decided to write this blog about my first Ruby project because I really enjoyed this project and think the results are pretty cool I won t get into the details about the code here but it is all available on my GitHub The IdeaThe idea I came up with was to write a program that creates a dot matrix animation based on input images Here were my goals for the project The user can provide any number of images for the animationEach image acts as a keyframe in the animationThe user can specify the size of the dot matrix rows columns and dot size The user can specify how long each keyframe is displayed as well as how long the transition between keyframes lastsThe user will receive an animation based on the inputs where dots are rendered on each frame with a size that relates to the pixel s colorFor the purpose of having a set of images to start with I made some simple bitonal vector images of my initials I will be using these three images as the keyframes for my test animation The ImplementationBefore writing the code I wanted to come up with a plan so I could determine which tools I should implement Here s what I came up with Process the input imagesReduce the image size down to the dot matrix size so one pixel is represented by one dot processing a full size image would take longer use more memory and provide no benefit For each pixel in the image determine the size a dot would need to be to represent a close approximation of the shade tintInterpolate between keyframes so the dots sizes transition smoothly Generate frames of the GIF animationRender a dot for each pixel with a size based on the pixel s colorSave the final GIF file Processing the Input ImagesTo accomplish this project I knew I would need some way to process the input images Resizing the images was the easy bit The more complex and more important task was to find the best way to relate a pixel s color in the source image to a dot s size in final animation I felt that the relative luminance as described in this W accessibility document was a logical property to use in this case and can be easily calculated with a color s RGB components After determining what tasks I needed to fulfill I determined that the RMagick library would be a good choice for this project Rendering a GIFSince I already decided to use RMagick to process the images it makes sense to continue using it to generate a new GIF file for the animation as well Luckily most of the process is pretty straightforward Create an instance of the ImageList class a class defined in the RMagick library to hold each frame of the animationFor each frame Create an instance of the Image class also from RMagick Provide a background colorFor each pixel dot Draw a circle in the corresponding location with a radius determined by the relative luminanceAdd the Image instance to the ImageListProvide a duration for how long the Image just added should last this allows us to pause longer on a keyframe compared to the transitional animation frames Save the ImageList instance to a gif fileThe more challenging piece is the transition between keyframes To do this I decided to write a method that would generate a new weighted average image between two keyframes As time progresses the weight will shift towards the end keyframe to allow me to interpolate and generate a frame at any point in time This new image can then be processed just like the keyframes Below is an image demonstrating what I need to accomplish With any of these transitional images a new frame can be processed to create a frame of the dot matrix animation The ClassesWith a library selected and a plan set I had to determine how to actually write the program Leaning more towards an object oriented approach I decided I wanted to use three classes An Animation class that holds most of the information logic for the animation as a wholeA Frame class that holds the data for a single image in the animationA Dot class that holds the information for a single dot pixel in an imageWhen the program is initiated it creates an instance of the Animation class It then resizes all of the input images down to the desired dot matrix size and adds them to an array in the Animation instance The next step is to create Frame instances for each keyframe and all the transitional frames Then each pixel of each Frame is used to instantiate a Dot which is then used to render the animation This is a bit of a simplification but the source code is available on my repository on GitHub for those who want to dive a little deeper The InterfaceI wanted to provide a command line interface for the user that was easy to use and I also wanted to provide the flexibility with the options used to render the animation After looking around online I found that Thor was a good tool to utilize It allowed me to easily create a number of options that make this program much more versatile An example below shows how a user can select which folder the source images are in as well as what the background and foreground colors should be bin run render gif subfolder demo bg color black fg color redThere are more options than that as well and a default value is provided for each one There is also a separate Ruby file that holds all the defaults to make it easy for a user to set their own preferences The ResultsI m really proud of the results I was able to get the program to do exactly what I was looking for and I enjoy seeing the animation For the first example here are three images I used as keyframes one image for each of my initials After using these images in the script here is the animation I got Awesome After seeing the results for a very simple bitonal image I wanted to see how it looked for more complex examples I decided to generate a static dot matrix with a width of pixels for these examples I used this black amp white photo of the Eiffel Tower by Lisa BR on Unsplash and ran my script to see some nice results I also tried it out on this photo of a dog and a pumpkin by Nathan Guzman on Unsplash and saw similarly promising results Obviously a lot of detail was lost since the original pictures were almost pixels in width each and were being reduced to pixels also all color is removed but all things considered I think the results are great The pumpkin next to the dog may not be recognizeable at this resolution and with the absense of color but other than that both images still retain enough detail to be made sense of The FutureHere s a few things I d like to add in the future Have the foreground background colors be dynamically set by the dominant colors in the source imageProvide the option to generate an SVG instead of or in addition to a GIFAllow an animated GIF to be an input image and have each frame be processed it currently reads only a single frame from animated GIFs I hope you found this project as interesting as I did I had a lot of fun making it and feel a lot more comfortable with Ruby s syntax after going through it Thanks for reading 2021-11-10 16:44:30
海外TECH DEV Community Transform tabular data with composable workflows https://dev.to/neuml/transform-tabular-data-with-composable-workflows-3lh4 Transform tabular data with composable workflowsThis article is part of a tutorial series on txtai an AI powered semantic search platform txtai executes machine learning workflows to transform data and build AI powered semantic search applications txtai has support for processing both unstructured and structured data Structured or tabular data is grouped into rows and columns This can be a spreadsheet an API call that returns JSON or XML or even list of key value pairs This article will walk through examples on how to use workflows with the tabular pipeline to transform and index structured data Install dependenciesInstall txtai and all dependencies We will install the api pipeline and workflow optional extras packages pip install txtai api pipeline similarity CSV WorkflowThe first example will transform and index a CSV file The COVID Open Research Dataset CORD is a repository of medical articles covering COVID This workflow reads the input CSV and builds a semantic search index The first step is downloading the dataset locally Get CORD metadata file wget head metadata csv gt input csv tail metadata csv gt gt input csvThe next section creates a simple workflow consisting of a tabular pipeline The tabular pipeline builds a list of id text tag tuples that can be easily loaded into an Embeddings index For this example we ll use the url column as the id and the title column as the text column The textcolumns parameter takes a list of columns to support indexing text content from multiple columns The file input csv is processed and the first rows are shown from txtai pipeline import Tabularfrom txtai workflow import Task Workflow Create tabular instance mapping input csv fieldstabular Tabular url title Create workflowworkflow Workflow Task tabular Print rows of input csv via workflowlist workflow input csv Computer simulation of the dynamics of a spatial susceptible infected recovered epidemic model with time delays in transmission and treatment None Understanding the Potential Role of Abrocitinib in the Time of SARS CoV None Can the concept of Health Promoting Schools help to improve students health knowledge and practices to combat the challenge of communicable diseases Case study in Hong Kong None Buying time for an effective epidemic response The impact of a public holiday for outbreak control on COVID epidemic spread None The SARS CoV spike LR EQ variant in the Indian B strain showed significant reduction in the neutralization activity of immune sera None Next we take the workflow output build an Embeddings index and run a search query from txtai embeddings import Embeddings Embeddings with sentence transformers backendembeddings Embeddings method transformers path sentence transformers paraphrase mpnet base v Index subset of CORD datadata list workflow input csv embeddings index data for uid in embeddings search insulin title text for url text in data if url uid print title uid Importance of diabetes management during the COVID pandemic Position Statement on How to Manage Patients with Diabetes and COVID Successful blood glucose management of a severe COVID patient with diabetes A case report The example searched for the term insulin The top results mention diabetes and blood glucose which are a closely associated terms for diabetes JSON Service WorkflowThe next example builds a workflow that runs a query against a remote URL retrieves the results then transforms and indexes the tabular data This example gets the top results from the Hacker News front page Below shows how to build the ServiceTask and prints the first JSON result Details on how to configure the ServiceTask can be found in txtai s documentation from txtai workflow import ServiceTaskservice ServiceTask url method get params tags None batch False extract hits workflow Workflow service list workflow front page highlightResult author matchLevel none matchedWords value withzombies title matchLevel none matchedWords value An opinionated guide on how to reverse engineer software url matchLevel none matchedWords value tags story author withzombies story front page author withzombies comment text None created at T Z created at i num comments objectID parent id None points story id None story text None story title None story url None title An opinionated guide on how to reverse engineer software url Next we ll map the JSON data using the tabular pipeline url will be used as the id column and title as the text to index from txtai workflow import Task Recreate service applying the tabular pipeline to each resultservice ServiceTask action tabular url method get params tags None batch False extract hits workflow Workflow service list workflow front page An opinionated guide on how to reverse engineer software None As we did previously let s build an Embeddings index and run a search query Embeddings with sentence transformers backendembeddings Embeddings method transformers path sentence transformers paraphrase mpnet base v Index Hacker News front pagedata list workflow front page embeddings index data for uid in embeddings search cloud title text for url text in data if url uid print title uid How Temporal Workload Shifting Can Reduce Carbon Emissions in the Cloud Hetzner Cloud Goes US Ashburn VA Hetzner cloud servers are now available in Ashburn USA XML Service workflowtxtai s ServiceTask can consume both JSON and XML This example runs a query against the arXiv API transforms the results and indexes them for search Below shows how to build the ServiceTask and prints the first XML result service ServiceTask url method get params search query None max results batch False extract feed entry workflow Workflow service list workflow all aliens OrderedDict id updated T Z published T Z title If Loud Aliens Explain Human Earliness Quiet Aliens Are Also Rare summary If life on Earth had to achieve n hard steps to reach humanity s level nthen the chance of this event rose as time to the n th power Integrating this nover habitable star formation and planet lifetime distributions predicts gt nof advanced life appears after today unless n lt and max planet duration n lt Gyr That is we seem early We offer this explanation a deadline is set by n loud aliens who are born according to a hard steps power law expand at a ncommon rate change their volumes appearances and prevent advanced life like nus from appearing in their volumes Quiet aliens in contrast are much nharder to see We fit this three parameter model of loud aliens to data nbirth power from the number of hard steps seen in Earth history birth nconstant by assuming a inform distribution over our rank among loud alien birth ndates and expansion speed from our not seeing alien volumes in our sky We nestimate that loud alien civilizations now control of universe volume neach will later control x galaxies and we could meet them in nMyr Gyr If loud aliens arise from quiet ones a depressingly low ntransition chance is required to expect that even one other quiet nalien civilization has ever been active in our galaxy Which seems bad news for nSETI But perhaps alien volume appearances are subtle and their expansion nspeed lower in which case we predict many long circular arcs to find in our nsky author OrderedDict name Robin Hanson OrderedDict name Daniel Martin OrderedDict name Calvin McCarter OrderedDict name Jonathan Paulson arxiv comment OrderedDict xmlns arxiv text To appear in Astrophysical Journal link OrderedDict href rel alternate type text html OrderedDict title pdf href rel related type application pdf arxiv primary category OrderedDict xmlns arxiv term q bio OT scheme category OrderedDict term q bio OT scheme OrderedDict term physics pop ph scheme Next we ll map the XML data using the tabular pipeline id will be used as the id column and title as the text to index from txtai workflow import Task Create tablular pipeline with new mappingtabular Tabular id title Recreate service applying the tabular pipeline to each resultservice ServiceTask action tabular url method get params search query None max results batch False extract feed entry workflow Workflow service list workflow all aliens If Loud Aliens Explain Human Earliness Quiet Aliens Are Also Rare None As we did previously let s build an Embeddings index and run a search query Embeddings with sentence transformers backendembeddings Embeddings method transformers path sentence transformers paraphrase mpnet base v Index Hacker News front pagedata list workflow all aliens embeddings index data for uid in embeddings search alien radio signals title text for url text in data if url uid print title uid Calculating the probability of detecting radio signals from alien civilizations Field Trial of Alien Wavelengths on GARR Optical Network Aliens on Earth Are reports of close encounters correct Build a workflow with no code The next example shows how one of the same workflows above can be constructed via API configuration This is a no code way to build a txtai indexing workflow Index settingswritable trueembeddings path sentence transformers nli mpnet base v Tabular pipelinetabular idcolumn url textcolumns title Workflow definitionsworkflow index tasks task service action tabular url method get params tags null batch false extract hits action upsertThis workflow connects to the Hacker News API gets the data for the front page and indexes it The workflow configures the same actions that were configured in Python previously Let s start an API instance killall uvicorn CONFIG workflow yml nohup uvicorn txtai api app amp gt api log amp sleep cat api logINFO Started server process INFO Waiting for application startup INFO Application startup complete INFO Uvicorn running on Press CTRL C to quit Next we ll execute the workflow txtai has API bindings for JavaScript Java Rust and Golang But to keep things simple we ll just run the commands via cURL Execute workflow via API call curl X POST http localhost workflow H accept application json H Content Type application json d name index elements front page An opinionated guide on how to reverse engineer software null How X Window Managers Work and How to Write One null What is the inverse of a vector null Hetzner cloud servers are now available in Ashburn USA null Zig monthly October Games gamedev Elixir tools and more null Hetzner Cloud Goes US Ashburn VA null Using Zig s translate C to understand weird C code null Show HN A generator of Fake Italian Coffee names null Useless Specks of Dust Turn Out to Be Building Blocks of All Vertebrate Genome null High fidelity remote communication null Nazca New GUI for the Web null Microcentury null DownThemAll null How Temporal Workload Shifting Can Reduce Carbon Emissions in the Cloud null Are daily standups hurting your team null Automation Leverage null The boring technology behind a one person Internet company null It s time for Americans to buy less stuff null Beyond Whiteboarding Creating Expert System Architecture Diagrams null Covid How the virus spreads among vaccinated people null The data is now indexed Note that the index configuration has an upsert action Each workflow call will insert new rows or update existing rows This call could be scheduled with a system cron to execute periodically and build an index of top stories on Hacker News over time Now that the index is ready let s run a search Run a search curl X GET http localhost search query cloud amp limit H accept application json id score id score id score Add a translation step to workflowNext we ll recreate the workflow adding one additional step translating the text into French before indexing This workflow gets the top results from Hacker News translates the results and builds an semantic index of titles in French Index settingswritable trueembeddings path sentence transformers nli mpnet base v Tabular pipelinetabular idcolumn url textcolumns title Translation pipelinetranslation Workflow definitionsworkflow index tasks task service action tabular url method get params tags null batch false extract hits action translation args fr action upsert killall uvicorn CONFIG workflow yml nohup uvicorn txtai api app amp gt api log amp sleep cat api logINFO Started server process INFO Waiting for application startup INFO Application startup complete INFO Uvicorn running on Press CTRL C to quit Same as before we ll run the index workflow and a search Execute workflow via API call curl s X POST http localhost workflow H accept application json H Content Type application json d name index elements front page gt dev null Run a search curl X GET http localhost search query nuage amp limit H accept application json id score id score id score Wrapping upThis notework demonstrated how to transform index and search tabular data from a variety of sources txtai offers maximum flexibility in building composable workflows to maximize the number of ways data can be indexed for semantic search 2021-11-10 16:34:41
海外TECH DEV Community Tmux Tutorial for Beginners https://dev.to/iggredible/tmux-tutorial-for-beginners-5c52 Tmux Tutorial for Beginners IntroTmux is life That is not an exaggeration Once you started using Tmux you will ask yourself why you have not used it until now What Tmux IsAccording to man tmux Tmux stands for Terminal MUltipleXer Before you get perPLEXed by the phrase Terminal MUltipleXer I ll explain what it means A terminal multiplexer lets you to leave a terminal in the middle of a process and return to it seamlessly For example suppose that you are running a rails server vim editor and a mysql console in the middle of a rails workflow Then someone asks you to debug a completely different node project Without tmux I would probably stop the rails server close vim and exit the mysql server before starting the node project task This context switch causes a grinding halt in your flow What if instead of killing those rails related processes you can put them aside while they re still running run whatever processes you need to complete your node task then return to your original rails project task as if you never left That would be nice wouldn t it Tmux lets you do just that To be fair you could argue that you could just open more tabs for node tasks instead of killing the previous rails processes Although that would work this could cause tab chaos At some point you ll start asking which of these tabs did I just run the jest test or which of these two Vim tabs was my rails codebase When you start mixing tabs from completely unrelated tasks without clear boundaries you can t tell which tab is for what This also causes a grinding halt to your workflow The terminal is the crux of my workflow I need to organize my terminal Imagine this I can contain all my rails processes inside a session named rails project and all my node processes in a session named node project If I need to do node tasks I ll leave rails project and visit node project session When I m done I ll leave node project and revisit rails project Easy Tmux allows me to create any number of terminals from a single screen and group them I can detach them and they will still continue running in the background The best part I can attach them at any time Tmux is great for long term running processes and local development Don t you want to learn how to do that too Why Do I Want to Use Tmux Over time the number of process dependencies you need to get a job done increases Today it is often not enough to have just two terminals one for running rails server and one for running vim to accomplish your task In reality you probably need a rails server a webpacker a sidekiq a redis instance and a growing number of microservices to launch your app In addition you may need to have mysql console and rails console to see what s inside your app You may even need a dedicated terminal to run your tests Don t forget that SSH window to get the sql dump too Even if you have docker compose to host multiple services if you need to debug them you ll need multiple terminals to debug each service My point is a simple task today would require more than different active processes It makes it harder to switch context Even if you don t need to switch context often it is still useful to categorize your sub workflows within your workflow Maybe today you are focusing on writing tests so you need to use vim and a free terminal to run your test code they would need to fit inside a display The next day you may need to solve a data migration issue so you need a vim editor a mysql server to view your databases and a rails console to check your models Within a single project you can still experience a grinding halt when trying to accomplish a different task The point is you need to reduce the frictions caused by context switching in today s increasingly complex tasks Tmux can help with that What to Expect From This GuideUltimately you decide whether you want to use tmux or not You don t have to use tmux There are alternatives like GNU Screen Terminator Byobu etc Check them out and you decide whether or not to use tmux Personally I think tmux is a better fit for my workflow I am writing this guide to share what I understand about tmux I hope that you will learn one or two useful things Here is what you will learn in this guide SessionsWindowsPanesServersBasic configsBy the end of this article you will be faster than you would ever be without tmux Hopefully you will learn enough to continue pursuing learning tmux on your own just like the proverbs say Teach a man tmux you improve his productivity for a lifetime someone probably Please read this guide slowly It is tempting to speed read through a book call it done and move on to the next book To get the most out of this take your time understanding each section For every minutes you spend reading spend minutes tinkering around with what you just read Break things With that said let s learn some tmux InstallationFirst you need to install tmux if you haven t already A good way to visit the tmux repository I am using a Mac so for me I just needed to run brew install tmuxCool Verify that it is installed Run which tmux It should return with a path Now that tmux is installed let s learn tmux s cornerstone sessions Tmux SessionsA tmux session is a collection of pseudo terminals Imagine running different terminal processes each doing different things All these terminals are contained in a neat space that you can leave unattended and revisit at any time Creating a New SessionLet s use it Run the command tmuxThis will launch a new tmux session If you re still unsure about the tmux session don t worry I initially had a hard time grasping the concept too It would become much easier once I started getting immersed in it So let s continue Attaching and Detaching a SessionTo exit a session you need to d etach Press Prefix dHold up what is a Prefix I don t see any prefix key on my keyboard The prefix key can be anything you want Many tmux shortcuts require you to press a prefix key first If you re a Vim user it is similar to the concept of a leader key Think of it like a key to signal tmux that you are executing a tmux command By default tmux uses Ctrl b as the Prefix key From now each time you see Prefix it means Ctrl b hold Ctrl then press b In this case Prefix d means holding Ctrl then press b then release them then quickly press the letter d Later you ll learn how to change the prefix key from Ctrl b to any key you want If you do it correctly you should be taken out of the tmux session back to the original terminal When you re detaching from a session any process running in that session is not terminated It s still running You just don t see it Think of it like a background job Let s stop and appreciate how awesome this is On a regular terminal if we close the tab whatever process that we were running would be terminated immediately If I had rails server running and I close the tab the rails server process would be killed But if we detach from a session with rails server running the rails server is still there You are hiding the current process so you can focus on a different one Later when you re ready to resume you can unhide the rails server session by attaching into it To attach from the terminal run tmux attachAaannd you re back Cool The command line equivalent to detach Prefix d is tmux detach Named SessionWith tmux you can liberally generate as many sessions as you need Right now we have only one session running To generate more sessions you first need to be on the regular terminal not inside a session This time though let s give our session a name It s around breakfast time as I type this so let s name it breakfast session you can give it any name you want D Type tmux new s breakfastThe alternative verbose command is tmux new session s breakfast but I like to keep it short With that you should be in the tmux breakfast session Yum While you re inside the breakfast session recall that we also have the original session running To see a list of sessions and travel between sessions run Prefix sNow let s detach from whatever session you are in and go back to the regular terminal you re not inside any session We now have two detached sessions the original session and the breakfast session So how do we attach to a particular session from the terminal Earlier we ran the tmux attach to attach to the only available tmux session Now that there are two sessions we need to be more specific First if you re forgetful like me and already forgot the name of your sessions you can list the name of all the sessions by runningtmux lsIf I want to attach to the breakfast session run the attach command with t target followed by the session name tmux attach t breakfastNow I m back to the breakfast session Tmux is smart enough that you can give it a partial string So if I run tmux attach t b as long as I don t have any session starting with b other than breakfast tmux knows that I intend to go to breakfast Think of sessions like terminal containers Modern development usually requires you to launch multiple services and jobs just to get the app running For example maybe the app that you re working on requires a redis server a rails server two node services and a background job You can use a session to contain all of those processes This makes your workflow manageable and identifiable If you ever need to leave them to work on something else no need to kill them just detach it do whatever else you need to do and re attach Killing a SessionOnce you re done with the session task you can kill that session There are two ways to kill a session Run the terminal command to kill a sessionClose all the windows until there is no moreI ll start with method To kill the breakfast session run this from the terminal tmux kill session t breakfastThe kill session command needs a target t and a session name that you want to kill Note the t target argument is similar to the attach t command In tmux anytime you have multiple targets and you need to pinpoint a single abstraction like a session name you probably need to pass it a target t plus the target name Anyway running tmux kill session t breakfast will effectively kill that session Note killing a session terminates all processes inside it make sure that you save all your changes The second method is to kill all the panes and windows inside a session until there is nothing left We will go over panes and windows in a little bit For now just follow along To kill a pane press Prefix xIf you do that to every single pane and window upon closing the last pane in the last window in a session the session is effectively killed An alternative shortcut to Prefix x is Ctrl dIt does the same thing as Prefix x Personally I prefer Ctrl d because it only requires two keypresses as opposed to Prefix x Tmux Sessions ConclusionWe are done with tmux sessions Let s recap what we learned We learned that a session is like a container to a set of terminals You can Create a session in tmux with tmux new s MY SESSIONDetach from a session with Prefix d or tmux detachList sessions with tmux lsAttach to a session with tmux attach t MY SESSIONList sessions and switch to a different session with Prefix sKill a session with tmux kill session t MY SESSIONClose a pane window with either Ctrl d or Prefix xIf you are new to tmux let this soak in Take time to internalize this Practice practice practice Don t rush to the next one It s better to go at a slower pace but to retain more than go at full speed but forget almost everything When you re ready let s learn about tmux windows Tmux WindowsTmux windows are subsets of tmux sessions When you re creating a new tmux session tmux new s MY SESSION what you re seeing is technically a tmux window Earlier I said that a tmux session is like a container of terminals While that was true each terminal activity happens inside a window So technically a tmux session is a container for tmux windows You can have as many windows as you want in a session Since a window contains a terminal on its own you can have a window dedicated for running your application server another window for logging and another window for text editing Many tmux window commands are conceptually similar to the session commands You can create delete and switch windows just to name a few I won t go through every single tmux window operation because in my opinion you can be very productive just by learning only a few of them Creating a New WindowYou can only create a new window from inside a tmux session Since it s almost lunch time at the time I wrote this let s start a new lunch session From the regular terminal not from inside tmux create a new session This should look familiar tmux new s lunchCool You re inside a session named lunch You re looking at a tmux window When you create a new session tmux automatically creates a new window So right now there is one window the default window in the lunch session To create a new window inside a session run this command tmux new window n fried riceThis creates a new window named fried rice I had that earlier this week If the new window command is too verbose you can shorthand it a bit with neww Let s create a new window named ramen because I m craving that right now tmux neww n ramenPractically speaking though I almost never use the new window terminal command of the time I use the following new window keyboard shortcut Prefix cTry creating two or three new windows Get this in your muscle memory Window creation is one of the most often used commands in my tmux workflow Switching WindowsBy now you should have multiple windows in a session Let s learn how to quickly switch windows Right now I have three windows the default windowfried rice windowramen windowI am currently on the first window If I want to go to the n ext window I can do that with Prefix nRetrospectively to go to the p revious window Prefix pAnother thing to know is that tmux window is indexed like an array data structure In many programming languages an array data structure is zero indexed Tmux window is also zero based The first window is window number the second window window number etc To go to window number N you can run Prefix NWhereas N is the window number So if I want to go to the first window Prefix will do it What if I want to go to the second window Prefix Third window Prefix In my regular workflow I try to keep my window collections small Normally I don t have more than tmux windows in any session if I have more it can quickly get out of control However people s workflows are different You may function better by having dozens of windows in any session Use whatever works for you If that s the case how can you quickly jump to window number The Prefix N shortcut only accepts one key When you try to do Prefix the th window tmux thinks you re doing Prefix To quickly jump to double window digits you can use Prefix NWhereas N is the window number First press the prefix Then press a single quote This lets you enter any window index number like Then press Return I forget things a lot my wife can vouch for that D I can hardly keep track of the windows I have opened in the current session I definitely can t keep track of all the windows across all my sessions if I have multiple sessions running Luckily you can quickly list and switch to any window in any session with Prefix wWhen you do Prefix w tmux lists all the windows inside all the sessions you have even the windows from detached sessions Try it I also use this command a lot Renaming WindowsA window name is used to identify what the window is about It s good to give it a succinct name If I m debugging a controller test then I ll create a new window named controller test yes not original but it s concise However sometimes your task changes The controller test task may morph into feature test shudders In this case you may want to rename your window To rename the current window Prefix Your cursor is now on the lower window area where you can edit the window name Deleting WindowsWhen you re done with a window you may want to delete it so it doesn t crowd your session There are two ways to kill a window kill the window with a terminal commandkill all panes inside a windowFor method you can run this from inside a window tmux kill windowThis kills the current window you re in If you want to kill a different window you can pass a target option to the command t To kill the ramen window tmux kill window t ramenFor a less verbose option you can use killw instead of kill window tmux killw t fried riceFor the second method you can run Prefix xOrCtrl d Tmux Windows ConclusionWe are done with tmux windows Let s recap A window is where your terminal lives A session consists of one or more windows Some window commands that we learned Create a window with tmux new window n MY WINDOW or Prefix cSwitch to a different window with Prefix n Prefix p and Prefix N where N is the window index number zero based Kill a window with tmux kill window t MY WINDOW Close a pane window with either Ctrl d or Prefix xAs always take your time to internalize this Practice what you ve learned about windows and sessions Try to create several windows navigate between them and delete them Create a new session and create some new windows there too Don t rush When you re ready it s time to learn about tmux panes Tmux PanesEarlier I said that when you started a new session what you saw was a tmux window I lied again What you saw was actually a tmux pane inside a tmux window inside a tmux session When you started a new session tmux automatically created a new window When a new window was created tmux generated a new pane Just like how a tmux session has at least one window a tmux window always contains at least one tmux pane Now that we ve been exposed to sessions windows and panes let s get the terminology straight A tmux window is a container to tmux panes A tmux session is a container to tmux windows When you start a session you have at least one tmux window Inside a session you can create many windows Prefix c Inside a tmux window you have at least one tmux pane When you split a window for the first time you are splitting it into two panes Each boxed terminal is a pane in its own right The hierarchy goes like this Session gt window gt pane Let s go through some tmux pane operations Creating a New PaneIf you own tablets or large smart phones they probably have a feature to split the screen in half so you can open two apps simultaneously Panes are similar such that you can split the screen vertically or horizontally so you can have multiple terminals in a single window A tmux window can be split many times into smaller panes The command to split a window horizontally is tmux split window hTo split it vertically tmux split window vThey are rather easy to remember h for h orizontal and v for v ertical To split a window horizontally with a keyboard shortcut Prefix To split a window vertically Prefix Split windows are also one of my most frequently used tmux commands Commit them to your muscle memory Deleting a PaneTo delete a pane is similar to deleting a window Prefix xOrCtrl dThis is our third time seeing Prefix x and Ctrl d Now you finally understand what this command actually does It deletes a pane When the last pane of a window is deleted that window is automatically removed When the last window of a session is deleted that session is automatically killed Navigate Between PanesLet s learn the different ways to navigate between panes First create multiple panes in a window Use the Prefix or Prefix amp shortcut to do that To switch to the next pane run Prefix oTmux focuses on a different pane each time you run that command You can also move directionally with Prefix UpPrefix DownPrefix LeftPrefix RightThese commands give you slightly more control Now you can instruct tmux which direction you want to focus on But that s not all Tmux can also display all the pane numbers of the current window for you to select from Run Prefix qYou should see numbers displayed in the foreground center of each pane If you type a particular number tmux will focus on that pane number So if I want to go to pane number I just run Prefix q To go to pane number run Prefix q Btw you could also have done this with tmux display panestmux select pane t NThe first command lists all the panes and the second command jumps to pane number N I personally would rather to Prefix q N Ain t nobody got time to type all that Resize a PaneI usually have about panes in a window But you may need to adjust their sizes For example the other day I had to debug a controller spec I had the tmux window split horizontally into two panes top and bottom I had Vim on the top window and the terminal on the bottom for running the specs By default tmux splits them equally but I prefer to have Vim to have more screen real estate To resize a pane you can run one of the followings tmux resize pane D tmux resize pane U tmux resize pane L tmux resize pane R The number is a measurement unit tmux cells The D U L R options stand for Down Up Left Right Unfortunately there are no keyboard shortcuts for this You can create your own shortcuts to make resizing quicker I ll show you how to do that in a later section Zoom a PaneAnother feature I find helpful is pane zooming If you have four panes displayed in a window each taking up of that window total area you can zoom your current pane into and hide the other panes with Prefix zNow it looks as if you only have a single pane allowing you to view the current pane at maximum area This is useful if you need to remove distractions and focus on a specific task at a specific pane Then once you re done you can de zoom and return to the previous layout by running Prefix z one more time Swapping PanesIf you have two panes in a window side by side you can swap them with Prefix Prefix You can also rotate the pane positions with Prefix Ctrl o Tmux LayoutsWhile we are discussing panes let s learn about tmux layouts because they are closely related Wait a minute what are tmux layouts Good question Tmux layouts are pane arrangements to organize your panes in a window Tmux comes with five ready to use layouts If that description is ambiguous and you re still confused don t worry Just follow along and you ll understand it soon enough Create a new window Then split it horizontally once Prefix Then split it vertically once Prefix Your window should now have three panes one half on the left and a quarter on top right and a quarter on bottom right Let s go back to layouts Tmux comes with different layouts even horizontaleven verticalmain horizontalmain verticaltiledLet s try them Type tmux select layout even horizontalNote how your tmux window is now split horizontally evenly Just like the name says the even horizontal layout re arranges the current panes into equidistant horizontal panes Let s try the vertical one tmux select layout even verticalLet s try a different flavor tmux select layout main verticalYour tmux window is now split horizontally with the main pane taking up more space while the other two panes are split evenly taking up less window real estate Let s try the horizontal version tmux select layout main horizontalFinally let s see what the last one looks like tmux select layout tiledNow your tmux window is split equally If you had panes it wouldn t exactly be split evenly but if you had panes it would split them perfectly equal You can toggle tmux layouts with a keyboard shortcut Press Prefix SpaceThe first time you press Prefix space tmux goes to even horizontal layout then it goes to even vertical layout then main horizontal etc It cycles between those five layouts Tmux Panes ConclusionLet s go over what we learned You learned about tmux pane A pane is where your sub terminals are displayed through A window can have one or more panes Here are the commands you learned Split a window horizontally with tmux split window h or Prefix Split a window vertically with tmux split window v or Prefix Delete a pane with Prefix x or Ctrl dNavigate to the next pane with Prefix oNavigate to another pane directionally with Prefix Up Down Left RightNavigate to pane number N with Prefix q NResize a pane by N unit with tmux resize pane D U L R NZoom de zoom a pane with Prefix zSwap panes with Prefix or Prefix and rotate panes with Prefix Ctrl oToggle layouts with tmux select layout even horizontal even vertical main horizontal main vertical tiled or Prefix SpaceTmux pane is a unique feature that differentiates tmux from most regular terminals Usually to start a new terminal you need to open a new tab But what if you need to have two terminals side by side With tmux you can easily split a window into two or more panes You can even organize how the panes are displayed As always take your time to digest what you just learned Play around Create multiple panes in a window then navigate around them Delete some panes Resize them Zoom in and out Change the layouts Combine this lesson with what you ve learned Create a new session Create a few new windows with multiple panes in them See how fast you can go from the current pane to another pane in a different window from a different session Do this until you can navigate around effortlessly Take as much time as you need When you are ready let s learn about tmux servers Tmux serversBy now you should have a good idea what tmux can do You should also understand how sessions windows and panes relate otherwise stop and review the last three sections There is one more missing piece tmux servers Although you can do fine merely knowing about sessions windows and panes without knowing about tmux servers it is good to know the whole picture to have a more accurate mental model Understanding tmux server will explain why some commands like tmux kill server exist to kill the server duh When we run the command tmux tmux not only creates a new session but it also creates a new server instance This whole ecosystem that you have been interacting with you can think of it like the client in client server interaction If it is like a client server interaction then there must be a tmux server somewhere Tmux server is what runs in the background while Tmux client runs in the foreground When we create multiple sessions tmux new s breakfast tmux new s lunch and tmux new s dinner those three are connected to the same tmux server Since we don t mention a server name these sessions are connected to a default server To launch a named server let s name it the food server run this from the regular terminal tmux L foodThis creates a new server named food Running this command also launches a new session by default Cool Let s detach from this server Prefix d So we have a food server running somewhere in your machine but you are detached from it What if you want to reconnect to the food server Run tmux L food attachYou ll be reattached to the food server Wait a minute this looks like the attach command from way earlier when we only had one session tmux attach It s because it is The difference is that we are attaching back to a session from the food server instead of the default server Running tmux L food creates a default session inside the food session What if we want to create a named session To create a new named session inside the food server say a roast duck session we can run tmux L food new s roast duckRecall that running tmux ls will list the sessions from the default server But what if we want to view all the sessions in the food server Easy run tmux L food lsIf we want to attach to the roast duck session in the food server run tmux L food attach t roast duckFinally to kill this food server you can run tmux L food kill serverThe kill server command kills a server When a server is killed it kills everything inside it sessions windows and panes make sure that you save everything before closing it By the way to kill the default unnamed server just run tmux kill serverIf you run tmux kill server when nothing is running you ll see no server running on private tmp tmux defaultYour exact path might be different from what I have but the important ideas are The command kill server is looking in the tmp directory which is usually where linux sockets are Wait did you say socket That sounds like a client server interaction The directory is named default because we tried to kill the default server By the way if you created multiple servers you ll find all those server names stored in here So if you created a food server you would find food in there too Phew That s a lot to take in Let s practice what we just learned to solidify what we just learned Do the following Create new tmux servers give them any name you want Inside each server create multiple sessions Inside each session create multiple windows Inside each window create multiple panesDetach from one server and attach to the other oneDelete the serversPractically speaking I almost never use more than one server in my workflow However your use case might be different Regardless it wouldn t hurt to know The more you know the less you don t know Customizing tmuxIn my opinion tmux could use a better set of keys For example I find that using the Ctrl b keys are not comfortable Let s change some key shortcuts You can modify tmux keys with the tmux config file When you launch tmux it looks for a file named tmux conf in the HOME path in my case it is tmux conf If it isn t there yet create a file tmux conf in your HOME path Let s change the tmux prefix Some of the popular prefix alternatives are Ctrl aCtrl Space Ctrl s Ctrl u Backticks Tab key variation instead of Ctrl keyetcPersonally I use Ctrl Space mainly because my Vim leader key is the Space key But ultimately use whatever keys that make the most sense to you To change your prefix to Ctrl Space add these in the tmux config file unbind C Spaceset g prefix C Spacebind C Space send prefixThe changes above won t take place immediately You first need to source the file You can either close tmux kill your tmux session and start a new one or source the config file To source tmux config file from inside a tmux session run tmux source file tmux confBy the way in the future I would like to be able to source my configurations quickly with Prefix r Add this in the config file bind key r source file tmux conf display message Tmux config reloaded Don t forget to restart the tmux session Now you can just run Prefix rTo quickly source your file By the way with some changes you may notice that even running Prefix r isn t enough You need to also restart the tmux server Detach from the session kill the server tmux kill server then start a new session Alternatively you can also run Prefix I note the I is uppercased to reload the tmux environment In short if running Prefix r is not sufficient try running Prefix I also If all fails restart the tmux Two more shortcuts that I don t find intuitive are the window splits Prefix and Prefix To me it makes more sense to use for a vertical split and for a horizontal split Add these lines bind split window hc pane current path bind split window vc pane current path Now when I press Prefix tmux does a vertical split and when I press Prefix tmux does a horizontal split More configs There are many different ways you can configure your tmux config To address them all would be out of the scope of this article If you want to learn more about tmux configs I am currently working on another article to address tmux configs in more detail so stay tuned I will update this post with the link to the said article when it is done If you want to see what my personal configs look like check out my dotfiles ConclusionPhew we have now reached the end of this guide I hope that you learned valuable things about tmux If there is anything that is unclear please feel free to drop by the comment section Here s the final recap In this guide we learned about tmux session window pane and server We learned about their relationships with each other We also learned a little about configuring tmux In the next article you will learn more about configuring tmux in detail I will update this guide with the link to the next article when it is ready More importantly take your time reading this guide It can be tempting to read through the entire guide without doing any practice Take a day to read about a section and let it digest Apply what you learn that day Instead of reading for minutes and practicing for minutes for every minutes you learn about something spend minutes Yes it is a lot Yes you ll read less on average But you will learn a lot more In the end what you learn is what actually matters not the amount of articles books you read Happy coding 2021-11-10 16:33:24
海外TECH DEV Community GraphQL Integration in Flutter https://dev.to/rrtutors/graphql-integration-in-flutter-4fib GraphQL Integration in FlutterWhat is GraphQL and how to integrate GraphQL Api integration in flutter application What is GraphQL GraphQL is an open source technology which will be used at server side to create optimized APIs to replace REST apis This GraphQL is developed by Facebook REST API contains multiple end points where as GraphQL is single end point and Rest API will have the over fetching response which some of the response data not be used inside application where as with GraphQL will fetch only required response When we are having more end points to work REST API might be difficulty to work in that case GraphQL APIs will be more easy to implement We can t decide which APIs we need to implements But in this example we are learning how to implement GraphQL APIs in flutter applicationGraphQL mainly two types of operations will be thereQueryMutationQuery This GraphQL operation will be used to Read Fetch data from the End pointSyntax query query name Fields Mutation This GraphQL operation will be used to write post data to the End point mutation editOperation dataField valueOfField returnType 2021-11-10 16:25:44
海外TECH DEV Community React JS error WebPack 4.44.2 (temp Fix) https://dev.to/gilly7/react-js-error-webpack-4442-temp-fix-2408 React JS error WebPack temp Fix The react scripts package provided by Create React App requires a dependency webpack Don t try to install it manually your package manager does it automatically However a different version of webpack was detected higher up in the tree home user node modules webpack version create a env at the root of the folder of react foldertype SKIP PREFLIGHT CHECK true in side env filenow run in cmd npm start 2021-11-10 16:18:30
海外TECH DEV Community Apache Airflow In EKS Cluster https://dev.to/aws-builders/apache-airflow-in-eks-cluster-dgo Apache Airflow In EKS Cluster AbstractTL DRAirflow is one of the most popular tools for running workflows especially data pipeline A successful pipeline moves data efficiently minimizing pauses and blockages between tasks keeping every process along the way operational Apache Airflow provides a single customizable environment for building and managing data pipelinesIn this post it provides step by step to deploy airflow on EKS cluster using Helm for the default chart with customization in values yaml cdk for creating AWS resources such as EFS node group with Taints for pod toleration in the SPOT instance Table Of ContentsArchitecture OverviewUsing CDK to create EFS and Access Point AP Install EFS CSI Driver using helm chart within airflow workers onlyCreate EFS storage class PV and PVCUse CDK to create airflow IAM roleUse CDK to create Auto scaling groups ASG Set up gitlab repo for git sync sidecarCreate values yamlAirflow secretsDeploy Airflow using helm chartCreate airflow ingressConclusion Architecture Overview This blog guide you deploy airflow on an existing EKS cluster using namespace airflow and its own resourcesPrerequiste EKS clusterIAM admin role or enough permission to create AWS resourcesCDK installation Typescript Helm chartAirflow components Worker scheduler web server flower Other things are airflow database redis and sync Use EFS to share logs DAGs between components such as worker scheduler and webserver Plus use EFS to store airflow database metadataThere are node groups On demand EC workers If you can control the retries of Airflow task and DAGS this group is better to use Spot instances instead On demand EC Airflow database pgBouncer and redisSpot fleet EC Schedulers webs and other components Using CDK to create EFS and Access Point AP It s neccessary to create EFS as a way to persistent airflow DAGs logs between workers and schedulerCheckout AWS EKS With EFS CSI Driver And IRSA Using CDK to undestand AWS EFS and CSI Driver provisionerCreate EFS within the VPC of EKS cluster and add security group for open access from EKS nodes efs stack ts import as efs from aws cdk aws efs import as ec from aws cdk aws ec import RemovalPolicy App Stack StackProps Tags from aws cdk core export class AirflowEfsStack extends Stack constructor scope App id string pattern string vpc ec IVpc ip string env tag string props StackProps super scope id props const securityGroup new ec SecurityGroup this AirflowEfsSG vpc securityGroupName pattern airflow sg description Security group for EFS CSI allowAllOutbound true securityGroup addIngressRule ec Peer ipv ip ec Port allTraffic Allow internal private vpc Tags of securityGroup add Name pattern efs sg Tags of securityGroup add cdk sg stack sg stack Tags of securityGroup add env env tag const fileSystem new efs FileSystem this AirflowEFS vpc securityGroup fileSystemName pattern airflow efs lifecyclePolicy efs LifecyclePolicy AFTER DAYS removalPolicy RemovalPolicy DESTROY Tags of fileSystem add Name pattern airflow efs Tags of fileSystem add cdk efs stack pattern efs env tag Tags of fileSystem add env env tag const fsAcccessPoint fileSystem addAccessPoint pattern EFSAccesPoint posixUser uid gid createAcl ownerUid ownerGid permissions path airflow data Tags of fsAcccessPoint add Name pattern data airflow pg Install EFS CSI Driver using helm chart within airflow workers only CSI driver provisioner is DaemonSet it will deploy to all worker nodes as default but we can restrict to run EFS kube system pods for airflow nodes only by adding toleration and affinity in values yaml values yaml controller tolerations key dedicated operator Equal value airflow effect NoSchedule affinity nodeAffinity requiredDuringSchedulingIgnoredDuringExecution nodeSelectorTerms matchExpressions key role operator In values airflownode tolerations key dedicated operator Equal value airflow effect NoSchedule nodeSelector role airflowDeployhelm repo add aws efs csi driver lt helm repo updatehelm upgrade i aws efs csi driver aws efs csi driver aws efs csi driver values efs values yaml n kube system Create EFS storage class PV and PVC Pre requisite EFS and AP IDs which are created from previous stepUpdate the EFS and AP ID to the storage class and persistent volume then create them pvc yaml kind StorageClassapiVersion storage ks io vmetadata name af efs scprovisioner efs csi aws comparameters provisioningMode efs ap fileSystemId fs be directoryPerms gidRangeStart gidRangeEnd apiVersion vkind PersistentVolumemetadata name af efs pg pvspec capacity storage Gi volumeMode Filesystem accessModes ReadWriteMany persistentVolumeReclaimPolicy Retain storageClassName af efs sc csi driver efs csi aws com volumeHandle fs be fsap fffce apiVersion vkind PersistentVolumeClaimmetadata name data airflow postgresqlspec accessModes ReadWriteMany storageClassName af efs sc resources requests storage GiGet PVC we will need this to update to values yaml later kubectl get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEdata airflow postgresql Bound efs pg pv Gi RWX efs sc h Use CDK to create airflow IAM role Best practice is to use IAM role service account IRSA but within airflow we can create its own role as instance profile with permission for node to join EKS cluster and permission to read write EFS or other AWS resources iamRole ts createWorkerRole IRole Airflow IAM worker role const worker role new Role this AirflowIamRole assumedBy new ServicePrincipal ec amazonaws com roleName this eksCluserName airflow const attachPolicies AmazonECContainerRegistryReadOnly AmazonEKSWorkerNodePolicy AmazonSReadOnlyAccess AmazonEKS CNI Policy for var policy of attachPolicies worker role addManagedPolicy ManagedPolicy fromAwsManagedPolicyName policy Tags of worker role add Name this eksCluserName airflow Tags of worker role add cdk iam stack this pattern iam this env tag Tags of worker role add env this env tag const autoscalingStatement new PolicyStatement sid AutoScalingGroup actions autoscaling DescribeAutoScalingGroups autoscaling DescribeAutoScalingInstances autoscaling DescribeLaunchConfigurations autoscaling DescribeTags autoscaling CreateOrUpdateTags autoscaling UpdateAutoScalingGroup autoscaling TerminateInstanceInAutoScalingGroup ec DescribeLaunchTemplateVersions elasticfilesystem tag GetResources effect Effect ALLOW resources conditions StringEquals aws RequestedRegion this region worker role addToPolicy autoscalingStatement return worker role Note ASG launch template will add this Airflow role to aws auth configmap mapRoles for joining new nodes to the EKS clusterCheckout AWS EKS Launch Template Of Node Group for understanding how IAM role in nodegroup works Use CDK to create Auto scaling groups ASG Why do we need auto scaling here In order to handle work loads between when running workflowsCreate a manage node group with spot instances for saving cost Of course we should care about spot instance might be interrupted If a workflow task gets interrupted due to node termination you may lose a part of progress but the cost of losing ten minutes of progress is much lower than losing four hours of work Using Spot instances for long running tasks can be disruptive if node running the task gets terminated by Spot Consider breaking long running tasks into multiple sub tasks with a shorter execution time that can be used to checkpoint a workflow s progress We also recommend that you configure automatic retries in DAGs especially when using Spot Two autoscaling groups Instance types are based on the need of Airflow processes such as workload data size number of DAGs tasks and their complexityASG pet min max spot type ca xlarge ca largecomponents sch web flower syncASG sts stateful set min max calculate the number of workers and auto scalingspot type ca xlarge ca largecomponents workersASG db database min max on demand type ca xlargecomponents airflow database redis pgBouncer asg stack ts import Stack App Tags StackProps from aws cdk core import Cluster Nodegroup CapacityType TaintEffect from aws cdk aws eks import Role ServicePrincipal ManagedPolicy PolicyStatement Effect IRole from aws cdk aws iam import as ec from aws cdk aws ec interface EcType pet Array lt string gt pet size Array lt number gt sts string sts size Array lt number gt db string export class AirflowAsgStack extends Stack public eks cluster any public worker role any public airflowSG any public eksCluserName string public launchTemplate any constructor public scope App id string public pattern string public vpc ec IVpc public vpcSg ec ISecurityGroup public region string public ip string ec types EcType public env tag string props StackProps super scope id props this eksCluserName us eks EKS cluster this eks cluster Cluster fromClusterAttributes this EksCluster pattern toUpperCase vpc clusterName this eksCluserName this launchTemplate this createLaunchTemplate Airflow SG to workers this airflowSG this createAirflowSG this worker role this createWorkerRole this createAsgPet ec types pet ec types pet size this createAsgSts ec types sts ec types sts size this createAsgDb ec types db createAirflowSG any Airflow security group const airflowSG new ec SecurityGroup this AirflowairflowSG vpc this vpc securityGroupName airflow priv sg description Security group to access to worker in private vpc allowAllOutbound true airflowSG connections allowFrom airflowSG ec Port allTcp Allow node to communicate with each other airflowSG connections allowFrom this vpcSg ec Port allTcp Allow nodes in another ASG communicate to airflow nodes Tags of airflowSG add Name airflow priv ssh sg Tags of airflowSG add cdk sg stack this pattern sg this env tag Tags of airflowSG add env this env tag return airflowSG createLaunchTemplate any More about launch templates Notes Nodegroup auto generates role if not specify Launch template node group automatically add the worker role to aws auth configmap const airflowLaunchTemplate new ec LaunchTemplate this AirflowLaunchTemplate lt launchTemplateName airflow asg lt securityGroup this airflowSG blockDevices deviceName dev xvda volume ec BlockDeviceVolume ebs keyName this pattern airflow Tags of airflowLaunchTemplate add Name airflow asg lt Tags of airflowLaunchTemplate add cdk lt stack this pattern lt this env tag Tags of airflowLaunchTemplate add env this env tag return airflowLaunchTemplate createAsgPet types Array lt string gt sizes Array lt number gt ASG Pet is used to assign deployments Due to using spot instances so recommendation min size const asgNodeGroupName eks airflow nodegroup pet const asgPet new Nodegroup this AirflowPetAsg nodegroupName eks airflow nodegroup pet subnets this eks cluster vpc selectSubnets subnetType ec SubnetType PRIVATE cluster this eks cluster capacityType CapacityType SPOT nodeRole this worker role instanceTypes new ec InstanceType types new ec InstanceType types minSize sizes maxSize sizes labels role airflow type af stateless lifecycle spot taints effect TaintEffect NO SCHEDULE key dedicated value airflow tags Name eks airflow nodegroup pet cdk asg stack this pattern asg this env tag launchTemplateSpec id this launchTemplate launchTemplateId createAsgSts type string sizes Array lt number gt ASG STS Assign Airflow workers const asgNodeGroupName eks airflow nodegroup sts const asgStatefulSet new Nodegroup this AirflowStsAsg nodegroupName asgNodeGroupName subnets this eks cluster vpc selectSubnets subnetType ec SubnetType PRIVATE cluster this eks cluster nodeRole this worker role instanceTypes new ec InstanceType type capacityType CapacityType SPOT minSize sizes maxSize sizes labels role airflow type af stateful lifecycle spot taints effect TaintEffect NO SCHEDULE key dedicated value airflow tags Name eks airflow nodegroup sts cdk asg stack this pattern asg this env tag launchTemplateSpec id this launchTemplate launchTemplateId createAsgDb type string ASG Db Assign Airflow database and redis to this worker group const asgNodeGroupName eks airflow nodegroup db const asgStatefulSet new Nodegroup this AirflowDbAsg nodegroupName asgNodeGroupName subnets this eks cluster vpc selectSubnets subnetType ec SubnetType PRIVATE cluster this eks cluster nodeRole this worker role instanceTypes new ec InstanceType type capacityType CapacityType ON DEMAND minSize maxSize labels role airflow type af db lifecycle on demand taints effect TaintEffect NO SCHEDULE key dedicated value airflow tags Name eks airflow nodegroup db cdk asg stack this pattern asg this env tag launchTemplateSpec id this launchTemplate launchTemplateId Deploy cdk deploy AirflowAsgStackUSCheck result kf get node grep eksip us east compute internal Ready lt none gt dh v eks cfceip us east compute internal Ready lt none gt dh v eks cfceip us east compute internal Ready lt none gt h v eks cfceIMPORTANT The above code contains creating Airflow security group you should checkout Understand Pods communication for deep understanding how EKS node join EKS cluster and how Pods communicate Set up gitlab repo for git sync sidecar Create new project to store DAGs on Git and let git sync update DAGs automatically Create user airflow and add to project as reporter developerGenerate its token as impersonating which will be used later Create values yaml values yaml is used to customize some attributes from airflow helm chart to adapt with our system and deployments such as credentials Airflow configs Pods assignment autoscaling etc Use community airflow helm chart not the official one Template values yaml from airflow helm chartsCustomizations Update airflow image if you d like to deploy from your own one or use latest public oneairflow image repository apache airflow tag python pullPolicy IfNotPresent Persist airflow logs using EFS logs airflow kubernetesPodTemplate securityContext fsGroup sync securityContext fsGroup scheduler securityContext fsGroup web securityContext fsGroup workers securityContext fsGroup flower securityContext fsGroup logs the airflow logs folder path opt airflow efs logs persistence enabled true subPath storageClass efs sc accessMode ReadWriteMany size GiReference to How to persist airflow logs for more options Update web service type to NodePort for later use Ingressweb service type NodePort Set up workers replicas for balance workload How to set up celery worker autoscaling Add toleration to airflow components Airflow nodes will only accept airflow Pods Global setting airflow defaultTolerations defaultTolerations key dedicated operator Equal value airflow effect NoSchedule For other extra components such as postgresql redis pgBouncer we need to add tolerations at each field Add nodeAffinity to assign airflow components to their node groupFor deployment services such as web scheduler sync flower affinity nodeAffinity requiredDuringSchedulingIgnoredDuringExecution nodeSelectorTerms matchExpressions key type operator In values af statelessFor stateful service such as workers affinity nodeAffinity requiredDuringSchedulingIgnoredDuringExecution nodeSelectorTerms matchExpressions key type operator In values af statefulFor postgresql redis pgBouncer affinity nodeAffinity requiredDuringSchedulingIgnoredDuringExecution nodeSelectorTerms matchExpressions key type operator In values af db Persist DAGs using git sync git sync sidecar SSH auth Pre requiste Create Linux user airflow generate its rsa ssh key add public key to airflow gitlab user and then use id rsa to generate secret kubectl create secret generic airflow ssh git secret from file id rsa pwd id rsa namespace airflow secret airflow ssh git secret createdGet gitlab known hosts ssh keyscan H gitlab cloudopz co gt gt known hostsUpdate values yaml at dags gitSync dags the airflow dags folder path opt airflow efs dags gitSync enabled true repo git gitlab cloudopz co devops airflow dags git branch master revision HEAD syncWait sshSecret airflow ssh git secret sshSecretKey id rsa known hosts verification can be disabled by setting to sshKnownHosts gitlab cloudopz co ssh rsa AAAABNzaCycEAAAADAQABAAABAQDDbjpsGTussTrWvrULzqDdbDJXVlOvmvE svINItUvSUrNNKiABsIlexsEnDTdYTfZkVFtflTeLKqvEJowFRZgSDOtWljPxRUhnMgGftImbaRYBqdsSbTebjfDRkykgIkAW LwsyeckncLZLAUQbh uIqutCPUlxZBnnnag ZFz EGCsQTxPsTUIyLrgehkLQkzvxdz JDHELdmdnwCJIXOKhFwwSDkRUAkHgVSHWsFZdfNMNaTRBRIUCnEqwDuEqSlThyfvoymuFeA JaiTgfhvDVleBwSx git sync sidecar HTTP auth Create secret with gitlab token key get from Set up gitlab repo for git sync sidecar kubectl create secret generic airflow http git secret from literal username airflow from literal password EKZvPiTCKVaNSzrjn namespace airflowUpdate values yaml at dags gitSync dags the airflow dags folder path opt airflow efs dags gitSync enabled true repo branch master revision HEAD syncWait httpSecret airflow http git secret httpSecretUsernameKey username httpSecretPasswordKey password Database PostgreSQL Chart with enabling debug and using EFSWe already created the PVC from Create EFS Access Point for postgresql volumeUpdate values yaml Note DEBUG enabled is optional postgresql enabled true postgresqlDatabase airflow postgresqlUsername postgres postgresqlPassword airflow existingSecretKey postgresql password extraEnv name BITNAMI DEBUG value true persistence enabled true storageClass efs sc existingClaim data airflow postgresql accessModes ReadWriteMany size Gi master podAnnotations cluster autoscaler kubernetes io safe to evict true volumePermissions enabled true Create Airflow variablesWe can use plain text or Secrets ConfigmapsHow to Generate FernetAirflow uses Fernet to encrypt passwords in the connection configuration and the variable configuration It guarantees that a password encrypted using it cannot be manipulated or read without the key Fernet is an implementation of symmetric also known as “secret key authenticated cryptography Generating Fernet key from cryptography fernet import Fernet fernet key Fernet generate key print fernet key decode your fernet key keep it in secured place Airflow secrets For airflow users reference to Access Control to assign proper permissions airflow secret yaml apiVersion v kind Secret metadata name airflow secret namespace airflow data airflow admin password airflow user password airflow viewer password airflow fernet clh password db user db password ttdb user ttdb password slack host slack webhook airflow database postgresql password git sync access token airflow gitlab user airflow gitlab token Deploy Airflow using helm chart The community usage helm chart add this repo as airflow stable helm repo add airflow stable helm repo updatekubectl create namespace airflowhelm upgrade i airflow airflow stable airflow version namespace airflow values values yamlCheck PVC kubectl get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEairflow logs Bound pvc dfc f ebeee Gi RWX af efs sc dhdata airflow postgresql Bound af efs pg pv Gi RWX af efs sc dCheck pods kubectl get pod owideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESairflow db migrations fb pnp Running dh ip ec internal lt none gt lt none gt airflow flower bffb mstx Running dh ip ec internal lt none gt lt none gt airflow pgbouncer bddcf qvkf Running dh ip ec internal lt none gt lt none gt airflow postgresql Running dh ip ec internal lt none gt lt none gt airflow redis master Running dh ip ec internal lt none gt lt none gt airflow scheduler dcff tzx Running dh ip ec internal lt none gt lt none gt airflow scheduler dcff cbd Running dh ip ec internal lt none gt lt none gt airflow sync connections cd dgjq Running dh ip ec internal lt none gt lt none gt airflow sync pools ffb qdcjn Running dh ip ec internal lt none gt lt none gt airflow sync users dbbff zxrs Running dh ip ec internal lt none gt lt none gt airflow sync variables fcd jpx Running dh ip ec internal lt none gt lt none gt airflow web fcc bvgls Running dh ip ec internal lt none gt lt none gt airflow web fcc vqkr Running dh ip ec internal lt none gt lt none gt airflow worker Running dh ip ec internal lt none gt lt none gt airflow worker Running dh ip ec internal lt none gt lt none gt We see that the two workers locate on different nodes Check node to be taints and pods are in toleration kubectl describe node ip ec internal grep Taints B CreationTimestamp Thu Jul Taints dedicated airflow NoSchedulekubectl describe pod airflow worker grep TolerationsTolerations dedicated airflow NoSchedule kubectl describe pod airflow worker grep TolerationsTolerations dedicated airflow NoScheduleCheck git sync for up to date DAGs The DAG file postgres operator py kubectl exec it airflow worker ls la efs dags repo Defaulting container name to airflow worker Use kubectl describe pod airflow worker n airflow to see all of the containers in this pod total drwxr sr x nogroup Jul drwxrwsrwx root nogroup Jul rw r r nogroup Jul git rw r r nogroup Jul postgres operator py rw r r nogroup Jul README md Create airflow ingress airflowingress ks yaml apiVersion networking ks io vbetakind Ingressmetadata annotations alb ingress kubernetes io backend protocol HTTP alb ingress kubernetes io certificate arn arn aws acm ap northeast certificate bbf aeb f zzzz xxxxyyyy alb ingress kubernetes io group name dev alb ingress kubernetes io group order alb ingress kubernetes io listen ports HTTPS kubernetes io ingress class alb labels dev airflow name airflow namespace airflowspec rules host airflow vinceredev com http paths backend serviceName airflow web servicePort Conclusion With all of steps above you can now deploy airflow in EKS cluster with control assigment of airflow components to AWS node groupBy using Amazon EC Spot you can reduce your spend on EC instances significantly with minimal configuration changes By using EFS with CSI driver you can persite data logs cross multiple zones By using CDK you get more familiar to create IaC and Kubernetes yaml as code ltag user id follow action button background color important color df important border color important Vu Dao Follow AWSome Devops AWS Community Builder AWS SA ️CloudOpz ️ vumdao vumdao 2021-11-10 16:12:29
海外TECH DEV Community Whats your biggest blocker getting your first software engineering job? https://dev.to/scottstern06/whats-your-biggest-blocker-getting-your-first-software-engineering-job-1b2e Whats your biggest blocker getting your first software engineering job Getting your first job out of a bootcamp or being self taught is no easy task but its possible What is your biggest blocker making that next step Scott Want more Come join our Facebook group to help you get your first job as a software engineer career development and so much more Here is a link to top interview resources 2021-11-10 16:08:56
海外TECH DEV Community Google Homepage Clone With HTML and CSS | By Frontend Everything https://dev.to/frontendeverything/google-homepage-clone-with-html-and-css-by-frontend-everything-l0g Google Homepage Clone With HTML and CSS By Frontend EverythingHello Everyone Welcome to My New Blog Post Today I have made a Google homepage clone with the help of HTML and CSS We have used no JavaScript in this I am Piyush Sharing About Web development Daily You can also check out me at frontendeverything Let s start making the google homepage clone step by stepFirst We will make the nav in the navbar we will include things Gmail images menu sign in button Let s see the HTML Code of the navbar Gmail Images Sign in Output till nowgoogleThis is nav with CSS we will move on CSS after htmlSecond part of HTML We will make the center part of the google home page with will include logo searchbar and buttons Let s see the Code of the center part Output till nowthis is with CSS styling will show the CSS code after this htmlThe final HTML Part This is the final part we will make the footer of the google homepage it will not contain many things Let s see the Code of the footer last part India About Privacy Terms Settings This is the Output till now note this output is not with cssoutput with cssThis is the full CSS Before we have only code HTML this is the full CSS code html height font size body font px arial sans serif Nav Items ul list style none padding px line height px li display inline block padding px px vertical align middle nav footer padding px px Top Nav nav img list style none color opacity nav a text decoration none color opacity nav ul li a hover text decoration line underline opacity Right Nav Items r nav float right position relative padding top px padding right px apps width px height px margin top px padding right px opacity apps hover opacity Sign In Button sign in border px solid f outline none background f display inline block line height px padding px border radius px sign in a font weight bold color fff opacity text decoration none sign in a hover opacity text decoration none sign in hover opacity box shadow px eee Center Conte cntr pg position absolute top left margin right transform translate logo display height px width px display block margin auto form display block margin auto search bar border radius px width px margin auto height px border px solid EEE background color fff box shadow px px px EEE margin bottom px outline none text indent px search bar hover search bar active padding bottom px padding top px margin top px width px box shadow px px px EEE outline none mic width px height px position relative left px top px submit buttons display inline block height px cursor pointer line height px background color fff border px solid fff border radius px color cursor default font family arial sans serif font size px font weight bold margin px px min width px padding px text align center submit buttons position relative left right cursor pointer submit buttons hover border px solid ddd color box shadow px px px EEE Footer l ftr float left r ftr float right footer line height px position absolute left right bottom color background color fff border top solid px eee footer a text decoration none color opacity footer a hover text decoration line underline This is complete code of CSSFinal OutputgoogleFinal output of google homepageTo make your work easier here is the codepen link don t forget to follow me there if you liked the project This is codepen link Thank You For Scrolling Till here If You gain any knowledge then do checkout me at frontendeverything I am Piyush I provide Content related to programming technology web development Daily 2021-11-10 16:06:36
海外TECH DEV Community Javascript snippets you need to know right now 🔥 https://dev.to/abhirajb/javascript-snippets-you-need-to-know-right-now-2mo6 Javascript snippets you need to know right now JavaScript is one of the most popular languages you can learn As many people say “If you re going to learn just one programming language go for JavaScript If this sounds compelling to you I am starting a series where i give Javascript snippets every Wednesday for weeks This tweet of mine had originally inspired me to create this series do drop a like and follow me Abhiraj Bhowmick rainboestrykr Javascript snippets for you to write better code Part A thread webdevelopment webdev javascript techtwitter devcommunity AM Nov Here s a list of beneficial snippets that you can learn and use immediately Lets get started ️⃣allThis snippet returns true if the predicate function returns true for all elements in a collection and false otherwise You can omit the second argument fn if you want to use Boolean as a default value const all arr fn Boolean gt arr every fn all x gt x gt trueall true️⃣arrayToCSVThis snippet converts the elements to strings with comma separated values const arrayToCSV arr delimiter gt arr map v gt v map x gt x join delimiter join n arrayToCSV a b c d a b n c d arrayToCSV a b c d a b n c d ️⃣arrayToHtmlListThis snippet converts the elements of an array into list tags and appends them to the list of the given ID const arrayToHtmlList arr listID gt el gt el document querySelector listID el innerHTML arr map item gt lt li gt item lt li gt join arrayToHtmlList item item myListID ️⃣bifurcateThis snippet splits values into two groups and then puts a truthy element of filter in the first group and in the second group otherwise You can use Array prototype reduce and Array prototype push to add elements to groups based on filter const bifurcate arr filter gt arr reduce acc val i gt acc filter i push val acc bifurcate beep boop foo bar true true false true beep boop bar foo ️⃣byteSizeThis snippet returns the length of a string in bytes const byteSize str gt new Blob str size byteSize byteSize Hello World ️⃣capitalizeThis snippet capitalizes the first letter of a string const capitalize first rest gt first toUpperCase rest join capitalize fooBar FooBar capitalize fooBar true Foobar ️⃣dayOfYearThis snippet gets the day of the year from a Dateobject const dayOfYear date gt Math floor date new Date date getFullYear dayOfYear new Date ️⃣decapitalizeThis snippet turns the first letter of a string into lowercase const decapitalize first rest gt first toLowerCase rest join decapitalize FooBar fooBar decapitalize FooBar fooBar countOccurrencesThis snippet counts the occurrences of a value in an array const countOccurrences arr val gt arr reduce a v gt v val a a countOccurrences Until next Wed Abhiraj 2021-11-10 16:06:10
海外TECH DEV Community useRef or useState, which is better? https://dev.to/salehmubashar/useref-or-usestate-which-is-better-258j useRef or useState which is better Hi guys In this post we will be learning what the useRef and useState hooks are their differences and when to use which The code examples in this post will involve only functional components however most of the differences and uses cover both class and functional componentsComplete Tutorial on useRef is uploaded at Hubpages The useState hookuseState is a built in react hook that allows you to store information as states in a variable It lets you add React states to functional components In the example below useState declares the state variable while the the value is stored in the count variable setCount is the function used to update this value import useState from reactimport React useState from react function Count Declare a new state variable called count const count setCount useState The useRef hookThe useRef hook is a built in React hook that takes one argument or parameter as its initial value and returns a reference or persisted mutable values This reference or ref for short contains the value which can be retrieved using the current property We can also store user inputs in refs and display the collected data like this import useRef hookimport React useRef from react export default function App create a variable to store the reference const nameRef useRef function handleSubmit e prevent page from reloading on submit e preventDefault output the name console log nameRef current value return lt div className container gt lt form onSubmit handleSubmit gt lt div className input group gt lt label gt Name lt label gt lt input type text ref nameRef gt lt div gt lt input type submit gt lt form gt lt div gt useRef vs useStateData or values stored in a reference or ref remains the same even after component re rendering unlike states So References do not affect component rendering but states do useState returns properties or an array One is the value or state and the other is the function to update the state In contrast useRef returns only one value which is the actual data stored When the reference value is changed it is updated without the need to refresh or re render However in useState the component must render again to update the state or its value When to use Refs and StatesRefs are useful when getting user input DOM element properties and storing constantly updating values However if you are storing component related info or use methods in components states are the best option So in conclusion both the hooks have their fair bit of pros and cons and they will be utilised according to the situation and use Thanks for reading Note There probably is much more that could have been mentioned here but in short these were the most important differences If you liked this tutorial you can buy me a coffee Complete Tutorial on useRef is uploaded at Hubpagesand also follow me on twitter Cheers 2021-11-10 16:04:17
海外TECH DEV Community Github Actions for Symfony 5 PHPUnit and more https://dev.to/romaixn/github-actions-for-symfony-5-phpunit-and-more-4e90 Github Actions for Symfony PHPUnit and more My WorkflowThis Github Actions will help you to guarantee an optimal quality and the good functioning of the code thanks to the launching of automatic tests But also warn you about the known vulnerabilities of your dependencies PHP SetupFirst this action setup PHP composer and install all composer dependencies Security QualityAfter that it check vulnerabilities in your dependencies and check your quality code according to PSR coding style using PHP CodeSniffer and PHPStan Webpack EncoreFor the Webpack Encore part it install all npm dependencies and build all your assets TestsFinally it run your PHPUnit tests and Behat if you have Submission Category Maintainer Must Haves Yaml Filename Symfony Testson push branches main dev pull request jobs symfony name Symfony PHP matrix php versions runs on ubuntu latest strategy fail fast true matrix php versions steps official name Checkout uses actions checkout v community name Setup PHP extensions and composer with shivammathur setup php uses shivammathur setup php verbose with php version matrix php versions extensions mbstring xml ctype iconv intl pdo sqlite dom filter gd iconv json mbstring pdo Composer name Get composer cache directory id composer cache run echo set output name dir composer config cache files dir name Cache composer dependencies uses actions cache v with path steps composer cache outputs dir key runner os composer hashFiles composer lock restore keys runner os composer name Install Composer dependencies run composer install no progress no suggest prefer dist optimize autoloader name Security check installed dependencies uses symfonycorp security checker action v community name Check PSR code style PHP CodeSniffer uses chekalsky phpcs action v with enable warnings true installed paths github workspace vendor squizlabs php codesniffer phpcs bin path vendor bin phpcs src ignore Migrations name Analyses PHP Code PHP Mess Detector run vendor bin phpmd src tests text phpmd ruleset xml name Analyse PHP Code PHPStan run vendor bin phpstan analyse src name Cache node modules uses actions cache v id yarn cache node modules with path node modules key runner os yarn cache node modules hashFiles yarn lock restore keys runner os yarn cache node modules name Yarn install if steps yarn cache node modules outputs cache hit true run yarn install name Yarn build run yarn run encore production name Archive production artifacts uses actions upload artifact v with name build path public build Symfony name Check the Symfony console run php bin console V php bin console about Tests name Run unit and functional tests run php bin phpunit stop on failure name Run Behat Mink tests run php vendor bin behat Additional Resources InfoYou can remove all yarn related parts if you don t use Webpack Encore 2021-11-10 16:01:03
Cisco Cisco Blog Midsize and Small Service Provider Opportunities and Challenges https://blogs.cisco.com/sp/midsize-and-small-service-provider-opportunities-and-challenges Midsize and Small Service Provider Opportunities and ChallengesMidsize and small SPsーservice providers with a customer base of million customers or lessーhave relatively small customer bases and limited technical staff However they possess many of the same business and operational challenges as larger operators but their approach to executing business strategy is noticeably different from the rest of the market 2021-11-10 16:41:43
Cisco Cisco Blog Cisco Takes a “Byte” out of Wi-Fi 6E https://blogs.cisco.com/networking/cisco-takes-a-byte-out-of-wi-fi-6e Cisco Takes a “Byte out of Wi Fi EJoin Cisco Principal Wireless Architect Mark Krischer as he hosts a special edition of the Cisco Insiders Series for Networking podcast as he discusses Wi Fi E with two of Cisco s wireless experts Technical Leader from the Technical Marketing Engineering team Jim Florwick and Product Marketing Manager David Wolf 2021-11-10 16:41:21
Cisco Cisco Blog Building Resiliency Guardrails to Isolate Crashes in Cisco Products https://blogs.cisco.com/networking/building-resiliency-guardrails-to-isolate-crashes-in-cisco-products Building Resiliency Guardrails to Isolate Crashes in Cisco ProductsThe latest version of IOS XE greatly improves software resiliency by reducing the fault domains to a single process using a process runtime architecture based on three software techniques work units transactions and persistence 2021-11-10 16:30:40
Cisco Cisco Blog Wi-Fi’s market expands with Wi-Fi 6E https://blogs.cisco.com/networking/wi-fis-market-expands-with-wi-fi-6e Wi Fi s market expands with Wi Fi EWi Fi E goes where no previous generation of Wi Fi could It fundamentally improves the user experience with MHz of additional spectrum and the ability to handle much higher device density across more channels with increased bandwidth 2021-11-10 16:13:00
海外科学 NYT > Science Scientists Fight a New Source of Vaccine Misinformation: Aaron Rodgers https://www.nytimes.com/2021/11/08/sports/football/aaron-rodgers-vaccine.html Scientists Fight a New Source of Vaccine Misinformation Aaron RodgersThe Green Bay Packers quarterback one of the most visible athletes in the country last week used anti vaccination rhetoric as his reasoning for not getting vaccinated against Covid 2021-11-10 16:46:31
海外科学 BBC News - Science & Environment COP26: Draft deal calls for stronger carbon cutting targets by end of 2022 https://www.bbc.co.uk/news/world-59231477?at_medium=RSS&at_campaign=KARANGA nations 2021-11-10 16:04:51
金融 金融庁ホームページ 東北財務局が、高病原性鳥インフルエンザ疑似患畜の確認を踏まえ、金融上の対応について要請しました。 https://www.fsa.go.jp/news/r3/ginkou/20211110-3.html 東北財務局 2021-11-10 17:30:00
金融 金融庁ホームページ 「主要行等向けの総合的な監督指針」の一部改正(案)に対するパブリックコメントの結果等について公表しました。 https://www.fsa.go.jp/news/r3/ginkou/20211110-2.html 行等 2021-11-10 17:00:00
金融 金融庁ホームページ 金融審議会「資金決済ワーキング・グループ」(第1回)議事録を公表しました。 https://www.fsa.go.jp/singi/singi_kinyu/shikinkessai_wg/gijiroku/20211013.html 金融審議会 2021-11-10 17:00:00
金融 金融庁ホームページ 令和3年銀行法等改正に係る政令・内閣府令案等に関するパブリックコメントの結果等について公表しました。 https://www.fsa.go.jp/news/r3/ginkou/20211110/20211110.html 内閣府令 2021-11-10 17:00:00
ニュース ジェトロ ビジネスニュース(通商弘報) 先進国などとのFTA締結示唆、バングラデシュ貿易投資サミット https://www.jetro.go.jp/biznews/2021/11/6a219db57ae752e3.html 貿易 2021-11-10 16:40:00
ニュース ジェトロ ビジネスニュース(通商弘報) 米消費者信用残高、9月は8.3%増の高い伸び、消費者マインド改善も供給逼迫懸念 https://www.jetro.go.jp/biznews/2021/11/d79cd28dea584f72.html 消費者マインド 2021-11-10 16:30:00
ニュース ジェトロ ビジネスニュース(通商弘報) 韓国産業通商資源部、ポーランドの新規原発建設事業の受注支援を要請 https://www.jetro.go.jp/biznews/2021/11/65d15497033bea47.html 産業通商資源部 2021-11-10 16:20:00
ニュース ジェトロ ビジネスニュース(通商弘報) カステックス首相、26億ユーロの若年者ニート向け就労支援策を発表 https://www.jetro.go.jp/biznews/2021/11/d2cc9593743cdad1.html 首相 2021-11-10 16:10:00
ニュース BBC News - Home COP26: Draft deal calls for stronger carbon cutting targets by end of 2022 https://www.bbc.co.uk/news/world-59231477?at_medium=RSS&at_campaign=KARANGA nations 2021-11-10 16:04:51
ニュース BBC News - Home Duchess of Sussex weighed up calling father 'daddy' https://www.bbc.co.uk/news/uk-59236643?at_medium=RSS&at_campaign=KARANGA sussex 2021-11-10 16:01:22
ニュース BBC News - Home Newcastle are the perfect fit for me - new boss Howe https://www.bbc.co.uk/sport/football/59239326?at_medium=RSS&at_campaign=KARANGA eddie 2021-11-10 16:39:39
ニュース BBC News - Home T20 World Cup - England v New Zealand: Martin Guptill is caught off Chris Woakes for four https://www.bbc.co.uk/sport/av/cricket/59239181?at_medium=RSS&at_campaign=KARANGA T World Cup England v New Zealand Martin Guptill is caught off Chris Woakes for fourMoeen Ali catches Martin Guptill for four off Chris Woakes third ball in the men s T World Cup semi final match between England and New Zealand 2021-11-10 16:11:55

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)