投稿時間:2022-04-18 08:21:28 RSSフィード2022-04-18 08:00 分まとめ(23件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… 「iPhone 14」シリーズの新たなCAD画像が流出か https://taisy0.com/2022/04/18/155902.html iphone 2022-04-17 22:32:56
IT ITmedia 総合記事一覧 [ITmedia エグゼクティブ] 第4回 既存事業か新規事業かではなく、既存も新規も進めてこそのビジネスDX https://mag.executive.itmedia.co.jp/executive/articles/2204/18/news024.html itmedia 2022-04-18 07:01:00
python Pythonタグが付けられた新着投稿 - Qiita AtCoder Beginner Contest 248 A~D 4完記事 https://qiita.com/kani_kani_kani/items/b668a9187a52439cde9c alacked 2022-04-18 07:26:29
python Pythonタグが付けられた新着投稿 - Qiita Pythonで独立した実行に対して重複しないようにJobを与えたときのメモ https://qiita.com/nabenabe0928/items/74786f97618e93816b74 sqlalc 2022-04-18 07:16:50
python Pythonタグが付けられた新着投稿 - Qiita 自作AIがスーパーマリオ1-1をやっとのことでクリアした https://qiita.com/temmaru/items/1bb590709cf623a5f6d1 自作 2022-04-18 07:06:30
AWS AWSタグが付けられた新着投稿 - Qiita 【AWS】WEBサーバー構築 https://qiita.com/chakiryou/items/13f0cf963ab32f02e974 yuminstallhttpdp 2022-04-18 07:29:08
技術ブログ Developers.IO ノーコードで運用自動化! Systems Manager Automationを見直したい https://dev.classmethod.jp/articles/introduce-ssm-automation/ ohumanlaborisnohumanerror 2022-04-17 22:00:33
海外TECH DEV Community Creating anonymous chat rooms with Socket.io and Express.js https://dev.to/zt4ff_1/creating-anonymous-chat-rooms-with-socketio-and-expressjs-1cm0 Creating anonymous chat rooms with Socket io and Express jsIn this article we are going to create a chat application that connects people anonymously to different rooms together in pairs of two The chat application would make use of Express js for the server side code listen to web socket communication using Socket io and the client side will be developed with vanilla JavaScript Setting up our projectWe will create a directory named chat app and change the directory to the directory using the command mkdir chat app amp amp cd chat appInitialize our Node application by running the command yarn init yInstall express in our project using yarn by running the command yarn add expressWe will create a JavaScript file named app js and create a simple Node HTTP server Next we will import express into our application create an express app and start the server to listen to requests on port app jsconst http require http const express require express const app express app get index req res gt res send Welcome home const server http createServer app server on error err gt console log Error opening server server listen gt console log Server working on port Now we can start the application by running the command node app jsYou can visit http localhost index http localhost index on your browser to test that the application works Initializing socket io on the server sideTo initialize a socket on the server side follow the following steps Install socket io dependency into our application by running the command yarn add socket ioImport socket io into our code create a new socket server and then add an event listener to the socket to listen if a connection is made app jsconst http require http const Server require socket io const express require express const app express app get index req res gt res send Welcome home const server http createServer app const io new Server server io on connection socket gt console log connected server on error err gt console log Error opening server server listen gt console log Server working on port Initializing socket io on the client sideWe would be creating a simple UI using Vanilla JavaScript and we serve the web page as a static file from our express application We d create a public directory including files to build up our UI making our project structure look like this chat app node modules public index html main js app js package json yarn lockWe are going to be making use of Tailwind CSS to style the Client UI to reduce the amount of custom CSS we d be writing In the index html create a template for our chat window lt index html gt lt DOCTYPE html gt lt html lang en gt lt head gt lt meta name viewport content width device width initial scale gt lt script src gt lt script gt lt title gt Anon Chat App lt title gt lt head gt lt body gt lt div class flex p sm p justify between flex flex col h screen gt lt div id messages class flex flex col space y p overflow y auto scrollbar thumb blue scrollbar thumb rounded scrollbar track blue lighter scrollbar w scrolling touch gt lt div gt lt div class border t border gray px pt mb sm mb gt lt div class relative flex gt lt input type text placeholder Write your message class w full focus outline none focus placeholder gray text gray placeholder gray pl bg gray rounded md py gt lt div class absolute right items center inset y hidden sm flex gt lt button type button class inline flex items center justify center rounded lg px py transition duration ease in out text white bg blue hover bg blue focus outline none gt lt span class font bold gt Send lt span gt lt svg xmlns viewBox fill currentColor class h w ml transform rotate gt lt path d M a l a l A Va va l a l z gt lt path gt lt svg gt lt button gt lt div gt lt div gt lt div gt lt div gt lt script src socket io socket io js gt lt script gt lt script src main js gt lt script gt lt body gt lt html gt In the HTML file above we included two JavaScript files the first one to initialize socket io on the client side and another main js file to write our custom JavaScript code Then in the main js file we would create a function that is able to add a message to the chatbox The function createMessage will expect two arguments The first argument is the message string and the second argument is a boolean to determine if the message is from the user or from another external user main jsconst messageBox document querySelector messages function createMessage text ownMessage false const messageElement document createElement div messageElement className chat message const subMesssageElement document createElement div subMesssageElement className px py rounded lg inline block rounded bl none bg gray text gray if ownMessage subMesssageElement className float right bg blue text white subMesssageElement innerText text messageElement appendChild subMesssageElement messageBox appendChild messageElement createMessage Welcome to vahalla createMessage Who are you to talk to me true Change the code in the server application app js make use of static files to render the client UI app jsconst http require http const Server require socket io const express require express const path require path const app express app use express static path join dirname public const server http createServer app const io new Server server io on connection socket gt console log connected server on error err gt console log Error opening server server listen gt console log Server working on port NOTE To view the changes made in our application we have to stop the running server application and re run it for the new changes to take effect So we are making use of nodemon to automate this process for us Install nodemon by running npm install g nodemonThen run the node application using nodemon nodemon app jsOpen http localhost http localhost on your browser to view what the chat app would look like Creating different rooms for Web Socket communicationTo keep track of the rooms created and the number of users connected to each room we will create a Room class to manage this data for us We d create a new file named room js in the root directory of our project Then we create the Room class and have the constructor initialize a property for keeping the state of our room room js the maximum number of people allowed in each roomconst ROOM MAX CAPACITY class Room constructor this roomsState module exports Room The roomsState is an array of objects that keeps the information about each room ID created and the number of users in that room So a typical roomsState would look like this rooms state roomID some id users roomID a different id users Next add a method to join a room The method will loops through the room to check if any rooms have a number of users that are less than the maximum number of participants allowed in each room If all room in the list is occupied it would create a new room and initialize the number of users in that room to To generate a unique id we would be making use of a package known as uuid in our application Install uuid by running this command in our terminal yarn add uuidThen import the package into our application by running as follows room jsconst v uuidv require uuid class Room constructor joinRoom return new Promise resolve gt for let i i lt this roomsState length i if this roomsState i users lt ROOM MAX CAPACITY this roomsState i users return resolve this roomsState i id else generate a new room id const newID uuidv this roomsState push id newID users return resolve newID module exports Room NOTE Making use of an array to manage the rooms state is obviously not the best way to do so Imagine having thousands of rooms in your application and you have to loop through each room for each join request It would execute at O n For the purpose of this tutorial we will stick to this approach We d add another method to the Room class leaveRoom to reduce the number of users in a particular room room jsclass Room constructor joinRoom leaveRoom id this roomsState this roomsState filter room gt if room id id if room users return false else room users return true module exports Room The leaveRoom method takes a room ID and loops through the array of rooms to find if any of the rooms match the ID provided in the argument If it finds the matching room it checks if the user in the room is one so as to delete that particular room state If the user in the room is greater than the leaveRoom method just deducts the number of users in that room by one Finally our room js code should be similar to this room jsconst v uuidv require uuid the maximum number of people allowed in a roomconst ROOM MAX CAPACITY class Room constructor this roomsState joinRoom return new Promise resolve gt for let i i lt this roomsState length i if this roomsState i users lt ROOM MAX CAPACITY this roomsState i users return resolve this roomsState i id const newID uuidv this roomsState push id newID users return resolve newID leaveRoom id this roomsState this roomsState filter room gt if room id id if room users return false else room users return true module exports Room Joining and leaving the rooms To create different channels for users in our chat application we would be creating rooms for them socket io allows us to create arbitrary channels that sockets can join and leave It can be used to broadcast events to a subset of clients source To join a room we would join a room with a unique room ID io on connection socket gt join a room socket join some room id socket to some room id emit some event In our server application once a new users join the connection the Room joinRoom returns a unique ID which is our unique room ID So we can join and leave room in our rooms as follow app jsio on connection async socket gt const roomID await room joinRoom join room socket join roomID socket on disconnect gt leave room room leaveRoom roomID Sending and receiving messagesNow we d move back to our client side code to emit events for messages sent from the client And also listen to message events coming from the server and write that message to our chatbox main jssocket on receive message message gt createMessage message sendButton addEventListener click gt if textBox value socket emit send message textBox value createMessage textBox value true textBox value NOTE In our chat application we directly add the message from user to the chatbox without confirming if the message is received by the socket server This is not usually the case Then on our express application app jsio on connection async socket gt const roomID await room joinRoom join room socket join roomID socket on send message message gt socket to roomID emit receive message message socket on disconnect gt leave room room leaveRoom roomID Making our express application code look like this finally app jsconst http require http const Server require socket io const express require express const path require path const Room require room const app express app use express static path join dirname public const server http createServer app const io new Server server const room new Room io on connection async socket gt const roomID await room joinRoom join room socket join roomID socket on send message message gt socket to roomID emit receive message message socket on disconnect gt leave room room leaveRoom roomID server on error err gt console log Error opening server server listen gt console log Server working on port And our client side JavaScript looking like this main jsconst messageBox document querySelector messages const textBox document querySelector input const sendButton document querySelector button function createMessage text ownMessage false const messageElement document createElement div messageElement className chat message const subMesssageElement document createElement div subMesssageElement className px py rounded lg inline block rounded bl none bg gray text gray if ownMessage subMesssageElement className float right bg blue text white subMesssageElement innerText text messageElement appendChild subMesssageElement messageBox appendChild messageElement const socket io socket on connection socket gt console log socket id socket on receive message message gt createMessage message sendButton addEventListener click gt if textBox value socket emit send message textBox value createMessage textBox value true textBox value Testing our chat appTo text our chat app we will open four different browsers to confirm that two rooms are created ConclusionIf you see this it means that we read thus far and probably have the chat app running on our machine You can find the code from this article in this GitHub repository To include more challenges these are features you can include in the chat applicationInform users if people left or joined the roomRefactor the rooms state array to a more efficient data structureAllow pairing based on topic selection You d need to configure this in the Room object To read more about socket io you can visit the official documentation If you enjoy reading this article you can consider buying me a coffee 2022-04-17 22:19:09
海外TECH DEV Community Soft delete cascade in PostgreSQL🐘 and YugabyteDB🚀 https://dev.to/yugabyte/soft-delete-cascade-in-postgresql-and-yugabytedb-166n Soft delete cascade in PostgreSQLand YugabyteDBThis is a quick example to answer This remark about soft deletes Kelly Sommers kellabyte An interesting RDBMS feature would be cascading soft deletes AM Apr I don t know which database Kelly Sommers uses but PostgreSQL has many features that combined help implementing this data processing logic in a declarative way I know people don t like to put code in the databases but this is not business logic This is pure data logic implementing soft deletes SQL has huge benefit for this it is a declarative language You declare it once test it and you are done No need for additional code or additional tests I ve run this on YugabyteDB to verify that it works the same as in PostgreSQL Of course no suprise YugabyteDB re uses the postgres SQL processing layer for the best compatibility TablesHere is the parent table which has a parent deleted timestamp set to the date of deletion The default infinity is for valid records This column is part of the primary key because there may be multiple deletion for the same parent id But only one valid CREATE TABLE parent parent id int parent deleted timestamptz default infinity primary key parent id parent deleted The child table inherits the parent primary key and adds a child number to it as its primary key The foreign key is declared with on update cascade as the soft deletes will be cascaded as updates to this primary key CREATE TABLE child parent id int parent deleted timestamptz default infinity child number int primary key parent id parent deleted child number foreign key parent id parent deleted references parent parent id parent deleted on update cascade ViewsTables could be sufficient But the beauty of SQL is the logical independence I want to query my tables from the application or by the user without caring about the soft delete implementation I declare views for that The application will query valid parent and valid child to see the current versions filtering out the soft deleted rows create view valid parent as select parent id from parent where parent deleted gt now create view valid child as select parent id child number from child where parent deleted gt now Thanks to re using the primary key there is no need to join the tables there This is the right choice when deletes are rare the cascading update overhead is acceptable but selects are frequent And people tend to think that joins don t scale ProcedureI want to encapsulate this logic in the database and create a procedure to do be called for this soft deletion create procedure soft delete parent id int as SQL update parentset parent deleted now where parent id id SQL language sql I ll show an alternative later if you don t like stored procedures But personally I like this procedure encapsulation because the semantic is clear the application calls a specific procedure DataI m inserting few rows there I m inserting valid rows and insert them though the view because a view is a virtual table with all DML allowed The default infinity value is set automatically insert into valid parent select n from generate series n insert into valid child select parent id n from valid parent generate series n Here is a screenshot from my test You can easily reproduce it did you try the YugabyteDB managed free tier TestWhen you implement data logic in SQL a simple unit test is usually sufficient because the database takes care of all multi user consistency select from valid parent select from valid child This shows only the valid rows I call the procedure to soft delete one parent call soft delete parent When querying the views the rows have been virtually deleted select from valid parent select from valid child Here is the result In the tables behind the views we can see all the rows with the soft deleted ones yugabyte select from parent parent id parent deleted infinity infinity rows yugabyte select from child parent id parent deleted child number infinity infinity infinity infinity rows Note that with GRANT and REVOKE you can give access to the views only or to these tables And revoke the right to hard delete RuleYou can make this completely transparent so that users don t have to call the procedure but simply run DELETE on the view with a DO INSTEAD code create or replace rule soft delete parent as on delete to valid parent do insteadupdate parentset parent deleted now where parent id old parent id This is simple Now any delete will actually do a soft delete This looks great as the application is just interacting with the standard SQL API SELECT INSERT UPDATE DELETE And it comes handy when the application cannot be modified But for better code quality I prefer a procedure so that the application developer knows what she does my procedure name is explicit about soft deletes You can also see that this RULE is not transparent in its output showing DELETE PostgreSQL compatibleThis technique is easy on PostgreSQL and PostgreSQL compatible databases which re use the PostgreSQL open source code like YugabyteDB Here is the list of SQL features that makes it easy declarative and transparent SQL FeaturePostgreSQLYugabyteDB🪳CockroachDBOraclecomposite PKdefault infinity on update cascade stored procedureinsert into viewrule instead of viewgrant revoke Temporal Validity is an alternative Triggers and deferred constraints may be an alternative Displayed as This is where having all PostgreSQL features in YugabyteDB makes it the right solution for many enterprise applications Even when you don t want to put business logic into the database there is one day where you will need a stored procedure triggers rule or any of those modern SQL features that have proven their value on monolithic databases and are now available in distributed SQL 2022-04-17 22:15:56
海外TECH DEV Community Proper test 2 https://dev.to/bhaveesarna/proper-test-2-243c content 2022-04-17 22:13:41
金融 ニュース - 保険市場TIMES 三井住友海上、好きなカード付帯保険を選択できる「選べる無料保険」開始 https://www.hokende.com/news/blog/entry/2022/04/18/080000 三井住友海上、好きなカード付帯保険を選択できる「選べる無料保険」開始「選べる無料保険」月日より開始三井住友海上火災保険株式会社以下、三井住友海上は、三井住友カード株式会社とともに、ニーズに合わせて好きな保険が選択できるカード付帯保険「選べる無料保険」を年月日より開始した。 2022-04-18 08:00:00
北海道 北海道新聞 大リーグ、鈴木が4号ソロ 開幕から8試合連続安打 https://www.hokkaido-np.co.jp/article/670755/ 大リーグ 2022-04-18 07:28:00
北海道 北海道新聞 「北斗星」ゲストハウス 鉄道ファンが宿泊しアドバイス 「走行音聞きたい」「防犯強化を」 https://www.hokkaido-np.co.jp/article/670666/ 寝台特急 2022-04-18 07:22:02
北海道 北海道新聞 <社説>北電泊停止10年 原発担える組織なのか https://www.hokkaido-np.co.jp/article/670713/ 北海道電力 2022-04-18 07:16:07
北海道 北海道新聞 <社説>日本のEV戦略 総力挙げて巻き返しを https://www.hokkaido-np.co.jp/article/670712/ 巻き返し 2022-04-18 07:16:04
北海道 北海道新聞 白老の鳥インフル 振興局が対策会議 道、業者向けに相談窓口 https://www.hokkaido-np.co.jp/article/670753/ 鳥インフルエンザ 2022-04-18 07:02:00
ビジネス 東洋経済オンライン 日経平均は5月に向け再上昇の可能性が出てきた 「3つのリスク」があっても相場は意外に堅調? | 市場観測 | 東洋経済オンライン https://toyokeizai.net/articles/-/582638?utm_source=rss&utm_medium=http&utm_campaign=link_back 日経平均 2022-04-18 07:30:00
ビジネス プレジデントオンライン 放置すると本格的な不登校に…子どもの「おなかが痛い」に潜むメンタル不調の兆候 - 子がますます相談しにくくなる「親が言ってはいけない」NGワード https://president.jp/articles/-/56664 精神科医 2022-04-18 08:00:00
ビジネス プレジデントオンライン 放置すると本格的な不登校に…子どもの「おなかが痛い」に潜むメンタル不調の兆候 - 子がますます相談しにくくなる「親が言ってはいけない」NGワード https://president.jp/articles/-/56394 精神科医 2022-04-18 08:00:00
IT 週刊アスキー 株式会社Agoop、ビジネスを加速させる人流マーケティングツール「マチレポ」を提供開始 https://weekly.ascii.jp/elem/000/004/088/4088952/ 提供開始 2022-04-18 07:30:00
海外TECH reddit [Post Game Thread] Light That Baby Up!! The Angels win the series finale and take 3 out of 4 from the Rangers in Arlington! https://www.reddit.com/r/angelsbaseball/comments/u5xece/post_game_thread_light_that_baby_up_the_angels/ Post Game Thread Light That Baby Up The Angels win the series finale and take out of from the Rangers in Arlington The Angels record improves to extending their win streak to games submitted by u xThe Legend Killerx to r angelsbaseball link comments 2022-04-17 22:03:12
海外TECH reddit [Highlight] Jayson Tatum wins game 1 for the Boston Celtics https://www.reddit.com/r/nba/comments/u5xgxi/highlight_jayson_tatum_wins_game_1_for_the_boston/ Highlight Jayson Tatum wins game for the Boston Celtics submitted by u fbreaker to r nba link comments 2022-04-17 22:06:36
海外TECH reddit Cloud9 vs. Evil Geniuses / LCS 2022 Spring Playoffs - Losers' Bracket Round 2 / Post-Match Discussion https://www.reddit.com/r/leagueoflegends/comments/u5xcp1/cloud9_vs_evil_geniuses_lcs_2022_spring_playoffs/ Cloud vs Evil Geniuses LCS Spring Playoffs Losers x Bracket Round Post Match DiscussionLCS SPRING PLAYOFFS Official page Leaguepedia Liquipedia Eventvods com New to LoL Evil Geniuses Cloud EG Leaguepedia Liquipedia Website Twitter Facebook YouTube C Leaguepedia Liquipedia Website Twitter Facebook YouTube Subreddit MATCH EG vs C Winner Evil Geniuses in m Bans Bans G K T D B EG Gnar viktor ahri veigar aatrox k H H B C leblanc nautilus twisted fate leona rakan k I M O O E EG vs C Impact ornn TOP jayce Summit Inspired nocturne JNG lee sin Blaber jojopyun ryze MID akali Fudge Danny zeri BOT caitlyn Berserker Vulcan yuumi SUP lux Isles MATCH EG vs C Winner Evil Geniuses in m Bans Bans G K T D B EG gnar ahri caitlyn jayce volibear k H H B C leblanc nautilus lee sin yuumi rakan k O M I EG vs C Impact ornn TOP camille Summit Inspired jarvan IV JNG trundle Blaber jojopyun viktor MID corki Fudge Danny zeri BOT jinx Berserker Vulcan karma SUP tahmKench Isles MATCH EG vs C Winner Evil Geniuses in m Bans Bans G K T D B EG gnar ahri caitlyn volibear aatrox k H I I C leblanc lee sin nautilus ornn yuumi k M C B EG vs C Impact gragas TOP gwen Summit Inspired nocturne JNG jarvan IV Blaber jojopyun ryze MID twisted fate Fudge Danny zeri BOT lucian Berserker Vulcan alistar SUP nami Isles This thread was created by the Post Match Team submitted by u TomShoe to r leagueoflegends link comments 2022-04-17 22:01:01

コメント

このブログの人気の投稿

投稿時間: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件)