投稿時間:2021-05-01 14:19:06 RSSフィード2021-05-01 14:00 分まとめ(23件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
TECH Techable(テッカブル) 離島や僻地への運搬に! 独Wingcopterの最新ドローンは1度に小包3個をお届け https://techable.jp/archives/153901 wingcopter 2021-05-01 04:00:31
python Pythonタグが付けられた新着投稿 - Qiita [python] 仮想通貨APIからローソク足チャートを作る簡単な方法 https://qiita.com/atu4403/items/42d64c9fa9302cfa6c8a 大まかな手順は以下の通りAPIからデータ取得データをpandasのDataFrameに変換、成形mplfinanceで描画ローソク足チャートを作るには描画部分で色々と複雑なのですが、mplfinanceというパッケージを使ったら簡単でした。 2021-05-01 13:41:44
python Pythonタグが付けられた新着投稿 - Qiita pythonのリアルタイム性能 https://qiita.com/kakinaguru_zo/items/755f4b77eedadc0be26d 実験実験結果狙った遅延と平均の誤差をマイクロ秒単位で表示実行優先度\狙った遅延普通に起動nicechrtfifonicechrtidle概ね実行優先度に応じてリアルタイム性能が高まっているが、リアルタイム性が必要な場合はchrtfifoで起動するのがよいです。 2021-05-01 13:36:37
python Pythonタグが付けられた新着投稿 - Qiita Python:Djangoで簡単なWebアプリの開発 https://qiita.com/Woodin093/items/aec5f79a4e4f94da46a0 テンプレートを格納するディレクトリは、アプリディレクトリの直下に「templatesアプリ名」のディレクトリを作成します。 2021-05-01 13:18:11
js JavaScriptタグが付けられた新着投稿 - Qiita JS~スプレッド構文~ https://qiita.com/akari_0618/items/ad869bcd06bde3dbc8f3 スプレッド構文は配列内での使用と関数内での使用があります。 2021-05-01 13:19:03
js JavaScriptタグが付けられた新着投稿 - Qiita 💡話は聞かせてもらった JavaScriptは滅亡する! https://qiita.com/u83unlimited/items/2ada1cf9c6a2adba5ab2 話は聞かせてもらったJavaScriptは滅亡するというわけで、「年あたりに互換の切られた後継言語に移り、年あたりにJavaScriptは廃止される」と妄想しているので、ロードマップや後継言語の仕様を適当に予言‍️していきます。 2021-05-01 13:10:48
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) javascriptの非同期の挙動について https://teratail.com/questions/336058?rss=all javascriptの非同期の挙動について以下のように書くとasyncgtconstaddawaitreduceasyncaccvgtawaitaccreturnaccvconsolelogadd実行結果が以下のようになってしまうのですがobjectPromise以下のように書き直すとasyncgtconstaddawaitreduceasyncaccvgtawaitaccreturnawaitaccvこの部分にawaitを追加consolelogadd実行結果が意図した通り以下のようになります。 2021-05-01 13:57:49
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) EclipseでStruts2が「説明 The requested resource is not available.」となる。サーバー:Tomcat 8。OS:Windows10。 https://teratail.com/questions/336057?rss=all EclipseでStrutsが「説明Therequestedresourceisnotavailable」となる。 2021-05-01 13:45:27
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) xamppでのCSSの表示の違い https://teratail.com/questions/336056?rss=all xamppでのCSSの表示の違いXamppのlocalhostを用いてWebアプリケーションを作っている最中です。 2021-05-01 13:36:25
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) Swiftでデフォルトカレンダーの変更を行う方法 https://teratail.com/questions/336055?rss=all ekeventstore 2021-05-01 13:29:03
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) APIで取得したdataがundifinedになってしまう https://teratail.com/questions/336054?rss=all APIで取得したdataがundifinedになってしまうAPIで取得したデータを使ってcomutedでページネーションのための処理を記述しようとしたところ、データがうまく使えない状態です。 2021-05-01 13:22:43
Program [全てのタグ]の新着質問一覧|teratail(テラテイル) 競技プログラミングABC199C問題にて起きるTLEとなる原因について https://teratail.com/questions/336053?rss=all 競技プログラミングABCC問題にて起きるTLEとなる原因について発生している問題・エラーメッセージAtcodernbspBeginernbspContestnbspnbspC問題nbspnbspにおいて以下のコードを書いて提出したのですが、TLEとなる理由についてわかりません。 2021-05-01 13:11:20
Ruby Rubyタグが付けられた新着投稿 - Qiita rails -sでサーバの起動ができない https://qiita.com/manikomild/items/d468033f42ea32f067fd ivenexpectedargumenterror 2021-05-01 13:22:02
AWS AWSタグが付けられた新着投稿 - Qiita EC2のルートボリューム交換を試す。 https://qiita.com/sakai00kou/items/ddaf9efaa1c02ee536b9 ECでルートボリュームを交換することにより、迅速な復元とトラブルシューティングが可能に通常は以下の様にインスタンスを停止してデタッチ・アタッチで交換しますが、ルートボリュームをインスタンス停止無しで復元できるってどうやっているんだっていうことでどういう動作をしているのか確認してみました。 2021-05-01 13:27:02
Docker dockerタグが付けられた新着投稿 - Qiita raydiumをdockerでローカル上に実行したい https://qiita.com/mizutamariya/items/c20c246eddbc2caaaf23 ここまできたらあとはcloneしたお好きなディレクトリにコマンドプロンプトでもpowershellでもいいので移動してdockercomposeupdbuildしばらくするとdoneとか出ると思うので、おもむろにdockerを見てみます。 2021-05-01 13:39:46
Git Gitタグが付けられた新着投稿 - Qiita Git ブランチの見つけ方 形跡たどる https://qiita.com/gohandesu2439/items/a4f0b3049d7a1e4cfd7a Gitブランチの見つけ方形跡たどるこのコードが入ったor削除された原因、タスクを調査して欲しい意図しないバグや不具合が起きている場合に、ディレクターさんにこんなお願いされることがたまにあります。 2021-05-01 13:42:28
Ruby Railsタグが付けられた新着投稿 - Qiita rails -sでサーバの起動ができない https://qiita.com/manikomild/items/d468033f42ea32f067fd ivenexpectedargumenterror 2021-05-01 13:22:02
Ruby Railsタグが付けられた新着投稿 - Qiita Rails LINEbot 入門 https://qiita.com/lolohacker/items/b95967b98a4f25830fd1 Webhook設定LINEサーバから自分が開発したWEBアプリにリクエストを送信するための設定をします。 2021-05-01 13:14:50
海外TECH DEV Community Habits you should change if you wants to develop your skill as a developer https://dev.to/devto4/habits-you-should-change-if-you-wants-to-develop-your-skill-as-a-developer-2bgm Habits you should change if you wants to develop your skill as a developer Never Give upThe problem you re trying to solve doesn t seem to have a solution You can t think of one therefore you re a bad developer Wrong I ll let you in on a little secret all problems can be solved by code it s just a matter of having the right amount of time and resources I m sure this is not breaking news to most of you but if you re just getting started and finding it hard to solve your problems ーhang in there They can be solved you probably just need more time and research We all struggle we all forget the most basic things Don t let anyone say you re not a good dev because you forget how a FOR loop is written Don t work beyond the hours Look coding can be fun and working is important so I get it but there is more to life than just coding It might not seem like it right now but if you spend too much time working or even coding for the fun of it you ll miss out on life Friends family relationships even hobbies other than coding duh are all very important facets of life and coding should not be above any of them And if you re thinking “well if I don t spend hours coding every day someone else who does it will get the job I want think again That person will end up burning out They will not be as productive or as happy about coding in the long run and you ll still be there with the same motivation and eagerness to work Life is all about balance If you put too much emphasis on one activity the rest will suffer And while you might be having a good time now it ll have its effect in the long run Asking for help is not a sign of weaknessAsking for help is not weak it s the smart thing to do You re building something for a reason whether it is because you want to build a product or because you re trying to learn something By asking for help you re arriving at your destination sooner Where can you ask for help Twitter is a great place The community around “tech twitter is very helpful Make sure you hashtag the technology you re asking about to make sure those following it can see your question Get Some More 2021-05-01 04:19:51
海外TECH DEV Community The Zen of Preact's source code https://dev.to/puruvj/the-zen-of-preact-s-source-code-59g2 The Zen of Preact x s source codeArtwork by Fernando JorgeRead in light dark or sepia themePreact is web dev household name at this point Almost every web developer who s been in this business for longer than years has heard of it and maybe even tried it themselves And probably reached the same conclusion as me It s awesome So today I m gonna do a deep dive into Preact s source code and remark on some interesting things I find there What is Preact In case you re not familiar Preact is the KB alternative to the KB of React by Jason Miller It s fully compatible with React s API and supports all packages that rely on React Its awesome that way ObservationsBefore we look at the code I ll remark on some things about Preact Written in TypeScript but not quite Preact s source code is written in TypeScript but the main files themselves aren t The main files with the functionality are written in plain JavaScript but they use JSDoc to pull in Types from TypeScript Definition files d ts An example This is the types d ts file export type RenamedType number null And here s the JS file param import types RenamedType a param import types RenamedType b returns function sum a b return a b As you can see the JavaScript code is just that JavaScript You won t see TypeScript style type specified in it Rather all type information is specified in comments which are ignored completely There s a whole article about Using TypeScript without TypeScript but the TLDR here would be Avoid development time tooling If its just plain JS you don t need to run a file watcher to transpile files as you change them Just run what you got And you already got a TypeScript compiler running all the time without you explicitly running it Your VSCode This is a very interesting approach and I see more and more libraries take it up especially non UI libraries For UI libraries you already got a web server running so adding in TypeScript in the tooling won t change much go ahead and add TypeScript Very well written codeI don t need to say this out loud really but Preact s source code is very very well written and commented as you d expect from such a paramount framework It reuses itself a lotYup One of the reasons Preact is so small is that it reuses it s own exported function in its other exported functions A LOTT I ll show you some places where this happens DisclaimerThis is not gonna be a complete breakdown and won t be sequential Preact is quite a big library to cover in a blog post so I ll just cover the interesting parts So let s begin We ll look at some interesting things in the core module i e the one when you type import from preact then we ll get to hooks Core module index jsAs is the tradition let s start with the index js file export render hydrate from render export createElement createElement as h Fragment createRef isValidElement from create element export Component from component export cloneElement from clone element export createContext from create context export toChildArray from diff children export default as options from options Notable points h which is Preact s JSX factory is actually named createElement Just like React createElement But is exported as h because it allows you to write raw Preact Without JSX also because it was initially inspired from HyperScript h div class haha h span key h h h span Whoa Also it is notable that it exports createElement as it is too to maintain compatibility with React createElement create element jsimport options from options export function createElement type props children export function createVNode type props key ref original export function createRef return current null export function Fragment props return props children export const isValidElement vnode gt vnode null amp amp vnode constructor undefined Omitted createElement and createVNode as they re quite big createRefLet me blow your mind refs in P React are basically used to encapsulate values that shouldn t trigger re renders and are not re created on every re render Lets see how Preact defines it export function createRef return current null A ref is just an object with current property set to null It s always advertised as that but I never thought that it s actually an object internally too A little clip of me when I found this out FragmentNext up we have Fragment Its also another astonishing thing export function Fragment props return props children Fragment just returns its children That s all I knew that s what it s supposed to do but I always pictured some complex code Didn t realise that it was just this super simple thing isValidElement Check if a the argument is a valid Preact VNode param vnode returns vnode is import internal VNode export const isValidElement vnode gt vnode null amp amp vnode constructor undefined Simply checking if the current Virtual DOM Node passed to it is valid or not Again one liner super small but here s a pattern I found out by looking at this code only Notice returns vnode is import internal VNode in JSDoc The code is basically using type guards Right in the JSDoc I haven t seen this pattern before which is all the more proof that reading code written by those smarter than you can make you a better dev render jsRemember the index jsx file where you initialize your Preact appimport render h from preact import App from App render lt App gt document querySelector app This is the render function export function render vnode parentDom replaceNode if options root options root vnode parentDom We abuse the replaceNode parameter in hydrate to signal if we are in hydration mode or not by passing the hydrate function instead of a DOM element let isHydrating typeof replaceNode function To be able to support calling render multiple times on the same DOM node we need to obtain a reference to the previous tree We do this by assigning a new children property to DOM nodes which points to the last rendered tree By default this property is not present which means that we are mounting a new tree for the first time let oldVNode isHydrating null replaceNode amp amp replaceNode children parentDom children vnode isHydrating amp amp replaceNode parentDom children createElement Fragment null vnode List of effects that need to be called after diffing let commitQueue diff parentDom Determine the new vnode tree and store it on the DOM element on our custom children property vnode oldVNode EMPTY OBJ EMPTY OBJ parentDom ownerSVGElement undefined isHydrating amp amp replaceNode replaceNode oldVNode null parentDom firstChild EMPTY ARR slice call parentDom childNodes null commitQueue isHydrating amp amp replaceNode replaceNode oldVNode oldVNode dom parentDom firstChild isHydrating Flush all queued effects commitRoot commitQueue vnode export function hydrate vnode parentDom render vnode parentDom hydrate First off very well commented From how well I can make sense of the situation here render function is basically making a commitQueue to store all the changes needed to be done next the diff function is taking in the old VNode and the new VNode making sense of situation and figuring out which DOM Nodes need to be updated and populating commitQueue Then its basically committing these changes Its just like how we do it in Database We perform some operation in batch the commit so they all get applied one by one at the same time I would love to cover diff in the blog post too but its so big it has its own lines long file All you have to know its job is to figure out which DOM Nodes need to be updated and which to keep the same hydrateThis function is very interesting as it nothing but calling the render function But something even more interesting its passing along itself as the rd argument And if you look again at render function it actually has an if condition looking if the function passed to it is named hydrate Heck there s even a comment about abusing the rd argument These people are way too smart I m probably exhausting my repeat limit but darn Preact s reuse of itself is really darn good create context jsThis one will probably excite you as Context is a very very loved API by a majority of P React developers This wasn t always the case but the useContext hooks made it very easy to use context Way too easy const lemonsCount setLemonsCount useContext lemonsContext import enqueueRender from component export let i export function createContext defaultValue contextId contextId cC i const context id contextId defaultValue defaultValue type import internal FunctionComponent Consumer props contextValue return props children contextValue type import internal FunctionComponent Provider props if this getChildContext let subs let ctx ctx contextId this this getChildContext gt ctx this shouldComponentUpdate function props if this props value props value subs some enqueueRender this sub c gt subs push c let old c componentWillUnmount c componentWillUnmount gt subs splice subs indexOf c if old old call c return props children Devtools needs access to the context object when it encounters a Provider This is necessary to support setting displayName on the context object instead of on the component itself See contextdisplayname return context Provider contextRef context Consumer contextType context This file this small file is all there s to the core context API These lines do so much Comments excluded So let s inspect Consumer Go back a long time back and remember we used to use Consumer to access context data This is how it looks lt Consumer gt data gt lt div gt Hello data lt div gt lt Consumer gt This looks pretty manageable but it could get worse when your code grew So if we look at the code of Consumer it s just this Consumer props contextValue return props children contextValue That s it Its expecting its children to be a function and it s simply calling it with the context data Suddenly the Consumer pattern example above makes sense As for Provider what it s doing mostly is modifying its parent component s lifecycle hooks to watch for context state changes Lastly there s the return statement at the bottom The last line is big mutation trick that is used often while coding classical languages like C C Java etc that is returning a variable and mutating it at the same time Here it is mutating it for the sake of Preact devtools so as to show the displayName in devtools as React Devtools do And now its time for the section you probably came here for entirely HOOKS HooksSo first off Hooks are located in a separate directory Unlike React everything is opt in in Preact which makes the Minimalist in me rejoice There s intentionality in every thing you do here I that So let s start off with the very very first hook you ever encountered useStateBut Beware a twist lies here useStateThis is useState export function useState initialState currentHook return useReducer invokeOrReturn initialState Mindblown right As you can see useState is basically calling useReducer which is another standard React hook So basically useState is just an alias of useReducer you could say The variables invokeOrReturn and currentHook are defined in the same file in the module scope and managed by Preact And lemme give you another nugget See the currentHook expression Guess what It s not needed in the core functionality It exists solely for Preact Devtools That is if Devtools weren t a consideration this code might as well have been const useState initialState gt useReducer invokeOrReturn initialState Literally a one liner Again intense focus on the whole self reusing thing I keep repeating All the heavy lifting here is done by the useReducer so let s look at it next useReducerexport function useReducer reducer initialState init type import internal ReducerHookState const hookState getHookState currentIndex hookState reducer reducer if hookState component hookState value init invokeOrReturn undefined initialState init initialState action gt const nextValue hookState reducer hookState value action if hookState value nextValue hookState value nextValue hookState value hookState component setState hookState component currentComponent return hookState value I ll admit I don t fully understand what s going on here but something that caught my eye here Look at the hookState value declaration inside the if block Its an array with elements st element is simply a value nd one is a function Wait a sec st element a value nd element a function Holy smokes Its the state setState pair returned from useState const state setState useState Infinity if that didn t blow your brains apart I dunno what will Next up The nd most famous hook useEffectexport function useEffect callback args type import internal EffectHookState const state getHookState currentIndex if options skipEffects amp amp argsChanged state args args state value callback state args args currentComponent hooks pendingEffects push state Aha Notice the if block here We re checking for things options skipEffects Preact has an options config where you can turn off all side effects from running So to run this useEffect we have to make sure its safe to run effects argsChanged state args args This one is very interesting Remember the nd argument you pass to useEffect useEffect gt Do epic shit emojiUpdated Guess what argsChanged is the function responsible for checking if changes were made in the dependencies passed to useEffect Here we pass it state args the argument list maintained by Preact for this specific hook and the nd argument is the new set of dependencies If any changes are detected this function returns true and the effect is run again As for argsChanged function its simply this function argsChanged oldArgs newArgs return oldArgs oldArgs length newArgs length newArgs some arg index gt arg oldArgs index Its basically checking if oldArgs even exist or not at first Why Cuz the dependency list passed to useEffect itself could be a state holding an array const deps setDeps useState useEffect gt Do epic shit deps OFC a simple reason could be that you didn t pass the array That is what most people would do rather than this above method nd its checking if argument list length is different or not This is a smart move because if the array size itself is changed you don t need to go through and check every value The cheapest function call is the one you never make Jason MillerAnd finally when all these conditions are true we finally check if the values match up using the arr some method From what I can tell this function is written in a way to stop as soon as it can You could ve written this same function in a way that it would do all these things and then tell the result Here through some clever short circuiting they made this function pretty efficient useLayoutEffectexport function useLayoutEffect callback args type import internal EffectHookState const state getHookState currentIndex if options skipEffects amp amp argsChanged state args args state value callback state args args currentComponent renderCallbacks push state This hook is very very interesting If you read the code of useEffect you ll find that they are exactly the same except for the very last line In useEffect it is currentComponent hooks pendingEffects push state Whereas here it is currentComponent renderCallbacks push state In useEffect the effects to executed are pushed to a queue that executes asynchronously Whereas in useLayoutEffect the effects are pushed to the render callbacks making it execute eagerly as the rendering is going on That s why its called use Layout Effect Next up is another hook that will blow your mind and change the way you write your Refs Yepp you guessed it right its useRef useRef This hook s implementation is so cool that I can t help but put the Sunglasses emoji in front of it export function useRef initialValue currentHook return useMemo gt current initialValue If you notice useRef is just useMemo in disguise with an object that has one property current with value null So effectively you could write your refs as memosconst containerElementRef useMemo gt current null Don t take this too seriously though Its better if element refs are assigned to proper useRef values only as it is cleaner the syntax is built around it What I wanna point at is is that a lot of people especially beginners equate Ref as the thing that holds DOM references and that s all it do Which is not a good thing really But when you look at this code and realise that the Ref is just a value that s cached for the lifecycle of the component clarity sinks in The mental block and the sense of magic goes away and you feel fully in control useCallbackexport function useCallback callback args currentHook return useMemo gt callback args And here s another hook that s just useMemo under the hood This gives me the lols At this point I m simply giggling silently seeing that everything in Preact hooks is just useMemo useMemoAhh the star of the show useMemo Finally export function useMemo factory args type import internal MemoHookState const state getHookState currentIndex if argsChanged state args args state value factory state args args state factory factory return state value This one is pretty simple Get the state for this specific hook compare the previous dependencies to the new and update values and factory function passed to it if anything changes And this again is so small it makes me laugh as well as cry Seriously going through this codebase gives me huge imposter syndrome everytime The architecture is so damn well done that code duplication isn t needed anywhere here so everything is super small Well done Preacters 🥲 useContextOne of the most favorite hooks of all time useContext export function useContext context const provider currentComponent context context id We could skip this call here but than we d not call options hook We need to do that in order to make the devtools aware of this hook type import internal ContextHookState const state getHookState currentIndex The devtools needs access to the context object to be able to pull of the default value when no provider is present in the tree state context context if provider return context defaultValue This is probably not safe to convert to if state value null state value true provider sub currentComponent return provider props value Lots of comments here If I remove all of themexport function useContext context const provider currentComponent context context id const state getHookState currentIndex state context context if provider return context defaultValue if state value null state value true provider sub currentComponent return provider props value Are you kidding me Just lines in the body and you have the biggest simplification that came when React hooks launched What sorcery is this Notable points here If no provider is detected it returns a default value thanks to that liner if statement And if no value is found here preact subscribes the current component to the context useErrorBoundaryexport function useErrorBoundary cb type import internal ErrorBoundaryHookState const state getHookState currentIndex const errState useState state value cb if currentComponent componentDidCatch currentComponent componentDidCatch err gt if state value state value err errState err return errState gt errState undefined I m a huge huge fan of Preact for providing a useErrorBoundary hook In React if you want error boundaries you have to create a class component yourself and set at the root of your component tree Whereas it ships by default in Preact which makes my heart flutter Notable points here This hook mostly sets the componentDidCatch lifecycle to catch the errors and do what you tell this hook to do Its more or less same as you yourself making a class component only you don t have to nest anything here just drop this hook in any component thats on top of the component tree That s it for hooks I didn t cover useDebugValue and useImperativeHandle as I have never had to use useDebugValue and useImperativeHandle is deemed unsafe to use ¯ ツ ¯ A note on simplicityNotice how I ve been saying the code is super simple Well it is super easy to read because that s how simple it is but writing it is hard Simplicity is rarely easy its always harder to achieve Writing a good emotional rollercoaster in words is hard Throwing out excessive clothes is hard Having a clean desk is harder than a cluttered desk And making KB code for what was originally KB is hard Subtraction is harder than addition division is harder than multiplication Making Preact by no means would ve been an easy task but Jason did it amazingly and all the contributors that jumped in later made it even greater while still keeping everything small and simpler This is a monumental task Hats off to the Preact team for this effortThis is it for today Signing off 2021-05-01 04:02:04
ニュース BBC News - Home The Papers: 'Holidays from 17 May' and 'care home freedom' https://www.bbc.co.uk/news/blogs-the-papers-56952475 england 2021-05-01 04:43:51
ビジネス ダイヤモンド・オンライン - 新着記事 [2021年5月]QUOカード株主優待利回りランキング! 配当+株主優待利回りが3%台後半のタマホームなど 5月の「QUOカード優待」全銘柄の利回り&内容を紹介 - 株主優待「1月~12月のおすすめ銘柄」 https://diamond.jp/articles/-/270139 2021-05-01 13:05:00
LifeHuck ライフハッカー[日本版] 自転車やベビーカーに取付可能なスマホホルダー「LOOP MOUNT」 https://www.lifehacker.jp/2021/05/233704-machi-ya-loopmount-start.html loopmount 2021-05-01 14:00: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件)