js |
JavaScriptタグが付けられた新着投稿 - Qiita |
【GAS】テンプレートを元にレポート一覧を作成 |
https://qiita.com/oktaSI/items/3b1f0ea3e5dbca82fb12
|
googleapps |
2023-03-21 07:53:56 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
お母さんでもわかる自分のマニュアル |
https://qiita.com/pix_shimitomo/items/4ef721bc01a56174a674
|
htmlcssjs |
2023-03-21 07:53:48 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
urlsGithubというChromeブラウザの拡張機能を作成。 |
https://qiita.com/taoka-toshiaki/items/67ed8d35675daee0430a
|
chrome |
2023-03-21 07:36:58 |
海外TECH |
Ars Technica |
Deadly drug-resistant yeast gained ground, more drug resistance amid COVID |
https://arstechnica.com/?p=1925412
|
threat |
2023-03-20 22:04:29 |
海外TECH |
DEV Community |
How to Setup Devise for User Authentication on Rails 7 |
https://dev.to/ackshaey/how-to-setup-devise-for-user-authentication-on-rails-7-ojg
|
How to Setup Devise for User Authentication on Rails If you are a frequent user of Ruby on Rails you know that building authentication and user management systems can be a time consuming and complex process That s where Devise comes in ーa powerful authentication solution that simplifies the process of implementing user management systems in your Rails applications As a Rails developer who churns out apps regularly I ve found myself reaching for Devise every single time However with the release of Rails I ve had to adjust my workflow and make sure that Devise works seamlessly with the new version In this blog post I ll share my workflow for setting up Devise on Rails and walk you through the steps to get started with this essential tool So whether you re a seasoned Rails developer or just getting started read on for a comprehensive guide to setting up Devise on Rails Hang on why should I use Devise Authenticating users in a web application is a critical task that requires careful consideration of security bestpractices Building authentication functionality from scratch can be a daunting and time consuming process particularlyfor developers who are not well versed in security principles This is where Devise comes in handy Devise provides a comprehensive and customizable solution that handles common authentication tasks such as user registration login and password resets while also supporting various authentication mechanisms and providing robust security features By using Devise developers can save valuable time and ensure their application s authentication system is strong and reliable allowing them to focus on building other aspects of their application Let s see it in action on Rails PrerequisitesBefore proceeding with the guide ensure that you have a new or barebones Rails app created using rails new Additionally you should not have a User model set up yet Step by Step GuideAdd Devise Letter Opener and Omniauth optional to your Gemfile gem devise github heartcombo devise ref fdeabc gem omniauth group development do gem letter opener endNote cloning Devise from GitHub is necessary because it contains fixes for some Rails incompatibilities Install the gems bundle installRun the Devise install generator rails g devise installThis generates the devise rb initializer and adds the en locale at config locales devise en yml Add the following Devise specific configurations to config development rb For Deviseconfig action mailer default url options host localhost port For Letter Openerconfig action mailer delivery method letter openerconfig action mailer perform deliveries trueconfig action mailer raise delivery errors trueGenerate the User model with Devise rails g devise userThis creates the user model files as well as a preliminary migration Edit the migration to add the fields you need Identifying fieldst string first name null false default t string last name null false default Also uncomment the trackable confirmable and lockable fields and accompanying indexes Edit user rb and add confirmable trackable lockable and omniauthable to Devise Tweak options in config devise rb to suit your needs For example you may want to increase the remember foroption to a couple of months config remember for monthsIn the same file change the default email to one from your application rubyconfig mailer sender no reply designerdiscount club Generate the Devise views so you can modify them later rails g devise viewsMigrate the database rake db migrateAdd the following code to application html erb right above the yield block lt if notice gt lt p class alert alert success gt lt notice gt lt p gt lt end gt lt if alert gt lt p class alert alert danger gt lt alert gt lt p gt lt end gt Try it out Start your rails server and head to http localhost users sign up and create a new user You should receive an email which opens in the browser via letter opener Great it s working Deny logged out access to a controller action and test it out Create a home action in an existing controller which is PagesController in this example class PagesController lt ApplicationController def landing end def home end endLet s redirect the user to the landing page if they try to access home but are logged out def landing redirect to action home params request query parameters if user signed in end def home redirect to action landing params request query parameters unless user signed in endEdit the global header to hide the sign in link if the user is signed in lt if user signed in gt lt li class flex gt lt link to Logout destroy user session path method delete data turbo method delete gt lt li gt lt else gt lt li class flex gt lt link to Sign up new user registration path rel noopener noreferrer gt lt link to Login new user session path rel noopener noreferrer gt lt li gt lt end gt That s it You now have a basic setup for user authentication using Devise on Rails You can customize the generated Devise views with Tailwind or Bootstrap to match your app s design Want to learn more Check out the Devise wiki Preparing for a coding interview Check out Firecode io |
2023-03-20 22:36:08 |
海外TECH |
DEV Community |
Zod 101 - A Typescript-first Schema Validation Library |
https://dev.to/kharioki/zod-101-a-typescript-first-schema-validation-library-4dgm
|
Zod A Typescript first Schema Validation Library The TrailerTypescript is great for checking variables at the top level e g you can specify that the age property for a User should be a number However you can t always be sure what you re going to get from a form input Typescript will present an error if it s not a number but on its own it doesn t know if a number is too low or too high to this usecase There s a similar problem with rd party API responses Why Zod Zod allows you to work around uncertainity by checking types at the runtime level as well at the type level Typescript checks type on the type level Zod checks type on the runtime level What is Zod Zod is a Typescript first schema declaration and validation library It is designed to be very developer friendly It aims to eliminate duplicative type declarations With Zod you can declare a validator once and Zod will automatically infer the static Typescript type for you We ll be using Vitest to run the tests Runtime Checkingconsider the following code export const toString num unknown gt return String num We are taking in a num variable that we ve typed as unknown We then return a stringified version of it unknown This means that we can call toString with anything we want on the type level including object types or undefined toString toString toString object Object toString undefined undefined For now all these would work but we want to prevent this at the runtime level If we call toString with a string we want to throw an error and say it expected a number but received a string Solution update the function to check the type at the runtime level const numberParser z number export const toString num unknown gt const parsed numberParser parse num return String parsed Testsit should throw a runtime error when called with not a number gt expect gt toString toThrowError Expected number received string it should return a strung when called with a number gt expect toString toBeTypeOf string We create a numberParser using the z number function This is a ZodSchema object that we can use to parse the num variable If the num variable is not a number the parse function will throw an error This means that any variable we create by calling numberParser parse will be typed as a number and our tests will pass Verify Unknown APIs with an Object SchemaZod is commonly used for verifying unknown APIs Consider the following API fetch const PersonResult z unknown export const fetchStarWarsPersonName async id string gt const data await fetch id then res gt res json const parsedData PersonResult parse data return parsedData name In the above instance the PersonResult variable is created with z unknown This means that we are saying that we don t know what the API response will be The test does pass it s the issue of PersonResult being typed as unknown that we want to solve Solution update the PersonResult variable to be a ZodObject const PersonResult z object name z string export const fetchStarWarsPersonName async id string gt const data await fetch id then res gt res json const parsedData PersonResult parse data return parsedData name Testsit should return the name async gt expect await fetchStarWarsPersonName toEqual Luke Skywalker expect await fetchStarWarsPersonName toEqual C PO Any additional keys you add to the PersonResult ZodObject from the original API response will be included in the parsedData variable Create an Array of Custom TypesConsider the following API fetch const StarWarsPerson z unknown const StarWarsPeople z unknown export const fetchStarWarsPeople async gt const data await fetch then response gt response json const parsedData StarWarsPeople parse data return parsedData results The correct way to solve this challenge is to create an object that references other objects In this case StarWarsPeople will be a z object that contains results Declaring arrays of objects like this is one of the most common use cases for z array especially when referencing types you already created const StarWarsPerson z object name z string const StarWarsPeople z object results z array StarWarsPerson export const fetchStarWarsPeople async gt const data await fetch then response gt response json const parsedData StarWarsPeople parse data return parsedData results Testsit Should return the name async gt const people await fetchStarWarsPeople expect people name toEqual Luke Skywalker Extracting a Type from a Parser ObjectIn the above example we created a StarWarsPerson object that we used to parse the results array We can extract the type from the StarWarsPerson object using the infer keyword type StarWarsPersonType z infer lt typeof StarWarsPerson gt This will allow us to use the StarWarsPersonType type in other places in our codebase import z from zod const StarWarsPerson z object name z string const StarWarsPeople z object results z array StarWarsPerson const logStarWarsPeople data z infer lt typeof StarWarsPeople gt gt data results map person gt console log person name Make Schemas OptionalZod is also useful for validating user input Consider the following form import expect it from vitest import z from zod const Form z object name z string phoneNumber z string export const validateFormInput values unknown gt const parsedData Form parse values return parsedData TESTSit Should validate correct inputs async gt expect gt validateFormInput name Matt not toThrow expect gt validateFormInput name Matt phoneNumber not toThrow it Should throw when you do not include the name async gt expect gt validateFormInput toThrowError Required The phoneNumber field is optional but we want to make sure that the name field is required We can do this by adding optional to the phoneNumber field const Form z object name z string phoneNumber z string optional Set a Default ValueConsider the following form import z from zod const Form z object repoName z string keywords z array z string optional export const validateFormInput values unknown gt const parsedValues Form parse values return parsedValues Suppose we want to default the keywords field to an empty array if the user does not provide any keywords We can do this by adding default to the keywords field import expect it from vitest import z from zod const Form z object repoName z string keywords z array z string default export const validateFormInput values unknown gt const parsedValues Form parse values return parsedValues Testsit Should include keywords if passed async gt const result validateFormInput repoName vitest keywords test testing expect result toEqual repoName vitest keywords test testing expect result keywords toEqual test testing it Should not include keywords if not passed async gt const result validateFormInput repoName vitest expect result keywords toEqual The Input is Different than the OutputThe validateFormInput function returns an object that is different than the input The keywords field is always an array even if the user does not provide any keywords If we create a FormInput and FornOutput type we can use the z infer keyword to extract the type from the Form object type FormInput z infer lt typeof Form gt type FormOutput z infer lt typeof Form gt Introducing z inputThe above input is not quite correct because when we input into validateFormInput we don t pass in any keywords We can use the z input keyword to extract the input type from the Form object type FormInput z input lt typeof Form gt type FormOutput z infer lt typeof Form gt Being specific with Allowed TypesConsider the following form const Form z object repoName z string privacyLevel z string Suppose we want to make sure that the privacyLevel field is either public or private We can do this by adding enum to the privacyLevel field const Form z object repoName z string privacyLevel z enum public private Another way is to use the z union keyword and pass in an array of z literal objects You can use literal to represent any literal value const Form z object repoName z string privacyLevel z union z literal public z literal private The enum keyword is arguably more readable but the z union keyword is more flexible Complex Schema ValidationConsider the following form import z from zod const Form z object name z string phoneNumber z string optional email z string website z string optional export const validateFormInput values unknown gt const parsedData Form parse values return parsedData Suppose we want to add a few constraints on what the values can be We want to validate that the name is at least character the phone number to have the right amount of digits and we want the website to be a valid URL and email to be a valid email address import z from zod const Form z object name z string min phoneNumber z string min max optional email z string email website z string url optional export const validateFormInput values unknown gt const parsedData Form parse values return parsedData Reducing duplicated code by composing schemasConsider the following code import z from zod const User z object id z string uuid name z string const Post z object id z string uuid title z string body z string const Comment z object id z string uuid text z string There are a few ways we can refactor this code Simple solutionWe can strip out the id into its own type Then we can use the Id type in the User Post and Comment types const Id z string uuid const User z object id Id name z string const Post z object id Id title z string body z string const Comment z object id Id text z string Better solution use the Extend methodAnother solution would be to create a base object ObjectWithId and extend it with the User Post and Comment types const ObjectWithId z object id z string uuid const User ObjectWithId extend name z string const Post ObjectWithId extend title z string body z string const Comment ObjectWithId extend text z string Use MergeWe can also use the merge keyword to merge the ObjectWithId and the User Post and Comment types const User ObjectWithId merge z object name z string Merging is generally used when two different types are being combined rather than extending a single type Transforming Data from within a SchemaAnother useful feature of Zod is manipulating data from an API response after parsing Consider the following API response import z from zod const StarWarsPerson z object name z string const StarWarsPeopleResults z object results z array StarWarsPerson export const fetchStarWarsPeople async gt const response await fetch const data await response json const parsedData StarWarsPeopleResults parse data return parsedData We can use the transform keyword to manipulate the data from the API response In this case we want to transform the name field and add a new field called nameAsArray import z from zod const StarWarsPerson z object name z string transform person gt person nameAsArray person name split const StarWarsPeopleResults z object results z array StarWarsPerson export const fetchStarWarsPeople async gt const data await fetch then res gt res json const parsedData StarWarsPeopleResults parse data return parsedData results TESTSit Should resolve the name and nameAsArray async gt expect await fetchStarWarsPeople toEqual name Luke Skywalker nameAsArray Luke Skywalker You can find the complete code on this repoWhen you meet someone who is not using Vitest to test |
2023-03-20 22:27:10 |
Apple |
AppleInsider - Frontpage News |
Is Apple about to announce a 'Broadcast' App? |
https://appleinsider.com/articles/23/03/20/is-apple-about-to-announce-a-broadcast-app?utm_medium=rss
|
Is Apple about to announce a x Broadcast x App Apple has just denied an update to years old internet radio and live streaming app Broadcasts based on a name likeness rule that is used to prevent developers from copying Apple app names Broadcasts denied for Apple name collisionLongtime developer code sleuth and Apple commentator Steve Troughton Smith has just been denied a routine update to a Mac version of his app Broadcasts The app is more than two years old according to the App Store listing and it hasn t encountered a naming issue before Read more |
2023-03-20 22:11:04 |
海外科学 |
NYT > Science |
Candida Auris, a Deadly Fungus, Spread Rapidly During Pandemic, CDC Says |
https://www.nytimes.com/2023/03/20/health/candida-auris-us-fungus.html
|
Candida Auris a Deadly Fungus Spread Rapidly During Pandemic CDC SaysCandida auris a drug resistant fungus that health officials hoped to contain is now in more than half the states according to a new research paper |
2023-03-20 22:05:02 |
海外科学 |
NYT > Science |
Earth to Hit Critical Global Warming Threshold by Early 2030s |
https://www.nytimes.com/2023/03/20/climate/global-warming-ipcc-earth.html
|
Earth to Hit Critical Global Warming Threshold by Early sA new report says it is still possible to hold global warming to relatively safe levels but doing so will require global cooperation billions of dollars and big changes |
2023-03-20 22:05:21 |
金融 |
金融総合:経済レポート一覧 |
FX Daily(3月17日)~金融システム不安根強く、131円台半ばまで下落 |
http://www3.keizaireport.com/report.php/RID/530456/?rss
|
fxdaily |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
金融政策決定会合における主な意見(2023年3月9・10日開催分) |
http://www3.keizaireport.com/report.php/RID/530460/?rss
|
主な意見 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
BIS国際資金取引統計および国際与信統計の日本分集計結果(2022年12月末現在) |
http://www3.keizaireport.com/report.php/RID/530461/?rss
|
日本銀行 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
米ドル流動性供給を拡充するための中央銀行の協調行動 |
http://www3.keizaireport.com/report.php/RID/530462/?rss
|
中央銀行 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
BISグローバル金融システム委員会報告書「コロナ危機に対する中央銀行の資産買入」の公表について |
http://www3.keizaireport.com/report.php/RID/530463/?rss
|
中央銀行 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
UBSがクレディ・スイスを買収:6中銀はドル供給を強化:木内登英のGlobal Economy & Policy Insight |
http://www3.keizaireport.com/report.php/RID/530465/?rss
|
lobaleconomypolicyinsight |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
UBSがクレディ・スイス買収に向けた交渉を開始:木内登英のGlobal Economy & Policy Insight |
http://www3.keizaireport.com/report.php/RID/530466/?rss
|
lobaleconomypolicyinsight |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
継続する米国の銀行不安:ベイルインとベイルアウト:木内登英のGlobal Economy & Policy Insight |
http://www3.keizaireport.com/report.php/RID/530467/?rss
|
lobaleconomypolicyinsight |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
1分でわかるトレンド解説:【1分解説】ファイナンシャル・ウェルビーイングとは? |
http://www3.keizaireport.com/report.php/RID/530491/?rss
|
第一生命経済研究所 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
1分でわかるトレンド解説:【1分解説】GFANZとは? |
http://www3.keizaireport.com/report.php/RID/530496/?rss
|
gfanz |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
マーケットデータシート:主要国際金融センターの比較 |
http://www3.keizaireport.com/report.php/RID/530501/?rss
|
国際金融情報センター |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
アジア主要通貨・株価の動き(3月17日まで) |
http://www3.keizaireport.com/report.php/RID/530502/?rss
|
国際金融情報センター |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
さらなるキャッシュレス化に向けた課題について整理する(1)~2022年の日本のキャッシュレス化の進展状況の振り返り:基礎研レポート |
http://www3.keizaireport.com/report.php/RID/530522/?rss
|
進展 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
さらなるキャッシュレス化に向けた課題について整理する(2)~さらなるキャッシュレス化に必要な施策について考える:基礎研レポート |
http://www3.keizaireport.com/report.php/RID/530523/?rss
|
課題 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
北米の未上場企業投資の出口戦略から垣間見えるリスクマネー還流の実態:研究員の眼 |
http://www3.keizaireport.com/report.php/RID/530525/?rss
|
出口戦略 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
金融政策の転換と債務残高(対GDP)の行方 |
http://www3.keizaireport.com/report.php/RID/530526/?rss
|
impact |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
欧州:金融政策動向(2023年3月、ECB理事会)~金融市場の不安が高まるなかでも、大幅利上げを継続:MRIデイリー・エコノミック・ポイント |
http://www3.keizaireport.com/report.php/RID/530531/?rss
|
三菱総合研究所 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
シリコンバレー銀行破綻による危機が欧州にも飛び火~試される金融システムのレジリエンス:欧州 |
http://www3.keizaireport.com/report.php/RID/530535/?rss
|
大和総研 |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
ウィークリーレポート 2023年3月20日号~米国株式は欧米の金融システムへの不安が高まる中、一時大幅下落... |
http://www3.keizaireport.com/report.php/RID/530557/?rss
|
三井住友トラスト |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
中国の預金準備率引き下げ~金融市場の安定と景気回復を支えるための金融緩和:マーケットレター |
http://www3.keizaireport.com/report.php/RID/530558/?rss
|
引き下げ |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
【注目検索キーワード】スポーツベッティング |
http://search.keizaireport.com/search.php/-/keyword=スポーツベッティング/?rss
|
検索キーワード |
2023-03-21 00:00:00 |
金融 |
金融総合:経済レポート一覧 |
【お薦め書籍】1300万件のクチコミでわかった超優良企業 |
https://www.amazon.co.jp/exec/obidos/ASIN/4492534628/keizaireport-22/
|
転職 |
2023-03-21 00:00:00 |
ニュース |
BBC News - Home |
Ukraine says Russian missiles destroyed in Crimea |
https://www.bbc.co.uk/news/world-europe-65021987?at_medium=RSS&at_campaign=KARANGA
|
dzhankoi |
2023-03-20 22:55:07 |
ニュース |
BBC News - Home |
Aleksandar Mitrovic: FA says standard ban 'clearly insufficient' as Fulham striker charged |
https://www.bbc.co.uk/sport/football/65018262?at_medium=RSS&at_campaign=KARANGA
|
Aleksandar Mitrovic FA says standard ban x clearly insufficient x as Fulham striker chargedFulham s Aleksandar Mitrovic is charged with violent and improper conduct after his red card at Manchester United but the Football Association says the standard punishment is “clearly insufficient |
2023-03-20 22:03:46 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
ウクライナ穀物生産、23年度は15%減=ソルスキー農相 - WSJ発 |
https://diamond.jp/articles/-/319857
|
農相 |
2023-03-21 07:25:00 |
コメント
コメントを投稿