python |
Pythonタグが付けられた新着投稿 - Qiita |
VscodeとDockerでPython-Flaskの開発環境をサクッと作った |
https://qiita.com/ffrr55s/items/b576a15d478795715801
|
VscodeとDockerでPythonFlaskの開発環境をサクッと作った概要Flaskを触ることになったのでサクッと開発環境を用意したい。 |
2021-04-24 22:11:55 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
ゼロから始めるTryHackMe[1]: Linux Fundamentals |
https://qiita.com/suk0/items/d7052cabe05f4999552e
|
まずOSのすべてのファイルからshibaを探すのでfindこの出力結果からshibaという文字を含むファイルを探すためにgrepを付け足して、findgrepshibaここまではTryHackMeが説明してくれた知識。 |
2021-04-24 22:09:57 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
python tkinterGUIへの埋め込みmatplotlibで3Dフィギュアをプロット |
https://qiita.com/taiko1/items/ed9becf5110829adb401
|
pythontkinterGUIへの埋め込みmatplotlibでDフィギュアをプロットpythonでtkinterウィンドウ内にmatplotlibを埋め込みDフィギュアをプロットする。 |
2021-04-24 22:09:45 |
js |
JavaScriptタグが付けられた新着投稿 - Qiita |
slackの webhook を利用した際に、CORS制限で投稿が出来ない。 |
https://qiita.com/shu-prog/items/75c48dc45c5839cf88ed
|
最初は自分のコードを疑っていたのですが、OPTIONSメソッドの通信を正常に処理できないサーバーというのが、たまにあるらしく、今回はその事が原因のようでした。 |
2021-04-24 22:46:06 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
FW(UTM)配下のL3スイッチにつながるネットワークの制御について |
https://teratail.com/questions/335001?rss=all
|
PAのポリシー設定を変更することで、Lスイッチ配下のセグメント同士の通信も制御できてしまうのですが、なぜ制御出来るのかが分かりません。 |
2021-04-24 22:53:47 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
for文でのnp.allの使い方 |
https://teratail.com/questions/335000?rss=all
|
for文でのnpallの使い方Pythonnbsp競技プログラミングnbspを勉強し始めて数か月主に仕事後しか経っていないため不適切な質問や非効率なコードが表示されているかもしれませんが、ご容赦ください。 |
2021-04-24 22:51:08 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
headerの中のnavタグの配置について |
https://teratail.com/questions/334999?rss=all
|
目標ffaccdccfjpegこういう形のレイアウトを目標にコーディングしているのですが、cssの配置がうまくいっていません。 |
2021-04-24 22:49:45 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
ボタンを画像の上に置きたいです |
https://teratail.com/questions/334998?rss=all
|
ボタンを画像の上に置きたいですメッセージタグにある資料請求ボタンを画像の上に置きたいのですが、どうも置くことができません。 |
2021-04-24 22:45:13 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
【Python_データ分析】 timedeltaを用いたデータの可視化 |
https://teratail.com/questions/334997?rss=all
|
【Pythonデータ分析】timedeltaを用いたデータの可視化前提・実現したいことPythonのtimedeltaに関するデータの可視化について質問させていただきます。 |
2021-04-24 22:27:51 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
Swift UIとRuby on Railsのアプリの連携について |
https://teratail.com/questions/334996?rss=all
|
SwiftUIとRubyonRailsのアプリの連携について現在、RubynbsponnbspRails歴年のプログラマの者です。 |
2021-04-24 22:17:34 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
[HTML5,CSS3,Scss]widthのレスポンシブ対応について |
https://teratail.com/questions/334995?rss=all
|
HTMLCSSScsswidthのレスポンシブ対応についてwidthを使いで要素の幅を指定し、PCタブレット画面までの間でレイアウトが崩れないようにしたいです。 |
2021-04-24 22:09:18 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
数字当てゲームの作成 |
https://teratail.com/questions/334994?rss=all
|
数字当てゲームの作成前提・実現したいことコンピューターがランダムで生成したつの数字を当てるゲームを作成したいです。 |
2021-04-24 22:08:19 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
RailsでBootstrapのモーダルがうまく機能しない |
https://teratail.com/questions/334993?rss=all
|
RailsでBootstrapのモーダルがうまく機能しない某書籍の内容でRailsアプリを作っているのですが、Bootstrapのモーダルがうまく表示されませんhamlで書いているのですがどこか間違いありますでしょうか。 |
2021-04-24 22:07:16 |
Program |
[全てのタグ]の新着質問一覧|teratail(テラテイル) |
googleのスプレッドシート:QUERY・IMPORTRANGE を使用しさらに contains で絞りたい時。 |
https://teratail.com/questions/334992?rss=all
|
googleのスプレッドシートQUERY・IMPORTRANGEを使用しさらにcontainsで絞りたい時。 |
2021-04-24 22:02:19 |
Ruby |
Rubyタグが付けられた新着投稿 - Qiita |
Rails初学者によるRailsチュートリアル学習記録④ 第2章 |
https://qiita.com/UtimoriNI/items/e39a601226eb1b6b1dbc
|
第章の概要scaffoldを使用したアプリ作成scaffoldとはscaffoldの使い方モデルの設計ユーザモデルの設計マイクロポストの設計MVCの挙動実際のアプリケーションに近づけるためにマイクロポストのバリデーションユーザーとマイクロポストの関連付け学習内容scaffoldを使用したToyアプリ作成scaffoldとは①scaffoldでできることscaffoldとは建築現場などで使用される「足場」という意味で、webアプリケーションの開発においては、モデルやビュー、コントローラという開発上での足場をまとめて作成してくれる機能を持ちます。 |
2021-04-24 22:02:57 |
AWS |
AWSタグが付けられた新着投稿 - Qiita |
【AWS】EC2サーバーでビルドしてたらout of memoryが出たのでSwap領域を確保した話 |
https://qiita.com/shin_moto/items/31dc129e5d1692717b97
|
【AWS】ECサーバーでビルドしてたらoutofmemoryが出たのでSwap領域を確保した話事象個人アプリのECがtmicroなので、メモリ不足を起こして、インスタンス内でビルドを行うとoutofmemoryでエラーになるようになった。 |
2021-04-24 22:21:41 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
Docker+Railsチュートリアルやってみる |
https://qiita.com/ayanokobayashi103/items/635db09fc777a6af4453
|
DockerRailsチュートリアルやってみるはじめにDockerComposeを利用してRailsPostgreSQLアプリを設定しRailsのwelcomeページを表示させる。 |
2021-04-24 22:23:18 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
VscodeとDockerでPython-Flaskの開発環境をサクッと作った |
https://qiita.com/ffrr55s/items/b576a15d478795715801
|
VscodeとDockerでPythonFlaskの開発環境をサクッと作った概要Flaskを触ることになったのでサクッと開発環境を用意したい。 |
2021-04-24 22:11:55 |
Git |
Gitタグが付けられた新着投稿 - Qiita |
【メモ】実務始めてよく使うgit操作 |
https://qiita.com/nyappy15th/items/54dced3cee9095a39580
|
個人的なメモも兼ねての投稿です先輩「このブランチで作業してください」既存のブランチをローカルに反映させれば良いので、下記コマンドを入力します。 |
2021-04-24 22:21:03 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
Docker+Railsチュートリアルやってみる |
https://qiita.com/ayanokobayashi103/items/635db09fc777a6af4453
|
DockerRailsチュートリアルやってみるはじめにDockerComposeを利用してRailsPostgreSQLアプリを設定しRailsのwelcomeページを表示させる。 |
2021-04-24 22:23:18 |
Ruby |
Railsタグが付けられた新着投稿 - Qiita |
Rails初学者によるRailsチュートリアル学習記録④ 第2章 |
https://qiita.com/UtimoriNI/items/e39a601226eb1b6b1dbc
|
第章の概要scaffoldを使用したアプリ作成scaffoldとはscaffoldの使い方モデルの設計ユーザモデルの設計マイクロポストの設計MVCの挙動実際のアプリケーションに近づけるためにマイクロポストのバリデーションユーザーとマイクロポストの関連付け学習内容scaffoldを使用したToyアプリ作成scaffoldとは①scaffoldでできることscaffoldとは建築現場などで使用される「足場」という意味で、webアプリケーションの開発においては、モデルやビュー、コントローラという開発上での足場をまとめて作成してくれる機能を持ちます。 |
2021-04-24 22:02:57 |
海外TECH |
DEV Community |
JavaScript function add(1)(2)(3)(4) to achieve infinite accumulation-step by step principle analysis |
https://dev.to/satishrajnale/javascript-function-add-1-2-3-4-to-achieve-infinite-accumulation-step-by-step-principle-analysis-15l8
|
JavaScript function add to achieve infinite accumulation step by step principle analysisQuestion We have a requirement to implement an infinitely cumulative function with js like add gt add gt add gt add gt and so on At first glance it looks amazing Now I will implement such an add function step by step we now define a toSting method for the function sumfunction sum a return a sum toString function return console log sum typeof sum After defining the sum toString method if you directly console log sum this function will be printed out If you directly alert sum we can see that will pop up Let s check the type of sum typeof sum Obviously sum is a function Okay now let s wrap this s function with a coat function add a function sum a return a sum toString function return a return sum console log add In the above code we have wrapped the previous code with a layer and also modified the sum toString method so that it returns the parameter a passed in from the outside instead of the previously fixed After wrapping a layer the return value is a function thus forming a closure In this way when we call add the return value is actually a function the function sum inside However when we alert sum will pop up Last stepfunction add a function sum b a a b return sum sum toString function return a return sum console log add At this point we can see that the above console log add this sentence prints out a function function in fact when alert add it will pop up This is the implementation process of add obviously our accumulating function can be called infinitely The whole realization process is two key points Use closures and have a deep understanding of JavaScript s scope chain prototype chain Rewrite the toSting method of the function let s analyze add step by step a Execute add What is returned is the sum function inside Through the closure the variable a in the sum function can be accessed so when we alert add the toSting method called will change the scope prototype chain The inside a pops up b Execute add lt is equivalent to gt sum This is equivalent to passing to b in the sum function so that a in the scope prototype chain a b at this time a continue to be saved in the scope Then it returns to the sum function c Execute add lt is equivalent to gt sum Same as the analysis in step b above except that a in the scope is updated and then the sum function is also returned |
2021-04-24 13:59:08 |
海外TECH |
DEV Community |
Fullscreen toggle functionality in Angular using Directives. |
https://dev.to/angular/fullscreen-toggle-functionality-in-angular-using-directives-59n0
|
Fullscreen toggle functionality in Angular using Directives We are gonna see some really cool ways to leverage directives to create a super simple fullscreen toggle functionality Let s see the definition for a directive in Angular Directives are classes that add additional behavior to elements in your Angular applications With Angular s built in directives you can manage forms lists styles and what users see As the definition says we can use it to add additional behavior to elements If it is not cool I don t know what else is Directives in AngularFor people often starting with Angular the term directive and how it works might be confusing And most of them would simply be stopping at using some of the most common directives like NgClassNgStyleNgIfNgFor We don t really have to care about how adding this would magically make things happen We might know that to conditionally render an element we can use ngIf and only renders the element if the case is true That is the end of the story One piece of advice that I would like to give to those who are getting the hang of Angular is that try to dig into these features and try to find the underlying implementation Angular has really good documentation on different types of directives and how to use them Read Here built in directivesTip To see how the built in directives are written just visit their API documentation page and click on the code icon which will take you to the direct file in the repo Creating a Fullscreen DirectiveSo today we are going to build a custom directive that is gonna help us with one single functionality maximize and minimize an element Enough talking let s get right into it Create a module for our directiveThis is actually optional But I do like to create a module and then the directive will be declared and exported from this module Then I would import this module wherever I need this functionality import NgModule from angular core import MaximizeDirective from maxmimize directive NgModule declarations MaximizeDirective exports MaximizeDirective lt Make sure to export it export class MaximizeModule Create the directiveNext up we create the directive I am calling it the maximize directive Once the directive is created let us add the logic to it The idea is to basically make the width and height of the element where the directive is placed to say vw and vh so that it spans the entire screen real estate You might also want to change the positioning of the element in some cases import Directive ElementRef Renderer from angular core import BehaviorSubject from rxjs import tap from rxjs operators Directive selector maximize exportAs maximize lt Make not of this here export class MaximizeDirective private isMaximizedSubject new BehaviorSubject false isMaximized this isMaximizedSubject pipe constructor private el ElementRef private renderer Renderer toggle this isMaximizedSubject getValue this minimize this maximize maximize if this el this isMaximizedSubject next true this renderer addClass this el nativeElement fullscreen minimize if this el this isMaximizedSubject next false this renderer removeClass this el nativeElement fullscreen Let me break down the code for you guys First thing is that we need to get hold of the element on which the directive is applied We do that by injecting ElementRef in the constructor This would give reference to the element Next we keep a subject to maintain the state of the directive to know whether we are currently minimized or maximized Modifying the element propertySo I have a CSS class defined which just modifies the height and width fullscreen width vw height vh position fixed top left The idea now is to toggle this class when the user wants it to be in fullscreen mode or not For that we get hold of Renderer Doc which is a great way to manipulate DOM elements in Angular So write two functions one for adding the class and one for removing We update the state when these functions are called Another function called toggle is added so that the user can perform the operation without having to know about the current state Exporting the directive instanceIn the section above I have marked a particular line of code Directive selector maximize exportAs maximize lt Make not of this here This is a really interesting feature that angular provides In the directive we can specify whether we want to make the instance available in the template Read here exportasWhat it does is that the directive instance will be made available in the template using the specified name lt div class card maximize maximize maximize gt lt p gt maximize isMaximized async lt p gt lt div gt See how I access the property isMaximized of the directive in the template Similarly all the public properties of the directive can be accessed using maximize UsageFor using the directive first I import the module in my AppModule If you have already declared the directive in your AppModule you can skip this step import BrowserModule from angular platform browser import NgModule from angular core import AppComponent from app component import MaximizeModule from maximize maximize module NgModule declarations AppComponent imports BrowserModule MaximizeModule lt Imported the module providers bootstrap AppComponent export class AppModule In your template you can now add the directive to any element lt div class card maximize maximize maximize gt lt button class min button click maximize minimize gt lt button gt lt button class max button click maximize maximize gt lt button gt lt div gt So like we ve seen in the section where we talked about getting the instance we can get hold of the minimize and maximize function in the directive to apply remove the class respectively Bonus Go Fullscreen in the browser tooSo what we did would just maximize the element but you would also want to make the browser go fullscreen we can add that too Install the screenfull librarynpm i screenfullUpdate the directive like so import as Fullscreen from screenfull lt add the import maximize if this el this isMaximizedSubject next true this renderer addClass this el nativeElement fullscreen if Fullscreen isEnabled Fullscreen request lt request fullscreen mode minimize if this el this isMaximizedSubject next false this renderer removeClass this el nativeElement fullscreen if Fullscreen isEnabled Fullscreen exit lt exit fullscreen mode Note You might want to open the sandbox preview in a separate window to get the fullscreen working or directly visit this preview URL CodeDo add your thoughts in the comments section Stay Safe ️ |
2021-04-24 13:28:27 |
海外TECH |
DEV Community |
Fun facts about programming – Enjoy Programing |
https://dev.to/animeshdhamku/fun-facts-about-programming-enjoy-programing-2ol7
|
Fun facts about programming Enjoy Programing Real programmersReal programmers favourite line is “It works on my machine Real programmers only test their code in production Real programmers hate to write specs But if they have to… Real programmers debug code on the production environment Real programmers…fix one bug and get new ones You know you re a programmer when you spill coffee on your laptop and aggressively press Ctrl Z to undo the error when you try to Ctrl F in a printed book when you spend a day to find the problem and you fix it with one line of code when your code works and you have no idea why when you tell a programmer joke and nobody understands it Most programmers struggle with two thingnaming things and cache invalidation the right amount of curses mixed with just enough coffee other programmers and other programmers code debugging and more debugging coffee and bugs The first rule of programmingnever ask “why Just be grateful it works if something looks easy it s hard if it looks hard it s almost impossible if it works don t touch it never write standardized code so no one will want to steal it Get some more funny facts about programingGet some interesting facts about programing |
2021-04-24 13:22:54 |
海外TECH |
DEV Community |
7 Way To Find In Array Using Javascript |
https://dev.to/pawanbhayde/7-way-to-find-in-array-using-javascript-4lhf
|
Way To Find In Array Using Javascript find The array find method returns the first matched element in array that satisfies a condition The find method takes a function as argument which returns true or false based on some condition let score let value score find val gt val gt console log value findlndex The Array findindex method returns the index of first matched element in array that satisfies a condition This method also takes a function argument which returns true or false let score let value score findIndex val val gt console log value includes The method checks if a specified element is present or not in an array and returns a Boolean value If the specified element ispresent in array then it returns true else false This method is case sensitive let menu Pizza Burger Momos console log menu includes Dal batti false indexOf This method returns the index of first occurrence of matched element in array If no element is matched then it returns This method is case sensitive let fruits console log fruits indexOf console log fruits indexOf lastIndexOf The method returns the index of last occurrence of matched element in array It searches element from end to beginning of array If no element is matched then it returns This method is case sensitive let fruits console log fruits lastIndexOf console log fruist lastIndexOf map The map method creates a new array populated with the results of calling a provided function on every element in the calling array let marks let pass marks map val gt if val gt pass push val filter This method finds and filter out elements that do not pass the condition This method takes a function as argument which returns true or false This function executes for each element in array If the function returns true for any element then only that element gets included in the returned array let marks let pass marks filter val →val gt console log pass Note visit my youtube channel for frontend tutorialssubscribe to my youtube channel Resent post Top Trending GitHub Repositories Pawan Bhayde・Apr ・ min read javascript github git webdev |
2021-04-24 13:18:28 |
海外TECH |
DEV Community |
Question 16 : JavaScript in-depth 4 types of common memory leaks and how to avoid |
https://dev.to/satishrajnale/question-16-javascript-in-depth-4-types-of-common-memory-leaks-and-how-to-avoid-13fd
|
Question JavaScript in depth types of common memory leaks and how to avoid What are possible causes of memory leaks Advance JavaScript concepts Garbage collection algorithm The commonly used garbage collection algorithm is called Mark and sweep and the algorithm consists of the following steps The garbage collector creates a roots list Roots are usually references to global variables in the code In JavaScript the window object is a global variable and is treated as root The window object always exists so the garbage collector can check whether it and all its child objects exist that is it is not garbage All roots are checked and marked as active ie not junk All child objects are also checked recursively If all objects starting from root are reachable they are not treated as garbage All unmarked memory will be treated as garbage and the collector can now release the memory and return it to the operating system Modern garbage collectors have improved the algorithm but the essence is the same reachable memory is marked and the rest is treated as garbage Four common JS memory leaksUnexpected global variablesUndefined variables will create a new variable in the global object as follows function myfunc arg bar this is a hidden global variable Function myfunc internal forget to use var in fact JS would assume bar mounted to the global object and accidentally create a global variablefunction foo arg window bar this is an explicit global variable Another surprise may be provided by global variables this created function foo this variable potential accidental global Foo calls itself this points to the global object window instead of undefined foo Solution Add to the head of the JavaScript file to use strict use strict mode to avoid unexpected global variables At this time the this in the above example points to undefined If you must use a global variable to store a large amount of data make sure to set it to null or redefine it after use The forgotten timer or callback functionTimer setInterval codes are very commonvar local getData setInterval function var node document getElementById Node if node Process node and data node innerHTML JSON stringify local The above example shows that when the node or data is no longer needed the timer still points to the data So even when the node is removed the interval is still alive and the garbage collector cannot reclaim it and its dependencies cannot be reclaimed unless the timer is terminated var element document getElementById button function onClick event element innerHTML text element addEventListener click onClick For the observer example above once they are no longer needed or the associated object becomes unreachable it is important to explicitly remove them Old IE cannot handle circular references Because the old version of IE cannot detect circular references between DOM nodes and JavaScript code it will cause memory leaks However modern browsers including IE and Microsoft Edge use more advanced garbage collection algorithms mark removal which can already detect and process circular references correctly That is recovered node memory you do not have to call removeEventListener up References away from the DOMIf you save the DOM as a dictionary JSON key value pair or an array at this time there are two references to the same DOM element one in the DOM tree and the other in the dictionary Then both references will need to be cleared in the future var elements button document getElementById button image document getElementById image text document getElementById text function doStuff image src button click console log text innerHTML More logic function removeButton Button is a descendant element of document body removeChild document getElementById button At this point it still exists A global button reference elements dictionary The button element is still in memory and cannot be recycled by GC If the code is saved in a certain form lt td gt references And in future decided to delete the entire table when the GC will intuitively think in addition to recycling saved lt td gt other nodes outside Is not the case this lt td gt is a form of child nodes child element of the parent element is a reference to the relationship Since the code retains lt td gt references yet to cause the entire table in memory So be careful when saving DOM element references ClosureThe key to closures is that anonymous functions can access variables in the parent scope var football null var replaceBall function var firstBall football var unused function if firstBall console log Got it football reallyLongArr new Array join goal function console log message setInterval replaceBall Each time it is called replaceBall football a goal new object containing a large array and a new closure is obtained Meanwhile the variable unused is a reference to the firstBall closure previously replaceBall they call football goal can be football used goal and unused shared closure scope although unused never used it refers to firstBall force it to remain in memory to prevent recovery Solution In replaceBall the final addition firstBall null lt gt By Satish Rajnale lt gt |
2021-04-24 13:16:52 |
海外TECH |
DEV Community |
How to Send Notifications in Chrome Extensions |
https://dev.to/shahednasser/how-to-send-notifications-in-chrome-extensions-2hmk
|
How to Send Notifications in Chrome ExtensionsThis article was originally posted on my personal blogIn this tutorial we ll go over how to send notifications in Chrome Extensions We ll go over how to send one notification and how to schedule notifications to be sent at a later time PrerequisitesThis tutorial assumes you already know how to create a Chrome extension If you don t then here is one you can start with first Setting PermissionsBefore you can send any type of notification you need to first add in yourmanifest jsoninpermissionskey the following permissions notifications other permissions in your extension This means that the user when installing or updating your extension has to accept that they will receive notifications in order to use the extension Send a NotificationTo send a notification you need to use theNotifications API In particular thechrome notifications createmethod which takes the following required options chrome notifications create NOTFICATION ID type basic iconUrl path title notification title message notification message priority Here s what each of these options means NOTIFICATION ID The id of the notification This can be necessary for updating the notification or clearing it type The type of notification Its values can be basic image list progress iconUrl The path to the icon that should be shown in the notification This should be relative to the root of your extension title the title of the notification message the message to be shown in the notification priority this one is not required but I recommend including it The value for it can range from to where is the lowest priority and is the highest The default for this option is so your notifications can go by unseen if you don t include this option It should also be noted that a value less than will produce an error on devices that don t have a notification center There are some other options that are optional buttons buttons that you want to be shown in the notification This takes an array of buttons with at most buttons The array should be an object with the property title which will be the title of the button For example buttons title Yes title No contextMessage This message will be shown in a lower font weight eventTime Timestamp associated with the notification For example eventTime Date now items This will only be shown for Mac OS X This could be useful for notifications of type list For example items title Item message This is first item progress This can be useful for notifications of type progress It takes a value between and requiresInteraction This one will only work for Chrome versions since The value for this is boolean If set to true it means that the notification will not disappear from the screen until the user interacts with the message by either clicking on it or dismissing it The default value for this is false silent This one will only work for Chrome versions since The value of this is boolean If set to true then the notification will not make sound or vibration The default is false To send a basic notification that just shows a message to the user chrome notifications create test type basic iconUrl images png title Test Message message You are awesome priority This will send one notification at the moment it s executed Scheduling NotificationsIn a lot of cases you don t actually want to send the notification now or you want to send notification at some interval like once a day For this we will use the Alarms API Alarms allow us to schedule something to be run at a later time When you create an alarm you can specify the time interval it will run at Then you can listen to the alarm and when it runs executes whatever code you want To be able to use Alarms we need to also include it in our permissions in manifest json permissions alarms notifications other permissions your extension require To send notifications at a certain schedule here s how the workflow goes Create an alarm that runs at certain intervalsListen for when the alarm runsWhen the alarm runs execute some logic and create a notificationCreate an alarm that runs at certain intervalsTo create an alarm we will use the methodchrome alarms create chrome alarms create ALARM NAME options You only need to specify the name of the alarmALARM NAME which will be used later when listening to the alarm No other options are required However if you use it without options the alarm will run only once at the time it was created The options you can pass are when When should the alarm start working If you want it to start right away when Date now periodInMinutes This is where we specify when the alarm will run It takes a number which is the number of minutes between each time the alarm fires So if I want the alarm to be fired every five minutes periodInMinutes delayInMinutes This specifies if theonAlarmevent should delay a little before firing The most important option here isperiodInMinutes It specifies when do we want to create our notification So if we want to create an alarm that will let us create a notification that runs everyday chrome alarm create testAlarm periodInMinutes Listen for when the alarm runsThe next step would be to listen when the alarm runs This should be usually done in background scripts for Manifest V or service workers for Manifest V You can read more about the differences between Manifest V and V here If you don t know what a background script is it s as its name says a script that s always running in the background even if your extension s page or pop up or whatever your extension uses is not open or running This helps us listen to events alarms messages etc at all times Service workers were introduced in Manifest V as a replacement for background scripts The main difference is service workers are not always running Service workers register event listeners to alarms messages etc same as background scripts so only the listeners run when necessary like when an event occurs If you don t already have a background script in your chrome extension you need to first include it inmanifest json background scripts js background js persistent false Or if you re using Manifest V you need to register a service worker background service worker js background js Then in the script we will listen to the alarm usingchrome alarms onAlarm addListenerwhich takes a callback function which will be our listener This callback function will be executed every time an alarm in our extension is run so we need to make sure we only listen to the alarm we need which we namedtestAlarm chrome alarms onAlarm addListener alarm gt if alarm name testAlarm our alarm is running send notification We need to check that alarm name testAlarm to make sure that our notifications alarm is running This is important if you have multiple alarms in your extension as well to make sure you re executing the desired logic for the correct alarm So if the condition is true we can create the notification When the alarm runs execute some logic and create a notificationDepending on your use case you might execute some logic maybe send a request to a server or any other logic then run the notification What we will do is that we ll just create the message when the alarm runs This is how it can be done chrome alarms onAlarm addListener alarm gt if alarm name testAlarm chrome notifications create test type basic iconUrl images png title Test Message message You are awesome priority After these steps our extension will create an alarm that will run once a day and executes the code in the listener we added to theonAlarmevent This listener will create a notification Thus a notification will be sent to the user every day Sending a Notification on FirefoxSending a notification on Firefox is exactly the same except you just need to replace chrome in all of the methods used with browser You can read more about the difference between Firefox and Chrome here SummaryTo create a notification you need to Add notifications to the permissions array in manifest jsonUse chrome notifications create to create a notification and send it To schedule a notification to run at an interval of time you need to Add alarms to the permissions array in manifest jsonUse chrome alarms create to create an alarm Listen to the alarm with chrome alarms onAlarm addListener and create a notification inside the listener If you would like to connect and talk more about this article or programming in general you can find me on my Twitter account shahednasserr |
2021-04-24 13:10:08 |
海外TECH |
DEV Community |
Working with Scylla Database |
https://dev.to/j_a_o_v_c_t_r/working-with-scylla-database-3al9
|
Working with Scylla DatabaseHello everyone My intention today is to write about Scylla database Scylla is a NoSQL database based on Cassandra One difference between both is that Cassandra is developed in Java language and Scylla in C language The goal of that is to avoid some Java processes that can impact the performance of the application like garbage collector and stop the world After this introduction let s see how we can use Scylla and know some details about it Downloading imageFor work with Scylla we will use docker The first step is to download the image We can use the command below docker run name scylla db test d scylladb scylla After that we can use some tools of Scylla and guarantee that our database is healthy docker exec it scylla db test nodetool statusThe result of executing the command above isDatacenter datacenter Status Up Down State Normal Leaving Joining Moving Address Load Tokens Owns Host ID RackUN KB badb bea cf b eafbac rackThere is information about Datacenter but this is not our focus in this post At this moment we should just know that our node more information about that in the next section is Up and Normal UN PlaytimeFor executing commands in Scylla there is a CLI called cqlsh docker exec it scylla db test cqlshConnected to at cqlsh Cassandra CQL spec Native protocol v Use HELP for help cqlsh gt The first thing that we can do is create a keyspace Different from relational databases Scylla doesn t have the database concept In Scylla we work with keyspace which is a top level container that stores tables Besides creating a keyspace we need to configure other attributes like replication strategy CREATE KEYSPACE automobiles WITH replication class SimpleStrategy replication factor Like I said previously it s necessary to configure replication strategy and how we can see this is done with attribute replication Inside brackets has two configurations The replication factor which means that the data inserted in a table of automobiles keyspace will be replicated in nodes Nodes are instances of Scylla DB The other configuration is class and defines the replication strategy class to use There are options SimpleStrategy defines a replication factor for the whole cluster The only sub options supported is replication factor to define that replication factor and is mandatory NetworkTopologyStrategy A replication strategy that lets you set the replication factor independently for each data center The rest of the sub options are key value pairs where a key is a data center name and its value is the associated replication factor or a single key value with Auto Expand Replication Factor Recommended for production Just for knowledge we won t talk about this option in this post Now we can create our table The name will be Car USE automobiles CREATE TABLE car id uuid brand text model text color text PRIMARY KEY id How we can see Scylla syntax is similar to SQL syntax and to include data we use the insert clause INSERT INTO car id brand color model VALUES e eb d a VW Red Golf To see data in the table is just necessary to use the select clause SELECT FROM car id brand color model e eb d a VW Red Golf ConclusionThe idea of this post is to presenting Scylla DB and some operations that we can do There are more details that I intended to present in the future as partition key and clustering key and how we can define our primary key mixing up of both concepts This is crucial for better performance at the moment that we need to filter our searches For now that is enough I will see you in the next post References |
2021-04-24 13:01:41 |
海外TECH |
Engadget |
The Morning After: Picking the right mirrorless camera in 2021 |
https://www.engadget.com/the-morning-after-mirrorless-camera-guide-133043912.html
|
apple |
2021-04-24 13:30:43 |
海外科学 |
NYT > Science |
Highlights From SpaceX’s Launch of 4 Astronauts for NASA |
https://www.nytimes.com/live/2021/04/23/science/spacex-nasa-launch/
|
Highlights From SpaceX s Launch of Astronauts for NASAThe Crew mission is the third to carry people to the International Space Station “It s great to be back in space said the flight s commander |
2021-04-24 13:05:27 |
ニュース |
BBC News - Home |
Newcastle score in 95th minute to deny Liverpool key win in battle for top four |
https://www.bbc.co.uk/sport/football/56782072
|
Newcastle score in th minute to deny Liverpool key win in battle for top fourNewcastle substitute Joe Willock scores a dramatic stoppage time equaliser to damage Liverpool s hopes of Champions League football |
2021-04-24 13:51:26 |
LifeHuck |
ライフハッカー[日本版] |
お手入れ簡単&ドリンクのおいしさキープ。磁器製タンブラーがプロジェクト終了間近 |
https://www.lifehacker.jp/2021/04/233699-machi-ya-kokoroflask-end.html
|
kokoro |
2021-04-24 23:00:00 |
LifeHuck |
ライフハッカー[日本版] |
Appleのシリアル番号から製造国を解読する方法 |
https://www.lifehacker.jp/2021/04/learn-the-secret-language-of-apple-serial-numbers-whi.html
|
apple |
2021-04-24 22:05:00 |
サブカルネタ |
ラーブロ |
デカ盛り戦隊 豚レンジャー/まぜそば並 (880円) |
http://feedproxy.google.com/~r/rablo/~3/6XVkvS4Ja9M/80d94d254c62ce654a5ecfae3f705eb2
|
埼玉県和光市 |
2021-04-24 14:04:20 |
北海道 |
北海道新聞 |
連休中のエンタメ大打撃 「命には代えられない」と嘆きも |
https://www.hokkaido-np.co.jp/article/537089/
|
新型コロナウイルス |
2021-04-24 22:12:00 |
北海道 |
北海道新聞 |
「宇宙のハッピーな11人」 野口聡一さん、記念写真投稿 |
https://www.hokkaido-np.co.jp/article/537088/
|
国際宇宙ステーション |
2021-04-24 22:08:00 |
北海道 |
北海道新聞 |
バスケB1、川崎がCS進出 宇都宮に競り勝つ |
https://www.hokkaido-np.co.jp/article/537087/
|
宇都宮市 |
2021-04-24 22:08:00 |
北海道 |
北海道新聞 |
人出、半数超の地点で増加 前週比、4都府県は9割で上回る |
https://www.hokkaido-np.co.jp/article/537086/
|
都府県 |
2021-04-24 22:01:00 |
北海道 |
北海道新聞 |
衆院道2区補選 有権者の思い届け 25日投開票 コロナ対策、育児支援など注文 |
https://www.hokkaido-np.co.jp/article/537084/
|
補欠選挙 |
2021-04-24 22:02:07 |
コメント
コメントを投稿