TECH |
Techable(テッカブル) |
スマホを熱から守る! この夏持っておきたい冷却アイテムの種類と選び方 |
https://techable.jp/archives/181924
|
tiktok |
2022-07-18 08:00:38 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
Python: fft と ifft の使い方復習 |
https://qiita.com/damyarou/items/3d13f3515d7de5845b7d
|
numpy |
2022-07-18 18:00:13 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
環境構築 Anaconda(Windows) |
https://qiita.com/ykpen_coffee/items/ea56b5f608a3f683be91
|
oswindowspython |
2022-07-18 17:25:49 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
配列を連想配列に変換する (JavaScript) |
https://qiita.com/kago/items/516cdb53e71d778bf55e
|
arrayprototypereduce |
2022-07-18 17:15:05 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
resourcesのネスト |
https://qiita.com/yoshihiro-hy/items/6c334c3f606c3fdab5b4
|
resourcesboardsdoresource |
2022-07-18 17:19:35 |
AWS |
AWSタグが付けられた新着投稿 - Qiita |
【AWS】運用支援ツール |
https://qiita.com/morinskyy/items/e4cf7dc30bf8fc4992ec
|
cloudwatch |
2022-07-18 17:12:30 |
Azure |
Azureタグが付けられた新着投稿 - Qiita |
プレビューのリージョン間ロードバランサー(Cross-region load balancer)を Azure CLI で作ってみた |
https://qiita.com/mnrst/items/46d442ef9f0c6133f83f
|
crossregionload |
2022-07-18 17:01:59 |
海外TECH |
DEV Community |
Kubernetes Source Code Overview: Kube-controller-manager |
https://dev.to/abhishe89636035/kubernetes-source-code-overview-kube-controller-manager-404l
|
Kubernetes Source Code Overview Kube controller managerKube controller managerKube controller manager is a binary that runs controllers which are control loops shipped with Kubernetes Examples of controllers are the Deployment Controller Service Controller Job Controller Namespace Controller ReplicaSet Controller Endpoints Controller and so on IntroductionThis article provides an overview of kube controller manager source code in kubernetes cmd kube controller manager directory which including parameter parsing and initialization of various types of controllers For the code in kubernetes pkg controller module a further overview will be provided later The code structure of the kube controller manager is as follows The following code snippets are based on the Kubernetes v version The source code is at Main FunctionThe main function of kube controller manager is very clean NewControllerManagerCommandNewControllerManagerCommand creates a cobra Command object with default parameters RunRun runs the kube controller manager The core functions are CreateControllerContext StartControllers and NewControllerInitializers CreateControllerContextCreateControllerContext creates a context struct containing references to resources needed by the controllers such as the cloud provider and clientBuilder NewControllerInitializersNewControllerInitializers is a public map of named controller groups paired to their InitFunc This allows for structured downstream composition and subdivision NewControllerInitializers StartControllersStartControllers starts a set of controllers with a specified ControllerContext StartControllers InitFuncInitFunc is used to launch a particular controller It returns a controller that can optionally implement other interfaces so that the controller manager can support the requested features The bool indicates whether the controller was enabled type InitFunc func ctx context Context controllerCtx ControllerContext controller controller Interface enabled bool err error Some Start Controller Functions startJobController startJobController creates a new JobController and runs the goroutine responsible for watching and syncing Jobs startJobController startDeploymentControllerstartDeploymentController creates a new DeploymentController and runs the goroutine responsible for watching and syncing Deployments startDeploymentController startReplicaSetControllerstartReplicaSetController configures a new ReplicaSetController and begins watching and syncing ReplicaSets startReplicaSetControllerWrap upThe following diagram shows an overview flow of kube controller manager overview flow |
2022-07-18 08:30:05 |
海外TECH |
DEV Community |
End-to-end Typesafe APIs with TypeScript and shared Zod schemas |
https://dev.to/jussinevavuori/end-to-end-typesafe-apis-with-typescript-and-shared-zod-schemas-4jmo
|
End to end Typesafe APIs with TypeScript and shared Zod schemasValidating your data is absolutely necessary The data could be data fetched from an API data posted to the API in the request body or any other IO operation This article will present a method of using TypeScript and Zod to create shared schemas between your frontend and backend Shared schemas will allow not only achieving the required level of data validation but also provide tooling such as automatically generated shared types that greatly increase productivity Let s create the simplest possible todo app going through each line of code relevant to data validation Follow the code on GitHub where I have posted a simple example of this app created with Next js Why use Zod You can use any other validation library such as the other popular three letter options yup or joi I strongly recommend choosing Zod as it in my opinion provides a great set of utilities supports practically every type you could wish to support has great TypeScript support and a short easy to remember API Especially for people used to TypeScript types Zod schemas really do their best at making them feel like regular TypeScript schemas For example all object properties are required unless explicitly marked as optional or nullable similar to how TypeScript types require explicitly declaring a property as optional with undefined or null With other data validation libraries you might always have to remember to type string required true which just doesn t feel as natural Defining a schema and its auto generated typesLet s create a simple Todo app to illustrate how Zod is used both in the backend and the frontend Let s first define a schema for a todo item We declare a Zod object schema with the z object method We can then define each property and its types each of which can then be refined further with chained methods of those types The important part of defining a schema to reach maximum typesafety is to share it between your frontend and backend This could be done with for example an internal npm package or a monorepo In some cases such as with Next js you just place the schema for example in a folder such as lib schemas and it s automatically reachable by both your frontend and backend code Doing this prevents any need for duplicating the schema and maintaining two identical schemas Again an easy source of bugs “I ll just quickly change this property to optional… might be a sentence you hear yourself saying and then forget to change the other copy of the schema import z from zod export const todoSchema z object id z string done z boolean text z string min min disallows empty strings important z boolean optional createdAt z string updatedAt z string For later purposes we also define a schema for an array of todosexport const todosSchema z array todoSchema Next we define a type for todos Regularly you might start creating a type that matches the schema with export type Todo done boolean however that is not only unnecessary but also unproductive as it requires you maintain two versions of the same schema Instead you can use Zod to autogenerate the schema by type inference which Zod happens to be very good at schemas todo schema tsexport type Todo z TypeOf lt typeof todoSchema gt Protip Instead of exporting these types you can optionally declare the following type in your types d ts file or any other d ts file that is included in your tsconfig json Doing this means you don t ever again need to import your types with import Todo from path to todo However declaring types this way means you have to import all dependencies inline Little ugly but useful in the long run in my opinion types d tstype Todo import zod TypeOf lt typeof import lib schemas todo schema todoSchema gt To reflect on the power of shared schemas combined with automatically inferred types without them you would have to keep one copy of the both the schema and the interface in your backend and your frontend which would result in a total of four different schemas defining the exact same thing each one requiring to be updated when any update is required Typesafe fetching with your new schema and types Let s start implementing the API to serve the todos and the frontend functions required to consume them We create a simple endpoint to serve all todos export default async function handler req Request res Response if req method GET const todos await getAllTodosFromDatabase res json todos The old way of fetching this data in a typesafe manner would involve typecasting Some typechecking with if data null or if typeof data object or multiple other longwinded ways of attempting to validate your data might be present and should automatically signal to the developer that a better solution is required BAD async function fetchTodos Promise lt Todo gt const response await fetch api todos const json await response json return json as Todo Doing this would be an easy source of bugs You assume your backend delivers objects of a certain shape Suddenly the array doesn t even exist all the objects within it are null or some of the objects might have a missing id property You don t know and you can t trust until you validate This is where the schema comes into play Validating your data without any typecasting and with a lot more confidence in your own code can be achieved with just a few lines of code Good async function fetchTodos Promise lt Todo gt const response await fetch api todos const json await response json const parsed todosSchema safeParse json if parsed success return parsed data Handle errors console error parsed error return Using the safeParse method we can easily validate that the data has the correct shape and return it as is no typecasting necessary Zod handles typing for you In case there is an error parsed success will be false and the parsed error property will contain the resulting error Handling errors is left as an exercise to the reader however returning an empty array as a default value and logging the error is a start There We now have a simple API to serve data of the correct type and a client function to fetch it with validation Simple as that Updating and creating a todo itemLet s next tackle the reverse direction the server validating data received from the client Again we can define new shared schemas This time the schemas define the shape of the object sent as the request body to the API They can then be used for both validating on the server and defining the correct shape on the frontend Let s create schemas for updating and creating todo items with automatically inferred types lib schemas todo schema tsexport const todoUpdateSchema z object id z string done z boolean export const todoCreateSchema z object text z string important z boolean export type TodoUpdate z TypeOf lt typeof todoUpdateSchema gt export type TodoCreate z TypeOf lt typeof todoCreateSchema gt Let s next define simple handlers in the endpoint for these methods pages api todos tsexport default async function handler req Request res Response if req method PATCH const body todoUpdateSchema parse req body updateTodoInDatabase body id body done return res status end if req method POST const body todoCreateSchema parse req body createTodoInDatabase body return res status end Here instead of using the safeParse method we use a more direct method the parse method parse returns the validated data in its correct shape and throws on invalid data Sometimes this is preferred as it results in fewer lines and easier to read code but leaves the error handling to be done in a catch block For example on a server where errors may be handled by a common error handler function this could be a good option or if you just prefer try schema parse json catch e instead of const parsed schema safeParse json if parsed success else Consuming these routes on the frontend is as easy as defining the following functions the types of which are conveniently available already and the exact same types which the backend uses async function createTodo body TodoCreate await fetch api todos body JSON stringify body headers Content type application json method POST async function updateTodo body TodoUpdate await fetch api todos body JSON stringify body headers Content type application json method PATCH Let s reviewWe re done now All that s left to do is hook up the updateTodo createTodo and fetchTodos functions to the frontend code and to expand upon this idea The steps Create a schema with Zod shared between frontend and backend code Get automatic types with Zod s z TypeOf lt typeof schema gt type inference also shared Validate data when fetching data or posting data to the server use parse or safeParse according to your liking And the results Automatically generated typesShared schemas and types between frontend and backend codeFull confidence in your data s validityComplete data validation with just a few lines of codeNo maintaining symmetric schemas and types in multiple placesThe code shown in this article is obviously the bare minimum code of the simplest possible example but expanding this to larger applications is not only easy but quite honestly a necessity No application larger than a todo app created for learning a new JS framework should ever communicate data that has not been validated Moreover attempting to validate data without shared Zod schemas is just extra work and can even serve as a potential source of bugs |
2022-07-18 08:07:57 |
海外TECH |
DEV Community |
Learn Advanced web designing course in Delhi with A2n academy and upscale your career in IT industry |
https://dev.to/a2nacademy123/learn-advanced-web-designing-course-in-delhi-with-a2n-academy-and-upscale-your-career-in-it-industry-o69
|
Learn Advanced web designing course in Delhi with An academy and upscale your career in IT industryWeb designing is currently one of the most well liked and quickly expanding IT training courses Learning web design will make it easier for you to understand concepts in HTML CSS and JAVASCRIPT A web developer may create their own website from scratch if they have mastered all of the concepts An Academy is the finest place to take a web designing course in Delhi We provide top notch web design instruction globally with the help of our highly skilled experts We believe it is important to understand the principles of web design before diving into challenging coding languages Our interesting dynamic courses are made to make learning for you quick and pleasurable The significance of a web design course has increased recently due to growing demands from customers and architects Learning through instruction enables students to advance up the website architecture ladder and sharpen their abilities Additionally they help you build a solid portfolio which may inspire you to pursue your vocation more seriously Planning a web designing course in Delhi is a good way to master both the fundamentals and the most cutting edge web planning techniques The doors of An Academy a training facility for experts in web design development and marketing have been opened |
2022-07-18 08:02:18 |
海外TECH |
DEV Community |
setTimeout() & setInterval() in javascript |
https://dev.to/aishanipach/settimeout-setinterval-in-javascript-83b
|
setTimeout amp setInterval in javascriptAs we discussed earlier setTimeout starts it s timer and goes to task queue and waits until the call stack is empty This is all a part of the event loop working setTimeout Example code function sayHi alert Hello setTimeout sayHi Here sayHi function is executed after a delay of ms setTimeout doesn t necessarily execute the callback function precisely after the time inserted As it waits for the call stack to be empty it might be the case that the timer has already expired while waiting which means it will execute after a while and not the time mentioned Hence function sayHi alert Hello setTimeout sayHi Even here it will wait till the whole program is executed and call stack is empty By remaining in task queue it makes sure to avoid thread blocking So It waits atleast the time mentioned to execute the callback It does not block the main thread setInterval It keeps on executing the callback function after given interval until stopped let timerId setInterval gt console log attention setTimeout gt clearInterval timerId console log stop Here the attention is printed after every seconds and it s cleared using clearInterval below after seconds that is when stop is printed Learn more about concurrency in javascript and how can setTimeout is used setTimeout by Akshay Saini |
2022-07-18 08:01:25 |
海外ニュース |
Japan Times latest articles |
Japanese and South Korean foreign ministers meet to discuss ways to mend ties |
https://www.japantimes.co.jp/news/2022/07/18/national/japanese-south-korean-foreign-ministers-meet-discuss-ways-mend-ties/
|
Japanese and South Korean foreign ministers meet to discuss ways to mend tiesForeign Minister Yoshimasa Hayashi s meeting with his counterpart Park Jin is the first formal sit down between the two since South Korean President Yoon Suk yeol s May |
2022-07-18 17:38:00 |
海外ニュース |
Japan Times latest articles |
Yuzuru Hanyu to make ‘major announcement’ at upcoming news conference |
https://www.japantimes.co.jp/sports/2022/07/18/figure-skating/hanyu-news-conference/
|
Yuzuru Hanyu to make major announcement at upcoming news conferenceThe year old will speak at p m Tuesday in Tokyo fueling speculation he could be about to retire from competitive figure skating following a string |
2022-07-18 17:13:10 |
海外ニュース |
Japan Times latest articles |
It’s up to Kishida to achieve Abe’s great unrealized dream |
https://www.japantimes.co.jp/opinion/2022/07/18/commentary/japan-commentary/shinzo-abe-constitutional-dream/
|
japan |
2022-07-18 17:00:57 |
ニュース |
BBC News - Home |
UK heatwave: Country may have hottest day on record with 41C forecast |
https://www.bbc.co.uk/news/uk-62201793?at_medium=RSS&at_campaign=KARANGA
|
england |
2022-07-18 08:38:50 |
ニュース |
BBC News - Home |
Ukraine war: Zelensky fires security chief and top prosecutor |
https://www.bbc.co.uk/news/world-europe-62202078?at_medium=RSS&at_campaign=KARANGA
|
agencies |
2022-07-18 08:28:48 |
ニュース |
BBC News - Home |
Watch: UK heatwave could hit record 42C degrees |
https://www.bbc.co.uk/news/uk-62205141?at_medium=RSS&at_campaign=KARANGA
|
degreesbbc |
2022-07-18 08:18:54 |
北海道 |
北海道新聞 |
日1―5西(18日) 日本ハム12残塁 逆転負けで2連敗 |
https://www.hokkaido-np.co.jp/article/707110/
|
日本ハム |
2022-07-18 17:16:21 |
北海道 |
北海道新聞 |
容疑者「手紙送った」と供述 奈良県警押収、安倍氏銃撃で |
https://www.hokkaido-np.co.jp/article/707119/
|
奈良県警 |
2022-07-18 17:36:00 |
北海道 |
北海道新聞 |
東京、1万2696人コロナ感染 前週比201・3%、1人死亡 |
https://www.hokkaido-np.co.jp/article/707114/
|
新型コロナウイルス |
2022-07-18 17:16:21 |
北海道 |
北海道新聞 |
レバンガ北海道、スペシャルオリンピックス日本・北海道が連携 |
https://www.hokkaido-np.co.jp/article/707117/
|
知的障害者 |
2022-07-18 17:29:00 |
北海道 |
北海道新聞 |
道南在住167人感染 新型コロナ |
https://www.hokkaido-np.co.jp/article/707116/
|
道南 |
2022-07-18 17:20:00 |
北海道 |
北海道新聞 |
全道将棋選手権、苫小牧地区の斉藤さん初優勝 |
https://www.hokkaido-np.co.jp/article/707115/
|
斉藤さん |
2022-07-18 17:19:00 |
コメント
コメントを投稿