js |
JavaScriptタグが付けられた新着投稿 - Qiita |
Chrome拡張作ったら異世界転生した件 |
https://qiita.com/zakuroishikuro/items/5275f783a2d8b37db212
|
|
2021-06-21 04:11:03 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
GASとwebhookを用いてスプレッドシートのグラフの画像をdiscordに送信したとき、画像のみ表示されない問題 |
https://teratail.com/questions/345156?rss=all
|
GASとwebhookを用いてスプレッドシートのグラフの画像をdiscordに送信したとき、画像のみ表示されない問題前提・実現したいことスプレッドシートでグラフを作成し、GASにてグラフの画像化、一時的にGoogleドライブ上に画像ファイルを保存してurlを取得、それをembedの形でdiscordのwebhookを用いてメッセージとして送信したいです。 |
2021-06-21 04:36:30 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Atcoder Beginner Contest 128-C で SIGSEGV が出る |
https://teratail.com/questions/345155?rss=all
|
AtcoderBeginnerContestCでSIGSEGVが出るABCCを解いていたところエラーが出たのでどこが原因になっているのか教えていただきたいです。 |
2021-06-21 04:33:03 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
yolov3で学習済みモデルtrained_weights_final.h5が生成されない |
https://teratail.com/questions/345154?rss=all
|
yolovで学習済みモデルtrainedweightsfinalhが生成されない前提・実現したいこと初めての機械学習で上記のサイトを参考に機械学習を行っているのですが、trainedweightsfinalhが生成されず、次のステップに進んことが出来ません。 |
2021-06-21 04:18:43 |
海外TECH |
DEV Community |
A Successful IOC Pattern with Functions in TypeScript |
https://dev.to/mindplay/a-successful-ioc-pattern-with-functions-in-typescript-2nac
|
A Successful IOC Pattern with Functions in TypeScriptOver the past few months I ve been working on a TypeScript project where I decided to challenge myself to use Functions only This week I refactored the codebase to use IOC everywhere and it feels like I leveled up There s been a lot of articles these past couple of years about functional programming in JavaScript and for some reason these are mostly concerned with immutability sets map reduce and so on I come from a background of mostly OOP where the answer to IOC is largely just use constructors and interfaces so this hasn t been really helpful What was missing for me was a functional perspective on IOC and dependency injection In this article I will try to illustrate the problems and solutions with a silly example for illustration purposes for some reason your boss wants the browser to display a personalized welcome message using an old fashioned alert Yikes Well whatever you say boss but I expect this requirement will change in the future To make the most of this article you should know some basic TypeScript and you should be familiar with the terms inversion of control or dependency injection at least in the sense of using constructors and interfaces While DEV thinks this is an minute read I recommend you open the Playground and spend minutes getting a feel for this Okay let s say you come up with function like this function showMessage window Window message string window alert message As you can see I am already doing dependency injection Rather than reaching out for the window global this function asks for an instance of Window which makes it easy to unit test this function on a mock Window instance So far so good So we re done right Not quite Pretty soon you will introduce functions that depend on showMessage and in order for another function to call showMessage the other function needs to supply the window parameter which means the dependency on Windows spreads to other functions function showWelcomeMessage window Window user string showMessage window Welcome user But wait now showWelcomeMessage internally depends on showMessage we really should use dependency injection for that too right type showMessage typeof showMessage function showWelcomeMessage showMessage showMessage window Window user string showMessage window Welcome user This looks wrong showWelcomeMessage had to depend on Window only so it could pass it along to showMessage but it doesn t actually do anything with the Window object itself And while showMessage happens to use Window today we might change that in the future when someone realizes what a sad idea it was to use that alert Maybe we decide to have it display a toast message on the page instead and so the dependency changes from Window to Document That s a breaking change Now we have to run around and refactor everything that calls showMessage Calling any function gets increasingly cumbersome anytime any of the dependencies of any function changes we have to manually correct the calls and introduce more dependencies everywhere We re in dependency hell and by now we re wasting most of our time refactoring There has to be a better way My first realization was why should someone who wants to call showMessage need to know anything about it s internal dependencies What I really want is a function that is internally bound to an instance of Window so that the caller doesn t need to know or care That means we need a factory function for the actual function function createShowMessage window Window return function showMessage message string window alert message We ll need to extract the inner function type the one that has the message argument only so that other units can depend on that type showMessage ReturnType lt typeof createShowMessage gt Note the user of ReturnType here you could have manually typed out the function signature of the inner function but this helps avoid the duplication and the extra refactoring chore going forward With that in place our showWelcomeMessage no longer needs to care that showMessage internally uses window function showWelcomeMessage showMessage showMessage user string showMessage Welcome user This also makes showWelcomeMessage easier to test since now we don t need to mock window anymore we can mock showMessage instead and test that it s being called The code and the tests will now refactor much better as they have fewer reasons to change So we re done right Yeah but No Consider now what happens to the next function up the call hierarchy Let s say we have a login function and showing the welcome message happens to be part of what it does and we apply dependency injection here too type showWelcomeMessage typeof showWelcomeMessage function login showWelcomeMessage showWelcomeMessage user string showWelcomeMessage user This problem doesn t go away by just fixing it at one level we need to apply the same pattern we applied to showMessage wrapping it in a createShowMessage factory function And what happens when something else needs to call login Same thing again In fact as you may have realized by now we might as well apply this pattern consistently as a convention to every function we write Really To every function Yes really and bear with me because it doesn t look pretty function createShowMessage window Window return function showMessage message string window alert message type showMessage ReturnType lt typeof createShowMessage gt function createShowWelcomeMessage showMessage showMessage return function showWelcomeMessage user string showMessage Welcome user type showWelcomeMessage ReturnType lt typeof createShowWelcomeMessage gt function createLogin showWelcomeMessage showWelcomeMessage return function login user string showWelcomeMessage user type createLogin ReturnType lt typeof createLogin gt It does what we wanted though We can do all of our dependency injection from the top down now we can now bootstrap everything from a single function in our entry point script function bootstrap window Window const showMessage createShowMessage window const showWelcomeMessage createShowWelcomeMessage showMessage const login createLogin showWelcomeMessage return login usage const login bootstrap window login Rasmus Note that in this example bootstrap returns only login if you have multiple entry points you can return more functions Now as helpful as this pattern was this approach to bootstrapping does not really scale well There are two problems We re creating everything up front In this simple example we do need every component but applications with multiple entry points might only need some of the components some of the time The code is very sensitive to reordering you have to carefully arrange your factory function calls so that the previous function can be passed to the next It requires a lot of thinking about dependencies We can solve both of these problems by deferring the creation of dependencies until they re required that is by making the calls to the factory functions from within another function Let s call this a getter function Now since these getter functions could potentially be called more than once although in this simple example they re not we want them to return the same dependency every time rather than generating new ones We can solve this by adding a tiny helper function once to construct these wrapper functions and memoize the result function once lt T gt f gt T gt T let instance T return gt if instance undefined instance f first call return instance Let s refactor again we ll wrap all of our initializations in closures and apply once to them and our bootstrap function will now return the getLogin function Note that the once function would generate singletons if you were to call it from the global scope but since we re calling it from the bootstrap function scope new instances of all dependencies will be generated for every call to bootstrap The new bootstrap function looks like this function bootstrap window Window const getLogin once gt createLogin getShowWelcomeMessage const getShowWelcomeMessage once gt createShowWelcomeMessage getShowMessage const getShowMessage once gt createShowMessage window return getLogin usage const app bootstrap window const login app getLogin login Rasmus I ve purposely mixed up the order of these getter functions to illustrate the fact that the order no longer matters we re now free to arrange and group these lines in any order that makes sense and we re also no longer creating anything before one of the getter functions is actually called which removes any concerns about potential future performance problems So we re Yes done Footnote When not to apply this patternYou don t need to apply this pattern to every function Some functions don t have dependencies or maybe they depend only on standard JavaScript environment functions For example there s no benefit to injecting the Math max function since that s a pure function with no side effects Whereas on the other hand there s a clear benefit to injecting Math random since a mock can return values that aren t actually random making it possible to write predictable tests for your function Bonus Mutable StateI made one more little discovery this week that I d like to share I think we ve all been here one time or another let loggedInUser string undefined function setLoggedInUser user string loggedInUser user function getLoggedInUser string return loggedInUser It s dangerously easy and natural to do this in JavaScript But even if you put this inside a module this is global state and it makes things difficult to test since setLoggedInUser leaves behind in memory state that persists between tests And you could write more code to clear out this state between tests but ugh If you must have mutable state we need to model that mutable loggedInUser state as a dependency and then apply the create function pattern described above interface LoginState loggedInUser string undefined function createSetLoggedInUser state LoginState return function setLoggedInUser user string state loggedInUser user function createGetLoggedInUser state LoginState return function getLoggedInUser user string return state loggedInUser I could have abbreviated this more but I actually like seeing the word state here clarifying the fact that a shared state is being either read or written It might be tempting to just take the previous version of this code wrap it all in a single create function and return both of the functions bound to the same state but I wouldn t recommend that because you could end up with many functions that depend on this state and you don t want to be forced to declare them all in the same create function Also if you have to write a function that depends on several different state objects that approach does not work One more piece of advice don t just create one big state object for all of your mutable state this will muddy your dependencies as functions will appear to depend on the entire application state even when those functions only actually depend on one property If you have multiple properties in the same state object the cohesion should be high ideally meaning every function depends on all of the properties of that object The setLoggedInUser function does have a side effect but now the effect is on state that you instantiate and control making it easy to inject a new state for every test I m not a functional programming Guru yet and maybe there is more to learn here but it s definitely a step up from global state ConclusionI feel like I ve finally found a JS TS code style that really scales both in terms of complexity and performance Applying this to my codebase has been an absolute breeze I m spending considerably less time juggling dependencies or refactoring things Unit testing is never a problem anymore For years I ve heard proponents of functional programming talk about the benefits but the articles are mostly about arrays and immutability which is great and I ve heard all the other great arguments But it didn t really help me write software and the outcome of prior attempts too often was either unmanageable or untestable But usually both Unlocking this feels like the next level for me and I really hope this puts somebody else on the path to more productive and scalable codebases with TypeScript or JavaScript Thanks for reading Have fun |
2021-06-20 19:12:41 |
海外TECH |
DEV Community |
Wordpress - Move cron jobs to CLI |
https://dev.to/plotek/wordpress-move-cron-jobs-to-cli-kgg
|
Wordpress Move cron jobs to CLISome time ago we started to observe performance issues in our company s site built with WordPress One of the issues we have observed was calling crons in random user requests It is realized by calling URL Although in this file WordPress calls PHP method fastcgi finish request which sends a response to the user as soon as possible the cost of calling sub requests during the main request is worth acknowledging and improving There are other drawbacks of this Calling crons in request context means that it is limited e g by php fpm setting We often have limited resources such as memory or time limit for HTTP requests What s worse calling cron as http request utilizes resource e g php fpm pools that might be necessary to handle our traffic On the Internet there are a lot of tips on how to disable making subrequest to call crons and move them to CLI But there is one problem A lot of these tips suggest calling these scheduled tasks using crontab by calling curl or other http callings This addressed first problem and makes user request free of sub requests but does not resolve two abovementioned problems It is surprising because WordPress comes with wp cron command which supports running scheduled tasks in CLI without making HTTP calls In order to do this you have to add one line to your crontab wp cron event run due now path path to your wpIn this case we call the scheduled task every minutes WordPress is responsible for choosing a concrete task to run and runs it Of course you also have to disable calling sub request to wp cron php file In order to do that add the following to your wp config php file define DISABLE WP CRON true In my opinion you should also deny access to wp cron php file because some bots might DDoS our site requesting this endpoint I suggest making it on the application server level For example if you use Nginx add the following to your host configuration location wp wp cron php deny all |
2021-06-20 19:04:22 |
Apple |
AppleInsider - Frontpage News |
FCC updates emergency alerts to avoid 2018 false alert fiasco |
https://appleinsider.com/articles/21/06/20/fcc-updates-emergency-alerts-to-avoid-2018-false-alert-fiasco?utm_medium=rss
|
FCC updates emergency alerts to avoid false alert fiascoThe Federal Communications Commission is refreshing its text alert system combining two types of alerts into a single National Alerts category for iPhones and other Wireless Emergency Alert supporting devices as well as introducing checks to prevent false alerts from being made The FCC issued a Report and Order on Thursday in response to the National Defense Authorization Act for Fiscal Year which required it to work with the Federal Emergency Management Agency FEMA to make rules to strengthen emergency alerting As part of the change the existing Presidential Alerts category that was introduced in will be combined with alerts from FEMA in a new category titled National Alerts according to The Verge The category will continue to be a non optional alert class that will appear on all WEA supporting mobile devices such as iPhones Read more |
2021-06-20 19:33:18 |
海外TECH |
Engadget |
Amazon's new Fire HD 10 tablet falls to $80 for Prime Day |
https://www.engadget.com/amazon-fire-hd-10-tablet-amazon-prime-day-2021-192029791.html?src=rss_b2c
|
amazon |
2021-06-20 19:20:29 |
海外TECH |
Engadget |
Amazon's Fire TV Stick 4K drops to $25 before Prime Day |
https://www.engadget.com/fire-tv-stick-4k-drops-to-25-before-amazon-prime-day-2021-190155447.html?src=rss_b2c
|
prime |
2021-06-20 19:01:55 |
海外TECH |
WIRED |
25 Last-Minute Father's Day Gifts on Sale Now |
https://www.wired.com/story/last-minute-fathers-day-gift-ideas-deals-2021-2
|
cooking |
2021-06-20 19:34:00 |
海外TECH |
WIRED |
Become a Prime Day Pro With These Tips and 23 Early Deals |
https://www.wired.com/story/early-amazon-prime-day-deals-and-tips-2021-2
|
advice |
2021-06-20 19:14:00 |
医療系 |
医療介護 CBnews |
アフターコロナに備えコロナ病棟をどう再開するか?-先が見えない時代の戦略的病院経営(149) |
https://www.cbnews.jp/news/entry/20210618170205
|
千葉大学医学部附属病院 |
2021-06-21 05:00:00 |
ニュース |
@日本経済新聞 電子版 |
新型ロープウエー開発、「宇宙エレベーター」から着想
https://t.co/SchBoF4cJz |
https://twitter.com/nikkei/statuses/1406700365743988738
|
開発 |
2021-06-20 19:47:57 |
ニュース |
@日本経済新聞 電子版 |
先端技術・供給網確保で1000億円基金 政府、米欧と協力
https://t.co/5em5s4AdM2 |
https://twitter.com/nikkei/statuses/1406700364766736384
|
先端技術 |
2021-06-20 19:47:56 |
ニュース |
@日本経済新聞 電子版 |
現役世代接種きょう本格化 職場の申請1373万人に
https://t.co/jjrtIe1r0q |
https://twitter.com/nikkei/statuses/1406700363814621187
|
職場 |
2021-06-20 19:47:56 |
ニュース |
@日本経済新聞 電子版 |
東京や大阪、まん延防止に移行 条件付きで酒類提供
https://t.co/e6lUXAiE4n |
https://twitter.com/nikkei/statuses/1406700362862514177
|
防止 |
2021-06-20 19:47:56 |
ニュース |
@日本経済新聞 電子版 |
株主提案で「監査等委員」刷新 内紛の天馬に法の盲点
https://t.co/Vd3sYrHV1n |
https://twitter.com/nikkei/statuses/1406700361834844164
|
監査 |
2021-06-20 19:47:56 |
ニュース |
@日本経済新聞 電子版 |
企業「今こそ採用」 コロナ後見据え、積極姿勢取り戻す
https://t.co/DCUBsVOM3m |
https://twitter.com/nikkei/statuses/1406700360828211202
|
積極 |
2021-06-20 19:47:55 |
ニュース |
@日本経済新聞 電子版 |
世界のM&A2.3倍に 1~6月2兆ドル超、脱炭素など軸
https://t.co/mKqnwjzLsZ |
https://twitter.com/nikkei/statuses/1406700359808999424
|
mampa |
2021-06-20 19:47:55 |
ニュース |
@日本経済新聞 電子版 |
設備投資回復、21年度10.8%増 需給逼迫やデジタル対応
https://t.co/uZm6hkkgTK |
https://twitter.com/nikkei/statuses/1406700357510590465
|
設備投資 |
2021-06-20 19:47:55 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
【入山章栄・解説動画】移動距離が長い人ほど「イノベーション」を起こせる理由 - 入山章栄の世界標準の経営理論 |
https://diamond.jp/articles/-/272747
|
【入山章栄・解説動画】移動距離が長い人ほど「イノベーション」を起こせる理由入山章栄の世界標準の経営理論ビジネスパーソンはもちろん、学生や研究者からも好評を博し、万部を突破した入山章栄氏の最新刊『世界標準の経営理論』。 |
2021-06-21 04:50:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
大学「入試・就職・序列」の最新情報を全網羅!おトクな大学院の情報も必見 - 入試・就職・序列 大学 |
https://diamond.jp/articles/-/274208
|
大学「入試・就職・序列」の最新情報を全網羅おトクな大学院の情報も必見入試・就職・序列大学新型コロナウイルス感染拡大の“甚大な被害を受けた大学。 |
2021-06-21 04:45:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
武田薬品、外国人CEO支配による米国企業化「総仕上げ」の先に待つ残酷な未来 - 武田薬品「破壊と創造」 |
https://diamond.jp/articles/-/274235
|
武田薬品 |
2021-06-21 04:40:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
北國銀行のビジネスモデルがシステムのクラウド化で一変する理由 - 橋本卓典の銀行革命 |
https://diamond.jp/articles/-/274344
|
勘定系システム |
2021-06-21 04:35:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
インフレに目をつぶる「高圧経済」政策、長期停滞脱却の“魔法の杖”になるか - 政策・マーケットラボ |
https://diamond.jp/articles/-/274476
|
物価上昇 |
2021-06-21 04:30:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
FOMCが利上げ示唆、米金融引き締めで始まるドル高圧力の行方 - 政策・マーケットラボ |
https://diamond.jp/articles/-/274426
|
|
2021-06-21 04:25:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
スペースX、天問1号、ブルー・オリジン…海外へ行けない今こそ宇宙をめざそう! - 経営・戦略デザインラボ |
https://diamond.jp/articles/-/274474
|
スペースX、天問号、ブルー・オリジン…海外へ行けない今こそ宇宙をめざそう経営・戦略デザインラボ今、人々の宇宙への関心が高まっています。 |
2021-06-21 04:20:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
出世に必須の決算書理解、41%の企業が課長に求める知識レベルは? - 今週の週刊ダイヤモンド ここが見どころ |
https://diamond.jp/articles/-/274372
|
出世に必須の決算書理解、の企業が課長に求める知識レベルは今週の週刊ダイヤモンドここが見どころ課長や部長など管理職になりたい。 |
2021-06-21 04:15:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
年収が高い不動産会社ランキング2020最新版【トップ5】三菱地所・三井不動産を上回ったのは? - ニッポンなんでもランキング! |
https://diamond.jp/articles/-/274520
|
三井不動産 |
2021-06-21 04:10:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
年収が高い不動産会社ランキング2020【全114社・完全版】 - ニッポンなんでもランキング! |
https://diamond.jp/articles/-/274473
|
三井不動産 |
2021-06-21 04:10:00 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
「座席で通話」「隣席確保」も解禁、鉄道各社の新たなサービスとは - News&Analysis |
https://diamond.jp/articles/-/274375
|
試行錯誤 |
2021-06-21 04:05:00 |
ビジネス |
東洋経済オンライン |
「中国は敵、米国は味方」の認識があまりに浅い訳 自民党の異端議員が説く中国と正対する方法 | 最新の週刊東洋経済 | 東洋経済オンライン |
https://toyokeizai.net/articles/-/435242?utm_source=rss&utm_medium=http&utm_campaign=link_back
|
同盟関係 |
2021-06-21 04:30:00 |
コメント
コメントを投稿