This file contains hidden or 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
/** | |
* The vanilla javascript way of implementing such a functionality would be to use | |
* he window's matchMedia function. The function takes a string query and | |
* returns a MediaQueryList that can be used to get the current result of the | |
* query and listen to changes of the media query. | |
*/ | |
const mediaQueryList = window.matchMedia(`(min-width: 767px)`); | |
console.log(mediaQueryList.matches); // true or false |
This file contains hidden or 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
/** | |
* Creates a hash for a value using the SHA-256 algorithm. Returns a promise. | |
* | |
* Use crypto.createHash() to create a Hash object with the appropriate | |
* algorithm. | |
* | |
* Use hash.update() to add the data from val to the Hash, hash.digest() to | |
* calculate the digest of the data. | |
* | |
* Use setTimeout() to prevent blocking on a long operation. Return a Promise to |
This file contains hidden or 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
function fizzBuzz(n: number) { | |
return ( | |
{ true: '', false: 'Fizz' }[`${n % 3 === 0}`] + | |
{ true: '', false: 'Buzz' }[`${n % 5 === 0}`] || | |
n.toString() | |
) | |
} | |
function fizzBuzzFunctional(n: number) { | |
let test = |
This file contains hidden or 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
/** | |
* Workaround to set up a handshake, lazy-loading by resolving a promise | |
*/ | |
let settleReadyState = {} | |
let subprocess = {} | |
// following code outputs: Promise {<pending>} on console and sets | |
// settleReadyState = { resolve: ƒ, reject: ƒ} | |
// subprocess = {ready: Promise<pending>} |
This file contains hidden or 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
/** | |
* fibonacciGenerator.js | |
* tags: { JavaScript, Generator, Iterator } | |
*/ | |
function* fibonacciGenerator() { | |
var [prev, curr] = [0, 1] | |
while(true) { | |
[prev, curr] = [curr, prev + curr] | |
yield curr |
This file contains hidden or 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
@echo off | |
SET st3Path=C:\Program Files\Sublime Text 3\sublime_text.exe | |
rem add it for all file types | |
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f | |
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3" /t REG_EXPAND_SZ /v "Icon" /d "%st3Path%,0" /f | |
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 3\command" /t REG_SZ /v "" /d "%st3Path% \"%%1\"" /f | |
rem add it for folders | |
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3" /t REG_SZ /v "" /d "Open with Sublime Text 3" /f |
This file contains hidden or 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
#!/bin/bash | |
# Sometimes you need to move your existing git repository | |
# to a new remote repository (/new remote origin). | |
# Here are a simple and quick steps that does exactly this. | |
# | |
# Let's assume we call "old repo" the repository you wish | |
# to move, and "new repo" the one you wish to move to. | |
# | |
### Step 1. Make sure you have a local copy of all "old repo" | |
### branches and tags. |
This file contains hidden or 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
/* Return tuple types, with a nullable error component just like Go */ | |
/* meta: Typescript 3.9.5 */ | |
type Err = Error | null; | |
async function getUser(): Promise<[string, Err]> { | |
try { | |
const res = await fetch('/me'); | |
const data = await res.json(); | |
This file contains hidden or 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
/** | |
* getNumberOfDigits.js | |
* tags: { JavaScript, Array, RxJS } | |
*/ | |
const { interval } = Rx; | |
const { scan, pluck, groupBy } = RxOperators; | |
interval(1000).pipe( | |
scan( |
This file contains hidden or 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
echo-server-epoll | |
echo-server-poll | |
talk | |
talk.dSYM |