Skip to content

Instantly share code, notes, and snippets.

View julien-f's full-sized avatar

Julien Fontanet julien-f

View GitHub Profile
@julien-f
julien-f / example.js
Last active April 12, 2018 17:41
Async generator from generator
const makeAsyncGenerator = require('./make-async-generator')
const f = makeAsyncGenerator(function * () {
yield 'foo'
const value = yield Promise.resolve('bar') // yield promises to await them
yield value
try {
yield Promise.reject('baz')
} catch (value) {
yield value
on_exit_commands=''
on_exit () {
on_exit_commands="$1; $on_exit_commands"
}
trap 'eval "$on_exit_commands"' EXIT
text='foo bar'
on_exit 'echo "$text"'
on_exit 'echo baz'
@julien-f
julien-f / async.js
Last active February 15, 2018 00:08
// Composable, lazy task operation constructor
class Async {
constructor(resolver) {
this._resolver = resolver
}
then(onFulfilment, onRejection) {
return new SyncAsyncPromise(this._resolver).then(onFulfilment, onRejection)
}

Semaine courante

2018-W18

  1. ???
  2. tacos
  3. tagliatelles, truite fumée et brocoli

2018-W17

// https://gist.github.com/yelouafi/556e5159e869952335e01f6b473c4ec1
class Failure {
constructor (pos, expected) {
this.expected = expected
this.pos = pos
}
get value () {
throw new Error(
# choice prompt choice...
choice() {
local answer i
echo "$1"
shift
i=1
for choice
do
import classNames from 'classnames'
import isEmpty from 'lodash/isEmpty'
import PropTypes from 'prop-types'
import React from 'react'
import ReactSelect from 'react-select'
import uncontrollableInput from 'uncontrollable-input'
import {
AutoSizer,
CellMeasurer,
CellMeasurerCache,
@julien-f
julien-f / index.sh
Last active December 20, 2017 12:47
Run a command in parallel in POSIX shell (compatible Bash)
# run_parallel <n> <command> <args>
run_parallel() (
local fifo i n cmd arg x
# Create queue
fifo=$(mktemp -u)
mkfifo "$fifo"
exec 179<> "$fifo"
rm -f "$fifo"
@julien-f
julien-f / download.js
Last active November 21, 2018 13:13
Humble Bundle − Download all
const { basename, resolve } = require('path')
const { createWriteStream, existsSync } = require('fs')
const { get } = require('https')
const { parse } = require('url')
require(resolve(process.argv[2])).forEach(url => {
const base = basename(parse(url).pathname)
if (existsSync(base)) {
return
}
get(url, res => {
_ansi_mode() {
printf '\033[%sm' "$1"
}
_style() {
local arg
if [ $# -eq 0 ]
then
set -- reset