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
async function main() { | |
const { body } = await fetch('https://jsonplaceholder.typicode.com/photos') | |
const streamIterator = new StreamChunkIterator(body.getReader()) | |
for await (const chunk of streamIterator) { | |
console.log(chunk) | |
} | |
console.log('Voilà!') | |
} |
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
#!/bin/bash | |
# usage: cmd | osa_notify.sh | |
/usr/bin/osascript 3<&0 <<'APPLESCRIPT' | |
on run argv | |
set stdin to do shell script "cat 0<&3" | |
display notification stdin with title "osa_notify" sound name "Default" | |
return stdin | |
end run | |
APPLESCRIPT |
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
aws ec2 modify-instance-attribute --profile [profile] --region [region] --instance-id [instanceid] --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\":false}}]" |
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
moment.utc(new Date()).format('YYYY-MM-DDTHH:mm:ss.SSSSSSSSS[Z]') |
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
'use strict' | |
const express = require('express') | |
const browserifyMiddleware = require('browserify-middleware') | |
const path = require('path') | |
browserifyMiddleware.settings('transform', [ | |
[{ presets: ['es2015', 'react', 'stage-2']}, 'babelify'] | |
]) |
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
const loEndsWith = require('lodash.endsWith') | |
console.log('naive:', endsWith('asdsds😀', '?')) | |
console.log('naive:', endsWith('asdsds😀?', '?')) | |
console.log('naive:', endsWith('asdsds😀', '😀')) | |
console.log('mozilla polyfill:', mozEndsWith('asdsds😀', '?')) | |
console.log('mozilla polyfill:', mozEndsWith('asdsds😀?', '?')) | |
console.log('mozilla polyfill:', mozEndsWith('asdsds😀', '😀')) |
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
'use strict' | |
const size = 130000 | |
let arr1 = new Array(size) | |
let arr2 = new Array(size) | |
for (let i = 0; i < size; i++) { | |
arr1[i] = i + '' | |
arr2[i] = i + '' |
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
'use strict' | |
const size = 10000000 | |
let arr = new Array(size) | |
for (let i = 0; i < size; i++) { | |
arr[i] = i + '' | |
} |
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
'use strict' | |
const _ = require('lodash') | |
function intersection(source, target) { | |
let result = [] | |
for (let i = source.length - 1; i >= 0; i--) { | |
let value = source[i] | |
if (target.indexOf(value) > - 1) { | |
result.push(value) |
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
function toBits(a, res) { | |
if (a === 0) return | |
let r = a % 2 | |
if (r === 0) { res.push(0) } else { res.push(1) } | |
toBits(Math.floor(a / 2), res) | |
} | |
function dec2bin(dec){ | |
return (dec >>> 0).toString(2); | |
} |
NewerOlder