python |
Pythonタグが付けられた新着投稿 - Qiita |
世界一難しいナンプレを1秒で解く方法 |
https://qiita.com/shinichi1729/items/ac7d88b11b9d72b016bf
|
defsolvegridxyify終了判定returnTrueifxgt行下がるreturnsolvegridyifgridyx既にマスが埋まっているreturnsolvegridxyforkinrange先ほど定義した関数で値kをgridyxに入れられるか判定ifpossiblegridxykgridyxkifsolvegridxy次のマスを見るreturnTruegridyxここが重要returnFalse下から行目にgridyxとしている行がありますね。 |
2021-11-14 22:52:19 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
【本紹介】初心者フロントエンドエンジニアがおすすめできる今年読んだ本を紹介(前編) |
https://qiita.com/hiroyuki_0507/items/2d9240c653d49e3f1370
|
【冊目】プロになるためのWeb技術入門書籍紹介著者小森裕介出版社技術評論社初版発行年月日年月日金額円ページ数p難易度初級・中級・上級で判断初級簡単な感想タイトルの通りWebの背景や歴史を学べる入門者には優しい書籍。 |
2021-11-14 22:52:17 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
【JavaScript】イベント・イベントハンドラ① 「概要説明」 |
https://qiita.com/Stack_up_Rising/items/c155b2dda05b7e497d94
|
イベントハンドラのネーミングパターンネーミングパターンとして、「on」キーワードの隣にイベント名をくっつけたものがイベントハンドラのネーミングパターンとなっている。 |
2021-11-14 22:40:23 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
AWSのS3、ECRにおけるライフサイクルポリシーの設定 |
https://teratail.com/questions/369304?rss=all
|
・Sに格納されたzipのうち、ltobjectgtと名前がついてるについて個保持する。 |
2021-11-14 22:57:29 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
JavaScriptでドラッグアンドドロップで並び替え |
https://teratail.com/questions/369303?rss=all
|
JavaScriptでドラッグアンドドロップで並び替え前提・実現したいことJavaScriptでドラッグアンドドロップの機能をつかって英語の並び替えをしたいのですが英語の並べ替えが正解だったら正解と表示するようにしたいです。 |
2021-11-14 22:51:41 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Ubuntu Server 20.04で固定IPアドレスを設定したいです。 |
https://teratail.com/questions/369302?rss=all
|
UbuntuServerで固定IPアドレスを設定したいです。 |
2021-11-14 22:51:10 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
dockerにてブラウザ表示が出来る理由 |
https://teratail.com/questions/369301?rss=all
|
apache |
2021-11-14 22:46:25 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
モーダルを再度開いた場合にトップ部分から表示したい&モーダル間の遷移を可能にしたいです。 |
https://teratail.com/questions/369300?rss=all
|
モーダルを再度開いた場合にトップ部分から表示したいモーダル間の遷移を可能にしたいです。 |
2021-11-14 22:39:47 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
preventDefaultについて |
https://teratail.com/questions/369299?rss=all
|
preventDefaultについてクリックイベントを無効にするため、preventDefaultを設定しましたが上手くいきません。 |
2021-11-14 22:18:52 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
sassc のインストールがおそすぎる |
https://qiita.com/TatsuyaIsamu/items/a6bca03ae3495d6ffe55
|
sasscのインストールがおそすぎる前々から思ってたけどbundleinstallのときsasscのインストールがおそすぎるそのせいDockerのイメージを作る際にタイムアウトエラーみたいになるのが頻発。 |
2021-11-14 22:23:11 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
rSpec 複数のセレクターを所得して配列みたいに指定する |
https://qiita.com/TatsuyaIsamu/items/15d1011b5668fc723e9f
|
findclass |
2021-11-14 22:13:47 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
kaminari のメソッドのレシーバーが配列のときどうするか |
https://qiita.com/TatsuyaIsamu/items/1bb70d6056f064e212f1
|
kaminariのメソッドのレシーバーが配列のときどうするか上の画像では右側のユーザーがcurrentuserなんだけど自身のアカウントは検索画面で表示されないようにしたかった開発環境rubyRubyonRails前提userの認証機能があるアプリslimを使って書いているkaminariのページネーションでuserの一覧を表示している検索機能を実装しているnextメソッドまず考えたのはnextメソッドuserhtmlslimuserseachdouserifusercurrentusernextこんなかんじで繰り返し処理のなかでcurrentuserだったらスキップするしかし繰り返しはスキップされているけどcssは生成されてしまっているこれではダサいrejectメソッド繰り返しをスキップするのではなくDBのデータを加工するべきだと考えたrejectメソッドをつかってみるコードはusercontrollerrbusersqresultdistincttrueusersusersrejectuserusercurrentuserこんなかんじ。 |
2021-11-14 22:10:09 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
【初心者向け】Rubyインストール時の注意点 |
https://qiita.com/OKIDOKI000/items/25c37dd354aa471f5690
|
インストーラをダウンロードできたら、実行する前にセキュリティソフトを一時停止した方が無難です。 |
2021-11-14 22:07:16 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
docker-compose public の内容が反映されないときに疑うべきこと |
https://qiita.com/TatsuyaIsamu/items/09c6e796a7323a9b319b
|
dockercomposepublicの内容が反映されないときに疑うべきことEC上にてdockercomposeをつかってイメージをビルドした際にpublicの内容が反映されなかった。 |
2021-11-14 22:20:02 |
GCP |
gcpタグが付けられた新着投稿 - Qiita |
terraformを実行する強い権限をSAにもたせ、権限の借用を用いて最小限の権限のユーザーがterraformを実行できるようにする |
https://qiita.com/heronry/items/75cdf8576b9b24e13f05
|
terraformを実行する強い権限をSAにもたせ、権限の借用を用いて最小限の権限のユーザーがterraformを実行できるようにするやりたいことterraformはリソースの作成消去を伴うので強い権限をもたさないといけないそのような強い権限は、リソース操作を定常的に行わければ不要なので、個別ユーザーに直接権限をもたせたくないそのような要件を実現するための方法になりますというのを実現するために以下の手順を見つけたのですが、そのままではうまくいかなかったため、工夫して実用できるようにした、という記事になります参考また、このような方法によらず、本来terraformの実行を人の手を介さないでCICDを利用するアプローチのほうが理にかなっているかもしれません用途VPCServiceControlを設定する場合はSAを通じてteerraform実行が必要なので、ユーザーからVPCServiceControlのリソースを操作したい場合は、このような実行方法を要することになると思います※未検証準備準備作業及び設定までは強い権限を持ったユーザーで行う必要がありますまた、プロジェクトにクォータを追加しないとエラーになるので、予め設定しておきますmyusermypcgcloudauthapplicationdefaultsetquotaprojectmyprojectAPIcloudresourcemanagergoogleapiscomnotenabledonprojectWouldyouliketoenableandretrythiswilltakeafewminutesyNyEnablingservicecloudresourcemanagergoogleapiscomonprojectOperationoperationsacfpfinishedsuccessfullyCredentialssavedtofileUsersmyuserconfiggcloudapplicationdefaultcredentialsjsonThesecredentialswillbeusedbyanylibrarythatrequestsApplicationDefaultCredentialsADCQuotaprojectmyprojectwasaddedtoADCwhichcanbeusedbyGoogleclientlibrariesforbillingandquotaNotethatsomeservicesmaystillbilltheprojectowningtheresourceちゃんと設定できていないと以下のように怒られますWARNINGCannotaddtheprojectmyprojecttoADCasthequotaprojectbecausetheaccountinADCdoesnothavetheserviceusageservicesusepermissiononthisprojectYoumightreceiveaquotaexceededorAPInotenablederrorRungcloudauthapplicationdefaultsetquotaprojecttoaddaquotaprojectちなみにserviceusageservicesuseはrolesserviceusageserviceUsageConsumerに含まれていますtfstateの用意backendとしてgcsを簡易的に用意しておきまますSAではなくユーザーにbackendにアクセスするための権限が必要になりますprojectidmyprojectidlocaleuswestgsutilmbpprojectidcstandardllocalebongstfstategsutiliamchusermyaccountmydomaincomrolesstorageadmingsprojectidtfstatecatltltEOFgtlifecyclejsonlifecycleruleactiontypeDeleteconditionnumNewerVersionsEOFgsutillifecyclesetlifecyclejsongstfstatermlifecyclejson設定端的にterraformでの設定を示しますsetbackendterraformbackendgcsbuckettfstateprefixterraformstateprepareproviderfortokenprovidergooglealiastokengendatagoogleclientconfigdefaultprovidergoogletokengensasettingsresourcegoogleserviceaccountsatfexcprovidergoogletokengenaccountidsatfexecprojectvarbasicprojectgivestrongroleforSAresourcegoogleprojectiammembersatcexecroleprovidergoogletokengenprojectvarbasicprojectforeachtosetroleseditorroleeachvaluememberserviceAccountgoogleserviceaccountsatfexcemaildependsongoogleserviceaccountsatfexcmyuseraccountgivesminimumroleforinitialaccesstogcsbackendresourcegoogleprojectiammembermyminimumroleprojectvarbasicprojectforeachtosetrolesserviceusageserviceUsageConsumerrolesiamserviceAccountUserrolesviewerroleeachvaluememberusermyaccountmydomaincomrolesimpersonateresourcegoogleserviceaccountiammembersatfexecmemberprovidergoogletokengenserviceaccountidgoogleserviceaccountsatfexcnamerolerolesiamserviceAccountTokenCreatormemberusermyusermydomaincomdependsongoogleserviceaccountsatfexcmyusermydomaincomの利用時にコメントを外すcreatetokenwithlifetimeforinpersonateuserdatagoogleserviceaccountaccesstokensaprovidergoogletokengentargetserviceaccountgoogleserviceaccountsatfexcemaillifetimesscopescloudplatformsetdefauiltproviderwithtokenprovidergoogleaccesstokendatagoogleserviceaccountaccesstokensaaccesstokenprojectvarbasicprojectregionvarbasicregionvariablebasictypemapanydefaultprojectmyprojectregionuswestzoneuswestb最初のリソース作成時はtokenを利用しないのでコメントアウトしていますが、tokenを利用する際にコメントを外しますリソースを作り終えたら、権限の借用を行うユーザーに切り替えてlogingcloudauthapplicationdefaultlogin実行例mypcmyusergcloudauthapplicationdefaultloginYourbrowserhasbeenopenedtovisitclientidxxxCredentialssavedtofileUsersmyuserconfiggcloudapplicationdefaultcredentialsjsonThesecredentialswillbeusedbyanylibrarythatrequestsApplicationDefaultCredentialsADCQuotaprojectmyprojectwasaddedtoADCwhichcanbeusedbyGoogleclientlibrariesforbillingandquotaNotethatsomeservicesmaystillbilltheprojectowningtheresource構成検証providerを段で構成しており、最初のproviderはSAを含むtokenを発行するために用意するつ目のproviderは通常のものこちららでリソースを作っていく検証としてバケットを作ってみますresourcegooglestoragebucketbuketnametestbucketlocationuswestgt成功するはずですtokenは有効期限が切れれば使えなくなるので、terraformを実行するときだけ強い権限を持つということが実現できました。 |
2021-11-14 22:29:52 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
sassc のインストールがおそすぎる |
https://qiita.com/TatsuyaIsamu/items/a6bca03ae3495d6ffe55
|
sasscのインストールがおそすぎる前々から思ってたけどbundleinstallのときsasscのインストールがおそすぎるそのせいDockerのイメージを作る際にタイムアウトエラーみたいになるのが頻発。 |
2021-11-14 22:23:11 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
rSpec 複数のセレクターを所得して配列みたいに指定する |
https://qiita.com/TatsuyaIsamu/items/15d1011b5668fc723e9f
|
findclass |
2021-11-14 22:13:47 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
kaminari のメソッドのレシーバーが配列のときどうするか |
https://qiita.com/TatsuyaIsamu/items/1bb70d6056f064e212f1
|
kaminariのメソッドのレシーバーが配列のときどうするか上の画像では右側のユーザーがcurrentuserなんだけど自身のアカウントは検索画面で表示されないようにしたかった開発環境rubyRubyonRails前提userの認証機能があるアプリslimを使って書いているkaminariのページネーションでuserの一覧を表示している検索機能を実装しているnextメソッドまず考えたのはnextメソッドuserhtmlslimuserseachdouserifusercurrentusernextこんなかんじで繰り返し処理のなかでcurrentuserだったらスキップするしかし繰り返しはスキップされているけどcssは生成されてしまっているこれではダサいrejectメソッド繰り返しをスキップするのではなくDBのデータを加工するべきだと考えたrejectメソッドをつかってみるコードはusercontrollerrbusersqresultdistincttrueusersusersrejectuserusercurrentuserこんなかんじ。 |
2021-11-14 22:10:09 |
技術ブログ |
Developers.IO |
[Terraform]EC2 LinuxのOS設定やパッケージ追加をユーザデータとcloud-initで完結させる |
https://dev.classmethod.jp/articles/terraform-ec2-linux-settings-userdata-cloud-init/
|
apache |
2021-11-14 13:17:48 |
海外TECH |
DEV Community |
How to become a Certified Spring Developer Professional in 2022 |
https://dev.to/javinpaul/how-to-become-a-certified-spring-developer-professional-in-2022-5f31
|
How to become a Certified Spring Developer Professional in Disclosure This post includes affiliate links I may receive compensation if you purchase products or services from the different links provided in this article Hello Java programmers If you want to become a certified Spring developer or certified Spring professional then you may know that you need to pass the Vmware s Spring v certification with code EDU in That s the only way to become a certified Spring developer in In my last article I talked about ways to become a certified Java developer and today will share steps and resources to become a certified Spring Developer or Professional in If you have been doing Java development then you may know the benefits of the Spring Framework that make it one of the best Java frameworks in the community As an open source framework Spring offered the opportunity to build applications on the Java Enterprise Edition platform First introduced in October Spring Framework obtained a recent stable release in the form of Spring v which brought things like Reactive programming and WebFlux There is a huge demand for Java developers with Spring experience in fact Spring is often considered as the most important skill while hiring Java developers and many companies prefer to hire those candidates who have Spring Professional certification in their resume That s why more and more Java developers want to become Spring certified The Spring Core Professional v VMware EDU is not an easy certificate and a few years ago you can t even be eligible for that unless spending on official training but that restriction has been lifted a couple of years ago and more and more Java developers are now getting certified for their Spring expertise and experience to give their career a boost The Spring framework is all over the world in Java and developers could have many promising job opportunities Plus get industry recognition and a better salary So if you re still thinking about finding the right path to a better career this is your solution Start focusing on preparing for Spring Professional certification and earn Spring Developer certification Although the advice and reliable information on the Spring Professional v exam preparation path is quite limited The following discussion will attempt to present a detailed preparation guide for certification for Spring developers The highlights highlighted during the discussion would be basic information about the exam and exam objectives The discussion will also present readable ideas on the topics covered in different areas covered by the exam How to become a Certified Spring Professional in Finally in this article you will get to know about the preparation guide for Spring Professional Certification Let s get started with the steps to become a certified Spring developer and resources you need to pass this prestigious certification for Java developers Spring Core Professional v ExamThe Spring Professional Certification exam is especially for those candidates who can use Spring Framework in Java Application development Candidates who have knowledge of dependency injection and spring containers can take this exam The Spring Core Professional Certification exam VMware EDU validates the candidate s ability to test various concepts of the spring framework Spring Professional Certification Exam InformationNow let s take a closer look at the Spring Professional v exam The exam will include questions The format of the exam will be supervised and candidates will receive only multiple choice questions The exam has the code EDU The duration of the exam would be around minutes or an hour and a half The mark required for the exam is Therefore you must correctly answer at least questions to evaluate the exam You can use the following table to get an organized idea of your information on the Spring Professional Certification Exam VMware EDU Here is some more useful information about the Spring Core Professional v certification exam Objective covered in Spring ProfessionalAfter reflecting on the exam information related to the Spring Professional certification let s find out the areas of the exam Knowing the weight of individual subjects during the exam can provide better advice for preparation Like Candidates can focus on topics that present a high weight of exam questions Here are the crucial areas covered by the professional spring exam Container AOP JDBC Transactions MVC Security REST JPA Spring Data Testing Spring Boot Intro Spring Boot Autoconfig Spring Boot Actuator Spring Boot Testing Tips to Crack Spring Professional Certification ExamThis is a very important part of this discussion is the Spring Professional v Certification Exam VMware EDU Preparation Guide I will share the steps that must be taken to pass the spring professional exam Understand Domain of Spring Professional ExamThe candidates priority should be the exam objectives You should take a closer look at the program outlined for the spring professional exam The study guide on the official Spring certification website Vmware is a useful tool to learn more about the exam topics Once you understand the exam topics you can set up an exam preparation program You can assign different periods in your program to prepare different subjects for the exam Choose the best Online Course for Spring CertificationThe next important step in the process of preparing for the professional spring certification is a prolific training course The recommended source for a spring professional exam training course is Vmware Core Spring training is recommended in the exam file on the official Pivotal website The training course is ideal for obtaining Spring certification and improving understanding of Spring functionality and its advanced modules but it s very expensive and can cost you the tune of If you can afford it then by all means go for it but if you are looking for more affordable options then you should check the Spring Professional Certification Guide on Udemy It s a collection of courses each covering one module required to prepare for Spring certification You can buy these courses for each on Udemy sales which happen every now and then I highly recommend these courses along with the Spring Professional v simulator to anyone who is preparing for spring certification as it answers questions given Spring official exam guide and also teaches you key concepts required to answer those questions using appropriate code examples And if you need more material you can also checkout following courses to learn individual topics like Spring MVC Spring Boot Testing Spring Data JPA Spring Security etc Other Useful Courses Spring and Hibernate for BeginnersSpring Framework Beginner to GuruREST With SpringSpring Security Zero to MasterReactive Programming with Spring Spring MVC for BeginnersWhat s New in Spring Testing Spring Boot Beginner to Guru Best Books for Spring Professional ExamRecommended Spring Professional reading materials can also be helpful for preparation The fifth edition of Spring in Action is ideal for Spring v Another recommended reading is Pivotal Certified Professional Spring Developer Exam A Study Guide This book has not been updated with Spring v However you can find many useful resources regarding the new version of this book Here are the other useful books Pro Spring An In Depth Guide to the Spring Framework and Its ToolsPro Spring is one of the best reference books of spring It is aimed at developers who already know or work with the spring framework Its main purpose in the book is to allow readers to master the basic themes of spring The book is written by four writers including Lumina Cosmina Rob Harrop Chris Schaefer and Clarence Ho All writers shared their real world experiences using the book They shared their knowledge of Hibernate EJB and Remoting If you are developing a corporate Java application this book can help you learn how to take advantage of the different levels of the application including presentation web transactions etc Spring in Action Fifth EditionSpring in Action is one of the best books you can take to learn Spring Framework Craig Walls wrote it It is also one of the best selling books that have recently been updated to include the Spring update With this book you can learn Reactive programming Microservices and Spring WebFlux It also includes Spring s best practices for installing installing apps and Spring Boot This book is fairly easy to read thanks to Craig Wall s clear style making it one of our best Spring Framework books Spring Design PatternsSpring Design Patterns is another book on the Spring framework that teaches how to improve the development process The book was written by Dinesh Rajput and allows you to learn different design patterns to master the development of effective applications It also presents Spring best practices and uses design models to improve these practices It is a blow that every Spring developer should read at least once By using the book you will be able to speed up the development process and also learn proven methods for solving common problems The templates will also allow you to identify the main problems in your development process In addition the models work with the latest version of Spring which is Other Useful Books Spring Microservices in ActionCloud Native JavaGetting Started with Spring Framework Covers Spring Spring Cookbook Study GroupsFinally you must participate in shared learning The spring professional exam in a new form does not have many sources of guidance Therefore it is necessary to participate in communities and forums Learning communities and forums can help you interact with other candidates As a result you can contribute to the community and learn about the best preparation methods Practice in a real exam like environment before appearingPractical experience is required to obtain good marks on the spring professional certification exam Therefore you need to try a Spring Professional v simulator to practice the actual exam questions like scenarios In other words you need to go for practice tests Even if you have to pay a little more exam simulators can increase your chances of successfully passing the real exam That s all about how to prepare for the Spring Core Professional v Exam and become a certified Spring developer If you follow this template and steps then you are more likely to succeed in this prestigious exam and become a certified Spring professional you always wanted to be As I said there are both tangible and non tangible benefits of passing the Spring Core Professional v Exam You not only improve your knowledge of Spring framework Spring Boot and other Spring projects but also earn a certificate that can give you credibility and improve your job prospects as a Java developer Other Spring certification Resources You May Like Spring Professional v simulator Spring Professional Exam v Study Guide Spring Professional Exam v General Information PDF Courses to prepare for Spring Certification Books to Prepare for Spring Professional Certification Free Courses to learn Spring Boot Free Courses to learn Spring Framework Courses to Learn Microservices with Spring Courses to learn Spring Cloud and MicroserviceThanks for reading this article if you find this guide helpful in becoming a certified Spring developer professional then please share it with your friends and colleagues If you have any questions or feedback then please drop a note |
2021-11-14 13:42:18 |
海外TECH |
DEV Community |
How to simply create beautiful rosette patterns with JavaScript and SVG ✨🖌️ |
https://dev.to/thormeier/how-to-simply-create-beautiful-rosette-patterns-with-javascript-and-svg-3h4i
|
How to simply create beautiful rosette patterns with JavaScript and SVG ️I mean aren t they just beautiful to look at I mean look at them Amazing aren t they The symmetry the complexity the maths Let s build something like this today We ll use an SVG and some JS for that Wait wait wait The maths Yup the maths In order to generate these beautiful patterns we ll need some geometry We re only going to define the radius of the circle of the rosette pattern the amount of segments and a few other variables that contribute to the overall pattern We ll derive the rest from that Let s start by analyzing how rosette patterns are structured The structureThe symmetry of such a circular pattern is given by its segments The same segment is used over and over by mirroring rotating mirroring again and rotating again and so on So to line up the individual elements of a segment the circle needs to be cut into an even number of equally sized meaning same angle slices just like a cake The content of an individual segment doesn t matter It can be anything the mirroring guarantees that the borders between slices line up perfectly Now how does this help us with implementing a rosette pattern We could create a single segment as an SVG and reuse it via SVGs handy lt use gt tag and some transform statements Since SVGs usually come in rectangular shapes only we need some way to know the exact width and height of a segments That s nothing geometry hasn t solved yet Creating a segmentIn order to create a segment we want to know the radius of the final rosette pattern and its angle A segment is roughly speaking a triangular shape Let s do an example If we want to slice a circle into say equally sized slices a single segment would basically look like this If we would like to create triangular shape out of that we can extend the two lines until we find the spot where we can draw a tangent line to the circle forming a triangle Side note In this example the triangle is already a degrees triangle but that only works with segments since ° ° By moving the tangent over and connecting the dots we get a full rectangle containing the segment The height can be calculated with this formula hsegment ∗sin α ∗r h segment sin alpha rhsegment ∗sin α ∗rWith hsegmenth segment hsegment being the height α alphaα being the angle of the segment in this case ° and rrr being the radius of the segment This formula uses the fact that every triangle can be divided into two right angle triangles and that these triangles are similar if the the triangle has two sides of equal length The width can then be calculated using Pythagorases theorem wsegment r hsegment ∗∗ w segment sqrt r h segment wsegment r hsegment ∗∗You may have noticed that we re not using the radius directly here Calculating the width again from the radius and the height will make the triangle have the actual angle we want Otherwise it would be a bit too narrow With the height and the width of the segment we can now also calculate the final width and height of the entire rosette SVG using Pythagorases theorem hpattern ∗ hsegment r h pattern sqrt h segment r hpattern ∗ hsegment r wpattern hpattern w pattern h pattern wpattern hpatternNow we know how to get the size of a segment Let s take care of its content Generating a segments contentWe re gonne be a bit cheap about that Let s just use more circles By randomly placing differently colored and differently sized circles into the rectangle and cutting them off at the edges of the triangle we can create very interesting shapes and designs To select a bunch of colors that go well together we will use a technique described in this Twitter thread Vegard Danger Whatofit Myklebust usefulslug Mini tech art tutorial How to randomly pick colours that will go well together gamedev indiedev AM May The technique is rather straight forward Generate a random HSL color add or any number really to its hue chose random lightness and saturation values and you ve got two colors Repeat that with the second color to get a third one and repeat a few more times until you ve got the number of colors you want If you don t know how HSL colors work this post I did a while ago has an in depth explanation Let s build a rainbow on a canvas from scratch Pascal Thormeier・Sep ・ min read webdev tutorial javascript mathematics So far so good I think we can start coding Let s code the foundationLet s start with a rounding function and random number function because JavaScripts Math random is kind of bulky at times Rounds a number param n Number to round param places Number of places to round to returns number const round n places gt Math round n places places Random number between min and max param min Lower end of range param max Upper end of range param precision Number of decimal places returns const rand min max precision gt return round Math random max min min precision Next we create a Color class and a function that creates a palette of a given size I ll add a function to the Color class that gives me the next color Represents a color class Color Constructor param h Hue param s Saturation param l Lightness constructor h s l this h h this s s this l l Creates a random color returns Color static createRandom return new Color rand rand rand Generates the next color param hueStepSize By how much the Hue value should change returns Color getNextColor hueStepSize let nextHue this h hueStepSize Wrap around if hue is not between and if nextHue lt nextHue else if nextHue gt nextHue return new Color nextHue rand rand Get a string representation of this color returns string toString return hsl this h this s this l Creates a color palette of a given size param numberOfColors Number of colors param hueStepSize By how much the hue should change returns const getRandomColorPalette numberOfColors hueStepSize gt const colors let currentColor Color createRandom colors push currentColor while numberOfColors gt currentColor currentColor getNextColor hueStepSize colors push currentColor numberOfColors return colors Off for a good start Next we ll create a Circle class that represents part of the content of a single segment class Circle Represents a circle within a segment param cx param cy param r param color constructor cx cy r color this cx cx this cy cy this r r this color color Get a string representation of this circle returns string toString return lt circle cx this cx cy this cy r this r fill this color toString stroke stroke width gt Next up we want to create a Segment class that can generate its own circles class Segment Represents a single Segment param width Width of the segments rectangle param height Height of the segments rectangle param numberOfCircles Number of circles it should contain param colorPalette The color palette used constructor width height numberOfCircles colorPalette this width width this height height this circles this generateCircles numberOfCircles colorPalette Generates a given number of random circles with different colors from a given palette param numberOfCircles Number of circles to generate param colorPalette Palette to chose colors from generateCircles numberOfCircles colorPalette while numberOfCircles gt to of the segments width const radius rand this width this width this circles push new Circle Width radius guarantees that the circle doesn t overlap the width rand this width radius rand this height radius colorPalette rand colorPalette length numberOfCircles Creates a string representation of this segment returns string toString Notice how I left out the toString method of the segment I want to give this one some special attention In order to cut out the actual segment we ll use clippath Remember the triangle from earlier Its points align perfectly with the top right bottom right and center left of the rectangle class Segment Creates a string representation of this segment param id DOM id for referencing returns string toString id This is used to scale the clippath a bit without using transform scale When finished there will be some artifacts at the borders this reduces them const tolerance return lt svg width this width tolerance height this height tolerance id id gt lt defs gt lt clipPath id triangle gt lt scaleZ forces GPU rendering gt lt polygon transform scaleZ points tolerance this height this width tolerance tolerance this width tolerance this height tolerance gt lt clipPath gt lt defs gt lt g style clip path url triangle gt this circles map c gt c toString join n lt g gt lt svg gt However we added the tolerance variable SVG s transform in combination with clippath adds some artifacts at the borders of the triangle I haven t exactly figured out why this is happening but enlarging the segment just a tiny little bit is already helping a lot Let s try that const segment new Segment width height number of circles getRandomColorPalette const container document createElement div container innerHTML segment toString segment document body appendChild container And we get something like this Almost there Now we only need to repeat the segment a few times Creating the full patternNext up we need a class called Pattern that shows all the segments by rotating and mirroring them class Pattern Creates a full pattern param numberOfSegments param radius constructor numberOfSegments radius this numberOfSegments numberOfSegments const angle numberOfSegments The formula we used earlier angle Math PI is necessary because Math sin uses radians instead of degrees const segmentHeight Math sin angle Math PI radius const segmentWidth Math sqrt radius segmentHeight const colorPalette getRandomColorPalette this segment new Segment segmentWidth segmentHeight rand colorPalette this segmentHeight this segment height this width Math sqrt this segment height radius this height this width Creates a string representation of this pattern returns string toString To render the entire pattern we first need to get the rotation working Creates a string representation of this pattern returns string toString const segments let numberOfSegmentsLeft this numberOfSegments while numberOfSegmentsLeft gt Rotate the segment const rotationRadius this numberOfSegments numberOfSegmentsLeft let transformRotation rotate rotationRadius segments push lt use href segment transform transformRotation translate this width this width this segmentHeight transform origin this width this width gt lt use gt numberOfSegmentsLeft return lt div gt this segment toString segment lt div gt lt div gt lt svg width this width height this height gt segments join n lt svg gt lt div gt Now to flip every second segment we need to add a scale to the transform let transformRotation rotate rotationRadius if numberOfSegmentsLeft transformRotation scale The resultAnd here s the result And since everything s random every pattern you get is unique and is only ever generated for you If the one you see on load is boring simply click on the Show new button to hopefully get a more beautiful one I hope you enjoyed reading this article as much as I enjoyed writing it If so leave a ️or a I write tech articles in my free time and like to drink coffee every once in a while If you want to support my efforts you can offer me a coffee or follow me on Twitter You can also support me directly via Paypal |
2021-11-14 13:36:25 |
海外TECH |
DEV Community |
A Philosophy of Software Design: It is All About Complexity |
https://dev.to/inspiratory/a-philosophy-of-software-design-it-is-all-about-complexity-4ib1
|
A Philosophy of Software Design It is All About Complexity It is All About ComplexityA Philosophy of Software Design by John Ousterhout is one of my favorite books on Software Development It talks about how building software is all about managing complexity There are two ways we can deal with this complexity Write simple and obvious code to eliminate complexity Or encapsulate the complexity so that you don t have to deal with it A software system is complex if it is hard to understand or modify Another measure of complexity is how much time you spend dealing with the complexity in the system If there is complexity in the system that is isolated in an area that you don t have to interface with then this is equivalent to removing complexity Complex systems are hard to changehard to understandhard to predictSince complexity can be managed by hiding it it becomes important how we surface that complexity for other components in the system to interact with One of the most important techniques for managing software complexity is by designing systems where you only need to deal with a small position of complexity at a time This is called modular design A module can be thought of as a service component class or function Essentially it is any structure that encapsulates complexity Have Deep ModulesYou should aim to have deep modules that hide a lot of complexity and that expose it through a minimal interface A minimal interface reduces the complexity that a module imposes on the rest of the system It is not worth having shallow modules It is likely that your abstraction is not hiding enough details and the surrounding system has too many touchpoints with the large surface area of a shallow module You should try to find the simplest interface and build a somewhat general purpose module that is deep An example of a deep module is the garbage collector in Python It essentially has no interface and encapsulates a lot of complexity that arises from the task it performs Don t Mix Layers of AbstractionA lot of complexity can also be managed by how you structure things One thing to pay attention to is to have different layers for different abstractions and to not mix those abstractions This would make it easier to think about a given layer without concerning yourself with the rest Application of this principle can manifest itself at the interface of a module It suggests that the representations that are used internally by a module should be different from what is used by the interface Pass through methods and variables break this rule When you pass high level information to a low level method you end up having all the intermediate layers become aware of their existence Pull Complexity DownwardsAnother way of dealing with complexity is by pulling it downwards If you have a module that introduces complexity to the system due to the functionality it provides it is better to hide that functionality inside that module Most modules have more users than developers so it is better to hide the functionality to have the developers deal with it One example of this could be the config parameters They could obviously be useful and provide flexibility but they can also be misused and pass the responsibility of configuration to the users when as a developer you could have handled it dynamically Ideally each module should solve a problem completely and config parameters can indicate an incomplete solution Keep Things TogetherBy creating too many small modules you could increase the surface area of the entire system which could increase the complexity It could also make it harder to read the code since the context is spread around Only break things up if it is going to make the overall system simpler Define Errors out of ExistenceException handling code could be a source of a lot of complexity For one handling exceptions can create its own exceptions Also exception handling code doesn t get executed all that much by its very nature This means it is hard to ensure that it actually works as intended and doesn t suffer from bugs It could additionally be hard to test this kind of code too due to the exceptional circumstances it requires to be invoked A piece of code that raises too many exceptions is shifting the responsibility of dealing with the complexity to the user It would be best if you could just handle the errors silently without notifying the users whenever this makes sense Imagine a networking transport protocol such as TCP You don t receive an exception when a package drops The protocol just handles it automatically by resending it This is the complexity hidden Another simple example of this can be how array list access works in Python and JavaScript This code below would throw an error in Python due to the list index being out of range myList print myList Whereas this operation in JavaScript just returns undefined It doesn t throw an error and hence is less complex to deal with const myArray console log myArray Names and ConsistencyChoosing appropriate names when coding is incredibly important in managing complexity Names are abstractions A wrong or misleading abstraction can increase complexity and can be a source of hard to fix bugs Another thing to be careful about names is their consistent usage Be consistent when naming similar things and don t use that name for anything that is unrelated Consistency is important in general too It helps reduce the complexity in the system by reducing the cognitive burden Consistency plays on our strength in pattern recognition and helps us leverage what we already know That s why it is important to abide by existing conventions Having a better idea of how to do things is not a sufficient excuse to introduce inconsistencies to the system Your new convention should be markedly better than the existing one to replace it CommentsThere are arguments against the usage of comments out there but they can still be valuable One primary argument against comments is that the code should be descriptive enough to reveal what it does But if you have to dive deep into the code to understand its functionality then it means the code doesn t have a good enough abstraction Comments are abstractions that can help you hide complexity Comments can also contain information that might be impossible to capture in the code like hardware quirks etc Comments don t necessarily add a maintenance overhead either if they are high level enough SummaryA Philosophy of Software Design affiliate link is primarily about one thing complexity Dealing with complexity is the most important challenge in software design It is what makes systems hard to build and maintain and it often makes them slow as well You should always evaluate your decisions from the standpoint of complexity to ensure the sustainable continuity of the overall system |
2021-11-14 13:22:45 |
海外TECH |
DEV Community |
What I learned - Error makes me a better programmer |
https://dev.to/suhcrates/what-i-learned-error-makes-me-a-better-programmer-1o4c
|
What I learned Error makes me a better programmerNote The boot camp that I m in is in the Republic of Korea South Korea and does not offer courses in overseas unless you can listen lectures in Korean So this post is not to promote a particular boot camp or any boot camp I think there are some typos and grammatical error in this post I ll fix them tomorrow It s been weeks since I started learning programming full time and I wanted to share some new epiphany I had recently That is making error makes me a better programmer To be more precise making error and trying to fix them make me a better programmer I have heard that adding lines of code into existing program is excruciating It may even bring down a whole system So one must be very careful and thoughtful when writing code What I m trying to convey is that when you re in learning phase feel free to make many error A good thing about programming is that the number of error you can make is almost limitless given that you re practicing your skills not actually working on applications currently used by users As someone who came from a domain whose number of trials is often limited it was hard for me to try out code I ve written at first I had to force myself to run things whether I felt sure about my code or not I realized the more I make error the more I learned how to make things work For example when I was learning how to use AWS VPC RDS lambda function and NAT gateway I had to re create lambda functions a number of times because of some error While it felt like I was wasting my time since it could have been done at first try my understanding of the relationship between the VPC RDS NAT gateway and lambda function deepened as my number of tries increased Although it s shameful my initial goal wasn t to understand the VPC and so on it seemed daunting at first but to get through the assignment I was given Unintentionally because of the error I encountered I understood how virtual private clouds work I haven t worked on a real production yet so I can only speak for those who just began to learn programming And for those who just began to code don t be afraid to make error You ll remember and learn more from code that didn t work at first rather than code that worked the first time |
2021-11-14 13:18:09 |
Linux |
OMG! Ubuntu! |
Android Mirror Tool ‘Scrcpy’ Gains New Features, New Icon |
https://www.omgubuntu.co.uk/2021/11/android-mirror-tool-scrcpy-adds-support-for-usb-keyboard-simulation-android-12
|
Android Mirror Tool Scrcpy Gains New Features New IconScrcpy is a super useful Android mirroring tool for desktop PCs The tool gains physical keyboards simulation and a high res app icon in the latest update This post Android Mirror Tool Scrcpy Gains New Features New Icon is from OMG Ubuntu Do not reproduce elsewhere without permission |
2021-11-14 13:13:29 |
海外ニュース |
Japan Times latest articles |
Jakucho Setouchi: A freewheeling nun who bucked conventional norms for women |
https://www.japantimes.co.jp/news/2021/11/14/national/jakucho-setouchi-freewheeling-nun-bucked-conventional-norms-women-dies-age-99/
|
Jakucho Setouchi A freewheeling nun who bucked conventional norms for womenPrior to beginning her religious journey in Jakucho Setouchi established herself first and foremost as a writer ーand a controversial one at that |
2021-11-14 22:02:10 |
ニュース |
BBC News - Home |
COP26: China and India must explain themselves, says Sharma |
https://www.bbc.co.uk/news/uk-59280241?at_medium=RSS&at_campaign=KARANGA
|
sharma |
2021-11-14 13:33:25 |
ニュース |
BBC News - Home |
Queen misses Remembrance Sunday service after back sprain |
https://www.bbc.co.uk/news/uk-59280608?at_medium=RSS&at_campaign=KARANGA
|
monarch |
2021-11-14 13:32:46 |
ニュース |
BBC News - Home |
US bank robber identified after decades-long hunt |
https://www.bbc.co.uk/news/world-us-canada-59280706?at_medium=RSS&at_campaign=KARANGA
|
bizarre |
2021-11-14 13:20:04 |
ニュース |
BBC News - Home |
Ecuador prison riot: New fighting at Guayaquil jail kills 68 |
https://www.bbc.co.uk/news/world-latin-america-59276428?at_medium=RSS&at_campaign=KARANGA
|
guayaquil |
2021-11-14 13:25:48 |
ニュース |
BBC News - Home |
Essex: Former player Zoheb Sharif makes racism allegations dating back to 2001 |
https://www.bbc.co.uk/sport/cricket/59277256?at_medium=RSS&at_campaign=KARANGA
|
sharif |
2021-11-14 13:17:10 |
LifeHuck |
ライフハッカー[日本版] |
ヘッドホンを付けても痛くならないメガネ【今日のライフハックツール】 |
https://www.lifehacker.jp/2021/11/244916lht-godeye.html
|
隙間 |
2021-11-14 22:05:00 |
コメント
コメントを投稿