Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

View ryasmi's full-sized avatar
🐿️
Checks emails once per day Mon-Fri

Ryan Smith ryasmi

🐿️
Checks emails once per day Mon-Fri
Engineering Manager at LP.Helping people do something they love because a lack of passion has a lack of impact.
View GitHub Profile
@ryasmi
ryasmi /_setGlobalLogLevel.md
Last activeDecember 10, 2020 18:13
A function to set the global log level in Node/Browser.

In PM2 you can use thePM2time option to add timestamps to logs. In a Lambda, it automatically adds the timestamp to CloudWatch. I think the log level is also shown in CloudWatch. Ideally PM2 would output the level of the log too.

@ryasmi
ryasmi /testRunner.js
CreatedAugust 20, 2018 11:40
Starting a potential test runner that doesn't provide an opinionated assertion library.
createRunner=()=>{
constbeforeAlls=[];
constafterAlls=[];
constbeforeEaches=[];
constafterEaches=[];
consttests=[];
consttest=(description,process)=>{
tests.push({
description,
@ryasmi
ryasmi /code-habit-const-functions-1.js
Last activeAugust 7, 2018 16:10
Code Habit - Const Functions
// Preventing hoisting. We're used to reading top to bottom, so this can be quite confusing.
constresult=add(1,2);
functionadd(x,y){
returnx+y;
};
console.log(result);
import*aslodashfrom'lodash';
import*asmomentfrom'moment';
// tslint:disable-next-line:no-class
classA{
publicconstructor(){return;}
}
interfaceB{
readonlyc:number;
@ryasmi
ryasmi /js-mushroom-episode-3-servers.md
Last activeMarch 23, 2018 16:55
JS Mushroom Episode 3 - Servers (2018-03-23)

First of all, make sure you have Node installed on your computer, I'd recommend usingNVM. Then create a new folder and make a "index.js" file with the following contents.

consthttp=require('http');constserver=http.createServer((request,response)=>{response.end('hello');});server.listen(1337,()=>{
app=async({count,fraction})=>{
constseconds=Math.floor(count/fraction);
constdiv=document.createElement('div');
constspan=document.createElement('span');
span.innerText=`${seconds}.${count%fraction}`;
div.style.color='white'
div.appendChild(span);
returndiv;
};
client=()=>{
@ryasmi
ryasmi /js-mushroom-episode-1-array-functions.js
Last activeFebruary 23, 2018 15:44
JS Mushroom Episode 1 - Array Functions (2018-02-09)
// Using forEach.
[1,2,3].forEach((item,index,items)=>{
console.log('item',item);// Logs "1" for the first item, "2" for the second item, and "3" for the third item.
console.log('index',index);// Logs "0" for the first item, "1" for the second item, and "2" for the third item.
console.log('items',items);// Logs "[1,2,3]" to the console for every item.
});
// Using map to add one to each item in an array.
constplusOneItems=[1,2,3].map((item,index,items)=>{
returnitem+1;
@ryasmi
ryasmi /js-mushroom-episode-2-promises.js
Last activeFebruary 23, 2018 15:44
JS Mushroom Episode 2 - Promises (2018-02-23)
// Using resolved promises with the .then callback.
Promise.resolve('hello world').then((message)=>{
console.log(message);// Logs "hello world" in the console.
});
// Using rejected promises with the .catch callback.
Promise.reject('error message').catch((err)=>{
console.error(err);// Logs "error message" in the console.
});
@ryasmi
ryasmi /renameAll.sh
CreatedFebruary 23, 2018 11:10
Script to rename all files recursively in a directory on a Mac.
forfilein$(find src -name'*.js');do mv"$file""${file%.js}.ts";done
@ryasmi
ryasmi /iriRegex.js
Last activeJanuary 7, 2018 21:51
escapedChar=(char)=>{
return`\\${char}`;
}
normChars=`w_~!$&'()*+,;=:-`.split('').map(escapedChar).join('');
otherChars='\\u00A0-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF\\uFFEF-\\uFFFD';
allChars=`${normChars}${otherChars}`;
extChars=`(?:[${allChars}]|(?:\\%[a-f0-9][a-f0-9]))`;
capturePattern=(pattern)=>{
NewerOlder

[8]ページ先頭

©2009-2025 Movatter.jp