Instantly share code, notes, and snippets.
🐿️
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.
- Oxford, UK
- in/ryasmi
ryasmi /_setGlobalLogLevel.md
Last activeDecember 10, 2020 18:13
A function to set the global log level in Node/Browser.ryasmi /testRunner.js
CreatedAugust 20, 2018 11:40
Starting a potential test runner that doesn't provide an opinionated assertion library. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
createRunner=()=>{ | |
constbeforeAlls=[]; | |
constafterAlls=[]; | |
constbeforeEaches=[]; | |
constafterEaches=[]; | |
consttests=[]; | |
consttest=(description,process)=>{ | |
tests.push({ | |
description, |
ryasmi /code-habit-const-functions-1.js
Last activeAugust 7, 2018 16:10
Code Habit - Const Functions This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
// 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); |
ryasmi /js-mushroom-episode-4-typescript.ts
Last activeJuly 17, 2018 14:24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
import*aslodashfrom'lodash'; | |
import*asmomentfrom'moment'; | |
// tslint:disable-next-line:no-class | |
classA{ | |
publicconstructor(){return;} | |
} | |
interfaceB{ | |
readonlyc:number; |
ryasmi /js-mushroom-episode-3-servers.md
Last activeMarch 23, 2018 16:55
JS Mushroom Episode 3 - Servers (2018-03-23)ryasmi /async-render-1.js
CreatedMarch 3, 2018 14:19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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 /js-mushroom-episode-1-array-functions.js
Last activeFebruary 23, 2018 15:44
JS Mushroom Episode 1 - Array Functions (2018-02-09) This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
// 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 /js-mushroom-episode-2-promises.js
Last activeFebruary 23, 2018 15:44
JS Mushroom Episode 2 - Promises (2018-02-23) This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
// 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 /renameAll.sh
CreatedFebruary 23, 2018 11:10
Script to rename all files recursively in a directory on a Mac. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
forfilein$(find src -name'*.js');do mv"$file""${file%.js}.ts";done |
ryasmi /iriRegex.js
Last activeJanuary 7, 2018 21:51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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