投稿時間:2021-12-04 05:26:08 RSSフィード2021-12-04 05:00 分まとめ(28件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
海外TECH Ars Technica iPhones of US diplomats hacked using “0-click” exploits from embattled NSO https://arstechnica.com/?p=1817983 access 2021-12-03 19:25:30
海外TECH MakeUseOf How to Showcase and Monetize Your Work on VistaCreate https://www.makeuseof.com/monetize-showcase-your-content-on-vistacreate-how-to/ contributor 2021-12-03 19:30:12
海外TECH MakeUseOf How to Find Your Windows 11 Product Key https://www.makeuseof.com/windows-11-find-product-key/ product 2021-12-03 19:15:12
海外TECH MakeUseOf How to Fix VMware Errors After a Linux Kernel Upgrade https://www.makeuseof.com/fix-vmware-errors-after-linux-kernel-upgrade/ vmware 2021-12-03 19:00:32
海外TECH DEV Community You don't need "if" https://dev.to/vangware/you-dont-need-if-37f1 You don x t need quot if quot It was the first day in my last year of tech high school The new programming teacher arrived and stood silent for a second and then he started the lesson This year we will create a state machine with persistence using C This state machine will be a light bulb that can be turned on or off We all just look at each other thinking ok that will be easy and then he dropped the bomb There s a catch You ll not be allowed to use if or for for it Now the class was clearly confused Flow control is one of the first things we all learn as programmers The main objective of that teacher was to teach us that we need to stop thinking conditions as if repetitions as for and so on and instead be more abstract with the logic on our code In JavaScript we have if else for of in while do while switch case try catch We will go through that list and learn about the cleaner and safer alternatives we have Conditions if switch Let s take this simple example as a starting point const welcomeMessage admin gt let message if admin message Welcome administrator return message So we have a function welcomeMessage which takes a user object and returns a message which depends on the user role Now because this if is quite simple we might spot already that this has an issue but JavaScript itself doesn t give us any kind of error We don t have a default value for that message so we need to do something like this const welcomeMessage admin gt let message Welcome user if admin message Welcome administrator return message Orconst welcomeMessage admin gt let message if admin message Welcome administrator else message Welcome user return message As I said in the introduction we don t need if for this we can use a ternary instead A ternary has this shape boolean valueForTrue valueForFalseSo we can change welcomeMessage to be like this const welcomeMessage admin gt admin Welcome administrator Welcome user Orconst welcomeMessage admin gt Welcome admin administrator user Ternaries have advantages over ifs They force us to cover all the logic branches we are forced to have else in all our ifs They reduce the amount of code drastically we just use a and a They force us to use conditional values instead of conditional blocks which results in us moving logic from if blocks to their own functions The main argument against ternaries is that they become hard to read if we have several levels of nested ifs ifs inside an ifs and that s true but I see that as yet another advantage If you need to nest logic that means that you need to move that logic away So let s have yet another example for this const welcomeMessage canMod role gt Welcome canMod role ADMIN administrator moderator user That became hard to read quite easily but that means that we need to move some logic away from welcomeMessage so we need to do something like this const roleText role gt role ADMIN administrator moderator const welcomeMessage canMod role gt Welcome canMod roleText role user We covered if already but what about switch We can use a combination of plain objects and the operator so we go from this const welcomeMessage role gt switch role case ADMIN return Welcome administrator case MOD return Welcome moderator default return Welcome user To this const roleToText role gt ADMIN administrator MOD moderator role user const welcomeMessage role gt Welcome roleToText role For those not familiar with the operator it works like this possiblyNullishValue defaultValuepossiblyNullishValue can be either a value or nullish null or undefined If it is nullish then we use defaultValue if it isn t nullish then we use the value itself Previous to this we used to use but that goes to the default for all falsy values n null undefined false NaN and and we don t want that Error handling try catch When we want to run something that might throw an error we wrap it with a try catch as follows const safeJSONParse value gt let parsed try parsed JSON parse value catch Leave parsed undefined if parsing fails return parsed const works safeJSONParse const fails safeJSONParse undefinedBut we can get rid of that as well using Promises When you throw inside a promise it goes to the catch handler automatically so we can replace the code above with const safeJSONParse value gt new Promise resolve gt resolve JSON parse value If it fails just return undefined catch gt undefined safeJSONParse then works gt safeJSONParse then fails gt undefined Or you can just use async await and const works await safeJSONParse const fails await safeJSONParse undefined Loops for while The for and while statements are used to loop over a list of things but nowadays we have way better ways of doing that with the methods that come with some of those lists arrays or other functions that help us keep the same type of looping for objects as well So let s start with the easiest which is arrays const users name Luke age name Gandalf age Just loggingfor const name age of users console log The age of name is age Calculating averagelet ageTotal for const age of users ageTotal age console log The average age is ageTotal users length Generating new array from previousconst usersNextYear for const name age of users usersNextYear push name age age Instead of using for for this you can just use the Array prototype forEach for the logs Array prototype reduce for the average and Array prototype map for creating a new array from the previous one Just loggingusers forEach name age gt console log The age of name is age Calculating averageconsole log The average age is users reduce total age index items gt total age index items length items length Generating new array from previousconst usersNextYear users map name age gt name age age There is an array method for pretty much everything you want to do with an array Now the problems start when we want to loop over objects const ages Luke Gandalf Just loggingfor const name in ages console log The age of name is ages name Calculating averagelet ageTotal let ageCount for const name in ages ageTotal ages name ageCount console log The average age is ageTotal ageCount Generating new object from previousconst agesNextYear for const name in ages agesNextYear name ages name I put the word problem between quotes because it was a problem before but now we have great functions in Object Object entries and Object fromEntries Object entries turns an object into an array of tuples with the format key value and Object fromEntries takes an array of tuples with that format and returns a new object So we can use all the same methods we would use with arrays but with objects and then get an object back Just loggingObject entries ages forEach name age gt console log The age of name is ages name Calculating averageconsole log The average age is Object entries ages reduce total age index entries gt total age index entries length entries length Generating new object from previousconst agesNextYear Object fromEntries Object entries ages map name age gt name age The most common argument about this approaches for loops is not against Array prototype map or Array prototype forEach because we all agree those are better but mainly against Array prototype reduce I made a post on the topic in the past but the short version would be Just use whatever makes the code more readable for you and your teammates If the reduce approach ends up being too verbose you can also just do a similar approach to the one with for but using Array prototype forEach instead let ageTotal users forEach age gt ageTotal age console log The average age is ageTotal users length Closing thoughtsI want to emphasize something that usually gets lost in this series of articles I m doing The keyword in the title is NEED I m not saying you shouldn t use if for while and so on I m just saying that you might not need them that you can code without them and in some scenarios is even simpler the majority of scenarios from my point of view One of the names I considered for this series was re evaluating our defaults because what I m looking for is not to change of your coding style but actually to make you wonder Do I really NEED to do this or is there a simpler way So as usual my final question for you is Do you think you need if for while and so on Don t you think there might be a better way of solving that same issue with a simpler approach Thanks for reading this and if you disagree with something said in this post just leave a comment and we can discuss it further See you in the next post of this series 2021-12-03 19:36:21
海外TECH DEV Community 🚀10 Trending projects on GitHub for web developers - 3rd December 2021 https://dev.to/iainfreestone/10-trending-projects-on-github-for-web-developers-3rd-december-2021-12f5 2021-12-03 19:15:48
Apple AppleInsider - Frontpage News Apple hourly workers feel helpless under punishing pressure & mistreatment https://appleinsider.com/articles/21/12/02/apple-hourly-workers-feel-helpless-under-punishing-pressure-mistreatment?utm_medium=rss Apple hourly workers feel helpless under punishing pressure amp mistreatmentHourly workers in Apple s retail stores and the company s support call centers have revealed how poor conditions have led to struggles to pay rent ーand even to suicide Apple StoreApple employees around the world have already been complaining about pay equity and the company has now been paying out a bonus to some Now however many hourly paid frontline workers have revealed how bad conditions are working for Apple Read more 2021-12-03 19:51:01
海外TECH Engadget Facebook is testing a bill splitting feature in Messenger https://www.engadget.com/meta-facebook-messenger-split-payments-bill-194459104.html?src=rss Facebook is testing a bill splitting feature in MessengerThere may soon be more ways to get your friends to pay their share of the check Facebook or its parent company Meta announced today that it s testing Split Payments quot a free and fast way to share the cost of bills and expenses quot Starting next week users in the US will be able to charge their friends in a group chat or from the Payments Hub in Messenger nbsp In a group chat you ll need to hit the quot Get Started quot button to initiate the payments and then you can choose to divide a sum of money evenly or decide what each person owes You can also choose to include yourself and add a customizable message The money will be sent through Facebook Pay and after you submit your request will be sent to the group s chat room nbsp Facebook also said it s added new custom group effects from four additional creators King Bach Emma Chamberlain Bella Poarch and Zach King Earlier this month the company also released new quot soundmojis quot tied to the Stranger Things soundtrack and Taylor Swift s remaster of her album Red 2021-12-03 19:44:59
海外TECH Engadget Elon Musk says the first Tesla Cybertruck will be a four-motor variant https://www.engadget.com/elon-musk-tesla-cybertruck-four-motors-192835843.html?src=rss Elon Musk says the first Tesla Cybertruck will be a four motor variantWhen Tesla finally starts rolling the Cybertruck off the production line in the electric vehicle will debut with a four motor variant CEO Elon Musk wrote on Twitter that model will offer quot independent ultra fast response torque control of each wheel quot Some other EVs have a motor on each wheel including Rivian s RT Initial production will be motor variant with independent ultra fast response torque control of each wheelーElon Musk elonmusk December Musk also reiterated that the Cybertruck will have front and rear wheel steer He previously noted the EV would offer rear wheel steering which will enable it to drive diagonally quot like a crab quot Notably the Hummer EV has a crab mode Nissan s e orce all wheel control system ーwhich is in the Ariya electric crossover upcoming next gen Leaf and a lunar lander prototype ーhas front and rear motors too Tesla removed all Cybertruck specs and pricing from its website in October Would be owners can plunk down a refundable deposit of and configure their order close to when Tesla starts production which is scheduled to happen next year However it seems you ll likely have to wait longer if you want a two motor version 2021-12-03 19:28:35
Cisco Cisco Blog Securely connecting the hybrid workforce and network edge: SD-WAN’s role in a SASE architecture https://blogs.cisco.com/networking/securely-connecting-the-hybrid-workforce-and-network-edge-sd-wans-role-in-a-sase-architecture Securely connecting the hybrid workforce and network edge SD WAN s role in a SASE architectureIn the hybrid work environment IT organizations need to secure their remote workers and their network edge See how SD WAN and SASE can help 2021-12-03 19:42:34
海外TECH WIRED What Crypto Can Expect From Twitter’s New CEO https://www.wired.com/story/parag-twitter-crypto-dorsey agrawal 2021-12-03 19:32:58
ニュース BBC News - Home Arthur Labinjo-Hughes: Emma Tustin and Thomas Hughes jailed over killing https://www.bbc.co.uk/news/uk-england-59522243?at_medium=RSS&at_campaign=KARANGA tustin 2021-12-03 19:09:59
ニュース BBC News - Home Michigan school shooting: Parents of gunman charged with manslaughter https://www.bbc.co.uk/news/world-us-canada-59523682?at_medium=RSS&at_campaign=KARANGA handgun 2021-12-03 19:49:08
ニュース BBC News - Home Covid-19: Ireland closes nightclubs and tightens Covid rules https://www.bbc.co.uk/news/world-europe-59517114?at_medium=RSS&at_campaign=KARANGA restrictions 2021-12-03 19:33:32
ニュース BBC News - Home Christmas parties: Conservative staff event going ahead, says chairman https://www.bbc.co.uk/news/uk-politics-59517527?at_medium=RSS&at_campaign=KARANGA festive 2021-12-03 19:14:17
ビジネス ダイヤモンド・オンライン - 新着記事 中国発「海底撈火鍋」急拡大から一転300店舗閉鎖の裏で起きていたこと - DOL特別レポート https://diamond.jp/articles/-/289521 2021-12-04 04:50:00
ビジネス ダイヤモンド・オンライン - 新着記事 「エキゾチックアニマルはかわいい」で炎上したテレビ番組は何がいけなかったか - 井の中の宴 武藤弘樹 https://diamond.jp/articles/-/289520 朝の情報番組 2021-12-04 04:45:00
ビジネス ダイヤモンド・オンライン - 新着記事 人生に失望や不安を抱く「中年の危機」、乗越える3つの方法とは - News&Analysis https://diamond.jp/articles/-/287395 instagram 2021-12-04 04:40:00
ビジネス ダイヤモンド・オンライン - 新着記事 かつての兄弟国がなぜ戦闘状態に?ウクライナ紛争の背景を読む - 世界の紛争地図 すごい読み方 https://diamond.jp/articles/-/288892 世界各地 2021-12-04 04:35:00
ビジネス ダイヤモンド・オンライン - 新着記事 ディカプリオも踊らされた!?美術界の闇に迫った仏ドキュメンタリー映画とは - 地球の歩き方ニュース&レポート https://diamond.jp/articles/-/289120 ディカプリオも踊らされた美術界の闇に迫った仏ドキュメンタリー映画とは地球の歩き方ニュースレポート年、世界を驚かせる取引が成立しました。 2021-12-04 04:30:00
ビジネス ダイヤモンド・オンライン - 新着記事 「なぜ、サッカー界に大谷翔平級の選手がいないのか?」セルジオ越後が語る意外な理由 - from AERAdot. https://diamond.jp/articles/-/289156 「なぜ、サッカー界に大谷翔平級の選手がいないのか」セルジオ越後が語る意外な理由fromAERAdotもしも、サッカー界に大谷翔平級の選手がいたら……。 2021-12-04 04:25:00
ビジネス ダイヤモンド・オンライン - 新着記事 10万円~40万円台で買える!「オールブラックダイバーズ時計」 - 男のオフビジネス https://diamond.jp/articles/-/289097 防水 2021-12-04 04:20:00
ビジネス ダイヤモンド・オンライン - 新着記事 「1日1万歩」に科学的根拠はない!?由来は日本発の健康グッズだった - ヘルスデーニュース https://diamond.jp/articles/-/289455 しかし、実はこの「万」という数字は、もともと医師や専門家が提唱したものではなく、年代半ばに日本で発売された「万歩計」という商品名に由来している。 2021-12-04 04:15:00
ビジネス ダイヤモンド・オンライン - 新着記事 コミュニティ中心のマーケティングが長期と短期両方の価値をもたらす - 池田純のプロスポーツチーム変革日記 https://diamond.jp/articles/-/289353 2021-12-04 04:12:00
ビジネス ダイヤモンド・オンライン - 新着記事 若い世代が「社会に役立つかどうか」で仕事を選ぶ本質的な理由とは? - PURPOSE パーパス https://diamond.jp/articles/-/287999 purpose 2021-12-04 04:10:00
ビジネス ダイヤモンド・オンライン - 新着記事 ひろゆきが「35歳までに見つけないと手遅れ」と語る、残酷な事実 - 1%の努力 https://diamond.jp/articles/-/288925 youtube 2021-12-04 04:05:00
ビジネス 東洋経済オンライン イギリスの「鉄道防犯対策」は日本と何が違うか ロンドン同時テロ後に防犯カメラ設置を徹底 | 海外 | 東洋経済オンライン https://toyokeizai.net/articles/-/472982?utm_source=rss&utm_medium=http&utm_campaign=link_back 日本国内 2021-12-04 04:30:00
GCP Cloud Blog Using Google Cloud Service Account impersonation in your Terraform code https://cloud.google.com/blog/topics/developers-practitioners/using-google-cloud-service-account-impersonation-your-terraform-code/ Using Google Cloud Service Account impersonation in your Terraform codeTerraform is one of the most popular open source infrastructure as code tools out there and it works great for managing resources on Google Cloud  When you re just kicking the tires and learning how to use Terraform with Google Cloud having the owner role on the project and running Terraform yourself makes things very easy  That s because with unlimited permissions you can focus on understanding the syntax and functionality without getting distracted by any issues caused by missing IAM permissions However once you re past that or if it s just not possible in the project you re working from it s a good idea to limit your own permissions and get into the habit of running your Terraform code as one or more service accounts with just the right set of IAM roles  A service account is a special kind of account that is typically used by applications and virtual machines in your Google Cloud project to access APIs and services  Applications and users can authenticate as a service account using generated service account keys  The downside to this approach is that it creates a security risk as soon as the key is generated and distributed Any user with access to a service account key whether authorized or not will be able to authenticate as the service account and access all the resources for which the service account has permissions  Fortunately there s another way to run Terraform code as a service that s generally safer service account impersonation  Creating resources as a service accountTo begin creating resources as a service account you ll need two things First you ll need a service account in your project that you ll use to run the Terraform code  This service account will need to have the permissions to create the resources referenced in your code Second  you ll need to have the Service Account Token Creator IAM role granted to your own user account  This role enables you to impersonate service accounts to access APIs and resources  The IAM role can be granted on the project s IAM policy thereby giving you impersonation permissions on all service accounts in the project However if you re adhering to the principle of least privilege the role should be granted to you on the service account s IAM policy instead Once you have a service account and the Service Account Token Creator role you can impersonate service accounts in Terraform in two ways set an environment variable to the service account s email or add an extra provider block in your Terraform code For the first method set the GOOGLE IMPERSONATE SERVICE ACCOUNT environment variable to that service account s email For example After that any Terraform code you run in your current terminal session will use the service account s credentials instead of your own  It s a quick and easy way to run Terraform as a service account but of course you ll have to remember to set that variable each time you restart your terminal session You ll also be limited to using just one service account for all of the resources your Terraform code creates   For the second method you will need to add a few blocks into your Terraform code preferably in the provider tf file that will retrieve the service account credentials  First set a local variable to the service account email You can also set this variable by writing a variable block and setting the value in the terraform tfvars file  Either way works fine  Next create a provider that will be used to retrieve an access token for the service account The provider is “google but note the “impersonation alias that s assigned to it Next add a data block to retrieve the access token that will be used to authenticate as the service account  Notice that the block references the impersonation provider and the service account specified above And finally include a second “google provider that will use the access token of your service account With no alias it ll be the default provider used for any Google resources in your Terraform code Now any Google Cloud resources your Terraform code creates will use the service account instead of your own credentials without the need to set any environment variables With this method you also have the option of using more than one service account by specifying additional provider blocks with unique aliases Updating remote state files with a service accountWhen you run Terraform code it keeps track of the Google Cloud resources it manages in a state file By default the state file is generated in your working directory but as a best practice the state file should be kept in a GCS bucket instead  When you specify a backend you need to provide an existing bucket and an optional prefix directory to keep your state file in  If this bucket exists but your user account doesn t have access to it a service account that does have access can be used instead   Once again you ll need the Service Account Token Creator role granted via the service account s policy  This service account can be different from the one you ll use to execute your Terraform code Specifying the service account here is as simple as adding the impersonate service account argument to your backend block With this one argument added to your backend block a service account will read and update your state file when changes are made to your infrastructure and your user account won t need any access to the bucket only to the service account The advantages of impersonationThe methods above don t require any service account keys to be generated or distributed  While Terraform does support the use of service account keys generating and distributing those keys introduces some security risks that are minimized with impersonation  Instead of administrators creating tracking and rotating keys the access to the service account is centralized to its corresponding IAM policy  By using impersonation the code becomes portable and usable by anyone on the project with the Service Account Token Creator role which can be easily granted and revoked by an administrator Related ArticleProvisioning Cloud Spanner using TerraformProvisioning and scaling Cloud Spanner and deploying an application on Cloud Run using Terraform templates Read Article 2021-12-03 19:30:00

コメント

このブログの人気の投稿

投稿時間: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件)