Skip to content

Instantly share code, notes, and snippets.

View kessler's full-sized 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 March 23, 2021 13:18
consume browser readable stream as async iterator
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 January 1, 2019 13:46
get notified when a command completes on osx
#!/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 / node_timers_example1.js
Created July 4, 2014 15:00
simple node.js timers examples
setTimeout(function() {
console.log('queue a print AFTER a second')
}, 1000)
setInterval(function() {
console.log('queue a print EVERY second')
}, 1000)
setImmediate(function() {
console.log('queue a print in the next event loop tick but after IO tasks are done')
@kessler
kessler / async_recursion_example.js
Created July 4, 2014 15:07
async recursion example
var count = 0
var countWithDelay = 0
function recurse() {
console.log('recurse: %d', count)
if (count++ === 100) return
setImmediate(recurse)
}
@kessler
kessler / mochaExample.js
Last active February 2, 2018 01:17
empty test
var expect = require('chai').expect
var targetFactory = require('../target')
describe('testing targets', function () {
var target
it('does something sync', function () {
expect(target()).to.equal('123')
})
@kessler
kessler / change.sh
Created December 19, 2017 00:49
change ebs delete on termination behavior
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 December 18, 2017 23:36
format javascript date to pg timestamp with timezone
moment.utc(new Date()).format('YYYY-MM-DDTHH:mm:ss.SSSSSSSSS[Z]')
@kessler
kessler / sub
Last active September 14, 2017 21:42
launch sublime text from terminal with current directory or with argument
#!/bin/sh
sub="/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
target=$1
if [[ -z $target ]]
then
target=$(pwd)
fi
@kessler
kessler / browserifyMiddleware.js
Created April 19, 2017 01:54
browserify middleware transform example
'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 February 21, 2017 18:35
string length is broken
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😀', '😀'))