Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Be well!

Yaniv Kessler kessler

:octocat:
Be well!
View GitHub Profile
@kessler
kessler / consume-browser-readable-stream-as-async-iterator.js
Last active Mar 23, 2021
consume browser readable stream as async iterator
View consume-browser-readable-stream-as-async-iterator.js
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à!')
}
@kessler
kessler / notify.sh
Created Jan 1, 2019
get notified when a command completes on osx
View notify.sh
#!/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
@kessler
kessler / change.sh
Created Dec 19, 2017
change ebs delete on termination behavior
View change.sh
aws ec2 modify-instance-attribute --profile [profile] --region [region] --instance-id [instanceid] --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\":false}}]"
@kessler
kessler / format.js
Created Dec 18, 2017
format javascript date to pg timestamp with timezone
View format.js
moment.utc(new Date()).format('YYYY-MM-DDTHH:mm:ss.SSSSSSSSS[Z]')
@kessler
kessler / browserifyMiddleware.js
Created Apr 19, 2017
browserify middleware transform example
View browserifyMiddleware.js
'use strict'
const express = require('express')
const browserifyMiddleware = require('browserify-middleware')
const path = require('path')
browserifyMiddleware.settings('transform', [
[{ presets: ['es2015', 'react', 'stage-2']}, 'babelify']
])
@kessler
kessler / endsWithTest.js
Created Feb 21, 2017
string length is broken
View endsWithTest.js
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😀', '😀'))
@kessler
kessler / shift_vs_pop.js
Created Jul 9, 2016
benchmark of shift vs pop with node.js
View shift_vs_pop.js
'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 + ''
@kessler
kessler / forward_vs_backward_for_loop.js
Last active Jul 9, 2016
benchmark of forward vs backward for loop with node.js
View forward_vs_backward_for_loop.js
'use strict'
const size = 10000000
let arr = new Array(size)
for (let i = 0; i < size; i++) {
arr[i] = i + ''
}
View lodash_vs_simple.js
'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)
View toBits.js
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);
}