投稿時間:2022-02-19 19:13:42 RSSフィード2022-02-19 19:00 分まとめ(15件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
ROBOT ロボスタ ロボット犬『Mini Pupper』(ミニぷぱ) レビュー 使ってわかった3つの楽しみ方 顔の変更、カメラの接続にも挑戦 https://robotstart.info/2022/02/19/mini-pupper-review.html 2022-02-19 09:14:50
python Pythonタグが付けられた新着投稿 - Qiita QISkit 4ビットグローバアルゴリズム https://qiita.com/kiyamada/items/1bf737fb1aada54397e9 2022-02-19 18:23:01
js JavaScriptタグが付けられた新着投稿 - Qiita Discord.jsで特定のユーザーのみが利用できるコマンドを作る https://qiita.com/YutoGamesYT/items/ad700b88d1653093d751 好きなものに変更しましょうconsttokenxxxxxxxxxxxxxxxx自分のDiscordTokenを入力してください起動した際に行う処理clientonreadygtconsolelogclientusertagでログインしましたここに処理を書いていくclientlogintokenその中にこれを入力してください実行しますnodeindexjsこれでBotが起動したはずですできてなかったらTokenが違ったり、サーバーに未導入、またはコードが間違っている可能性があります特定のユーザーが使えるコマンドを作る今回は前回作ったGbanコマンドを改良しますindexjsメッセージを受け取ったときに行う処理clientonmessageasyncmessagegt送信者がBot、またはDM、コマンドの接頭辞から始まってなかった場合無視するifmessageauthorbotmessageguildmessagecontenttoLowerCasestartsWithclientconfigprefixreturnconstargsmessagecontentsliceclientconfigprefixlengthtrimsplitgコマンドが入力されてなかったら無視ifmessagecontentprefixgbanもしもコマンドがgbanだったらifmesssageauthorid実行できる人のIDreturnmessagereplyあなたに実行する権限がありませんconstgbanIdargsconstreasonargsifgbanIdreturnmessagereplyGbanIDを入力してくださいifreasonreturnmessagereply理由を入力してくださいclientguildscacheforEachggtBotが参加しているすべてのサーバーで実行trygmembersbangbanIdreasonメンバーをBANconsoleloggnameでのGBANに成功しました成功したらコンソールに出すcatcheconsoleloggnameでのGBANの執行に失敗しました。 2022-02-19 18:43:52
js JavaScriptタグが付けられた新着投稿 - Qiita JSのビット演算は遅いのか https://qiita.com/Tsukina_7mochi/items/7a39d490d8188bf30974 JSのビット演算は遅いのか要約JSで大量のboolean変数を扱う際に各要素が論理値型の配列を使う場合と配列を使う場合のどちらが速いかの実験AND演算とランダムアクセスの時間を計測速さTypedArraygtnumbergtboolean実験環境WindowsVersionHBuildUbuntufocalontheWindowsSubsystemforLinuxxLinuxmicrosoftstandardWSLIntelCoreiUxGHzRAMGBdenoreleasexunknownlinuxgnuvNodejsvChromeOfficialBuildビットcohortStableV実験方法各要素につの真偽値を入れたArray、各要素に個の真偽値を対応させたUintArray及びArrayに対して次の実験を回ずつ行い、計測した時間の平均値を調べた。 2022-02-19 18:04:31
海外TECH DEV Community The Best Practice of handling FastAPI Schema https://dev.to/gyudoza/the-best-practice-of-handling-fastapi-schema-2g3a The Best Practice of handling FastAPI Schema The Best Practice of handling FastAPI SchemaFastAPI Has a concept of Schema DTO is more familiar name If you have developed at Spring or NestJS Simply DTO is Data Transfer Object and It is a kind of promise to exchange object information between methods or classes in a specific model FastAPI s schema depends on pydantic model from pydantic import BaseModelclass Item BaseModel name str model str manufacturer str price float tax floatAs you can see schema is made by inheriting the pydantic Base Model Now let s use this to construct an api endpoint from fastapi import FastAPIfrom pydantic import BaseModelapp FastAPI class Item BaseModel name str model str manufacturer str price float tax float app get async def root item Item return message Hello World If you declare that you re gonna get an item schema at the basic endpoint In this way an example of receiving the model is automatically generated You can use this in other ways likefrom fastapi import FastAPI Dependsfrom pydantic import BaseModelapp FastAPI class Item BaseModel name str model str manufacturer str price float tax float app get async def root item Item Depends return message Hello World If you register the value Depends at schema You can see that the part that you want to receive as a Body has changed to Parameter Doesn t it feel like You ve seen it somewhere Right It is a common method for constructing search query However as can be seen above it can be seen that there is a limit of required values It s a search query but it doesn t make sense that all members have a required option So it is necessary to change all of this to optional very easilyfrom pydantic import BaseModelfrom typing import Optionalclass Item BaseModel name Optional str model Optional str manufacturer Optional str price Optional float tax Optional float It can be made in this way but if the default value of the schema members are optional there is a hassle of removing all the Optional when configuring the PUT method endpoint later Oh it is recommended that anyone who has no clear distinction between the PUT method and the PATCH method here refer to this article In short PUT is the promised method of changing the total value of an element and PATCH is the method of changing some So I use this way from pydantic main import ModelMetaclassclass AllOptional ModelMetaclass def new self name bases namespaces kwargs annotations namespaces get annotations for base in bases annotations update base annotations for field in annotations if not field startswith annotations field Optional annotations field namespaces annotations annotations return super new self name bases namespaces kwargs This class has the function of changing all member variables of the class to Optional when declared as metaclass from fastapi import FastAPI Dependsfrom pydantic import BaseModelfrom pydantic main import ModelMetaclassfrom typing import Optionalapp FastAPI class AllOptional ModelMetaclass def new self name bases namespaces kwargs annotations namespaces get annotations for base in bases annotations update base annotations for field in annotations if not field startswith annotations field Optional annotations field namespaces annotations annotations return super new self name bases namespaces kwargs class Item BaseModel name str model str manufacturer str price float tax floatclass OptionalItem Item metaclass AllOptional pass app get async def root item OptionalItem Depends return message Hello World If you inherit the class made of the pydantic Base Model and declare metaclass AllOptional there You can see Parameters without required option However when dealing with a schema in practice there are things that are not needed when putting it in and necessary when bringing it later It is common for id created datetime updated datetime etc And sometimes you have to remove some members and show them In spring or nest you can flexibly cope with this situation by using the setFieldToIgnore function or the Omit class but as anyone who has dealt with FastAPI can see there are no such things So after a lot of trial and error i established a way of using FastAPI schema like the DTO we used before It would be irrelevant to say that this is the best practice now Why I looked up numerous examples but there was no perfect alternative so I defined them myself and made them This is an example using the schema called Item used above from pydantic import BaseModelclass BaseItem BaseModel name str model str manufacturer str price float tax floatThe most basic members are defined as BaseItem It can be seen as defining the elements used in Upsert The pydantic model will basically be a schema used in the PUT method because it will be treated as Required if it is not set as Optional or None class Item BaseItem metaclass AllOptional id int created datetime datetime updated datetime datetimeIt is an item that inherits BaseItem Even if the class inherited the Base Model is inherited the inherited class also becomes a pydantic model so it can be declared this simply It is used to throw items that are not used in Upsert including basic elements This is a schema mainly used to inquire items so wouldn t it be okay not to attach Optional But if there is a non Optional member and its value has no Value an error is occurred class FindBase BaseModel count int page int order strclass FindItem FindBase BaseItem metaclass AllOptional passParameters used to find items can be declared in this way It inherits the BaseItem and FindBase declared above and treats them both as options with metaclass AllOptional to remove the required option of the parameter And lastly class Omit ModelMetaclass def new self name bases namespaces kwargs omit fields getattr namespaces get Config omit fields fields namespaces get fields annotations namespaces get annotations for base in bases fields update base fields annotations update base annotations merged keys fields keys amp annotations keys merged keys add field for field in fields new fields new annotations for field in merged keys if not field startswith and field not in omit fields new annotations field annotations get field fields field type new fields field fields field namespaces annotations new annotations namespaces fields new fields return super new self name bases namespaces kwargs This is a metaclass that supports the Omit function I needed it but I couldn t find it so I made it class BaseItem BaseModel name str model str manufacturer str price float tax floatclass OmittedTaxPrice BaseItem metaclass Omit class Config omit fields tax price If you declare omit fields in class Config in this way you can get a new schema with removed fields ※And one thing to note is that metaclass is executed every time a class is created so only one class involved in an inheritance relationship can be declared For exampleclass BaseItem BaseModel name str model str manufacturer str price float tax floatclass Item BaseItem metaclass AllOptional id int created datetime datetime updated datetime datetimeclass TestItem Item additional number intIf the Item declared metaclass AllOptional is inherited from TestItem AllOptional is executed twice Once when creating an Item class once again when creating a TestItem that inherits the Item Therefore the additional number a member variable of TestItem that inherits the Item is also Optional That is metaclass So if you declare another metaclass like Omit the program is broken class TestItem Item metaclass AllOptional pass TypeError metaclass conflict the metaclass of a derived class must be a non strict subclass of the metaclasses of all its bases So it is good to declare and use metaclass in the last inheritance class before it is used as schema This makes easy to recognize its function Anyway if you use the above mentioned four http methods GET POST PUT and PATCH which are often used it consists of this It can also be found in my git repo from datetime import datetimefrom fastapi import FastAPI Dependsfrom pydantic import BaseModelfrom pydantic main import ModelMetaclassfrom typing import Optional Listapp FastAPI class AllOptional ModelMetaclass def new self name bases namespaces kwargs annotations namespaces get annotations for base in bases annotations update base annotations for field in annotations if not field startswith annotations field Optional annotations field namespaces annotations annotations return super new self name bases namespaces kwargs class Omit ModelMetaclass def new self name bases namespaces kwargs omit fields getattr namespaces get Config omit fields fields namespaces get fields annotations namespaces get annotations for base in bases fields update base fields annotations update base annotations merged keys fields keys amp annotations keys merged keys add field for field in fields new fields new annotations for field in merged keys if not field startswith and field not in omit fields new annotations field annotations get field fields field type new fields field fields field namespaces annotations new annotations namespaces fields new fields return super new self name bases namespaces kwargs class BaseItem BaseModel name str model str manufacturer str price float tax floatclass UpsertItem BaseItem metaclass AllOptional passclass Item BaseItem metaclass AllOptional id int created datetime datetime updated datetime datetimeclass OmittedTaxPrice BaseItem metaclass Omit class Config omit fields tax price class FindBase BaseModel count int page int order strclass FindItem FindBase BaseItem metaclass AllOptional pass app get async def root return message Hello World app get items response model List Item async def find items find query FindItem Depends return hello world app post items response model Item async def create item schema UpsertItem return hello world app patch items id response model Item async def update item id int schema UpsertItem return hello world app put items id response model Item async def put item id int schema BaseItem return hello world app get items omitted response model OmittedTaxPrice async def omitted item schema OmittedTaxPrice return hello world When configured in this way the following swagger documents are generated find items endpoint with optional parameters create item Put methodIf you omit the item name according to the usage of PUT METHOD error is returned to send it with some name The PUT was formed by declaring that it would receive BaseItem as a body PATCH method OmittedIn this way we learned how to deal with FastAPIschema If you use something you may see more necessary functions but the endpoint and docs configuration that you need this much is progressing without difficulty in my case If you want to actively use FastAPI s schema to write docs please refer to it to reduce trial and error 2022-02-19 09:37:49
海外TECH DEV Community OpenBSD ftpd 7.0: FTP server https://dev.to/nabbisen/openbsd-ftpd-70-ftp-server-go8 OpenBSD ftpd FTP server SummaryOpenBSD has its own FTP server called ftpd ftpd the FTP daemon is installed and disabled by default All what to do in order to use it is just run rcctl enable and rcctl start Tutorial Before ConfigurationLet s see it s disabled by default doas rcctl check ftpdftpd failed Step Enable DaemonFirst enable it doas rcctl enable ftpd Note Here etc rc conf local will be updated like this cat etc rc conf localftpd flags Step Start DaemonThen start it doas rcctl start ftpdftpd ok The FTP server is now running You can establish ftp connection to the server as long as there is no network issues Note Accessing as root is forbidden ConclusionOpenBSD provides not only the daemon program but also several configuration files etc ftpchroot and etc ftpusers must be sometimes useful 2022-02-19 09:35:53
海外TECH DEV Community Top Ways To Center A DIV Using CSS https://dev.to/jagannathkrishna/top-ways-to-center-a-div-using-css-3a70 Top Ways To Center A DIV Using CSSWelcome Friends Its a bit difficult thing to position a DIV So here let s take a look to top ways to Center DIV Absolute class position absolute top left transform translate But There s more easy ways Flex Make the parent DIV a flexible column or row then align amp justify the children in the center class display flex align items center justify content center That s a great way But today we can do it with less code using Grid Layout Grid Justify the parent DIV as a grid and place the items center class display grid place items center Yes its that much simple Thank You For You Time Have A Good Day 2022-02-19 09:31:53
海外ニュース Japan Times latest articles China would likely back Russia, diplomatically, if it moved on Ukraine https://www.japantimes.co.jp/news/2022/02/19/world/china-russia-support-ukraine/ China would likely back Russia diplomatically if it moved on UkraineChina s foreign ministry has repeatedly blamed the U S for spreading false information and creating tensions urging it to respect and address Russia s demands for security 2022-02-19 18:17:02
海外ニュース Japan Times latest articles Japan student admits to leaking university entrance exam questions two years in a row https://www.japantimes.co.jp/news/2022/02/19/national/crime-legal/university-student-question-leak/ Japan student admits to leaking university entrance exam questions two years in a rowThe woman said that she contacted a man online before last year s unified exams and used a smartphone during the tests to capture images of 2022-02-19 18:03:04
ニュース BBC News - Home Storm Eunice leaves thousands of homes without power https://www.bbc.co.uk/news/uk-60442797?at_medium=RSS&at_campaign=KARANGA eunice 2022-02-19 09:50:09
ニュース BBC News - Home Winter Olympics: GB's Gus Kenworthy recovers from fall as New Zealand's Nico Porteous wins halfpipe gold https://www.bbc.co.uk/sport/av/winter-olympics/60442921?at_medium=RSS&at_campaign=KARANGA Winter Olympics GB x s Gus Kenworthy recovers from fall as New Zealand x s Nico Porteous wins halfpipe goldGreat Britain s Gus Kenworthy recovers from an awful fall to finish eighth in the freeski halfpipe as New Zealand s Nico Porteous wins gold at the Winter Olympics in Beijing 2022-02-19 09:44:12
ニュース BBC News - Home Is Russia going to invade Ukraine and what does Putin want? https://www.bbc.co.uk/news/world-europe-56720589?at_medium=RSS&at_campaign=KARANGA ukraine 2022-02-19 09:31:10
北海道 北海道新聞 高木菜は敗退、佐藤が決勝へ スピード女子マススタート1回戦 北京五輪 https://www.hokkaido-np.co.jp/article/647759/ 北京五輪 2022-02-19 18:19:44
北海道 北海道新聞 ロシアのウクライナ侵攻に最大警戒 米大統領 外交解決もなお模索 https://www.hokkaido-np.co.jp/article/647767/ 米大統領 2022-02-19 18:13:00
北海道 北海道新聞 「ご当地キャラ博」生配信 我がまち遺産、魅力をアピール https://www.hokkaido-np.co.jp/article/647766/ 新型コロナウイルス 2022-02-19 18:08: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件)