Skip to content

Instantly share code, notes, and snippets.

View franher's full-sized avatar
🪴

Fran Herrero franher

🪴
View GitHub Profile
@franher
franher / license-adder.sh
Created November 23, 2017 09:19
Add a license header for all the js files under ./src folder (recursively)
#!/bin/bash
for i in $(find ./src -name '*.js' );
do
if ! grep -q Copyright "$i"
then
echo "$i"
cat license-header.txt "$i" > "$i".new && mv "$i".new "$i"
fi
done
@franher
franher / fs-stat-custom-promisify.js
Created June 18, 2017 15:33
Custom fs.stat promisify as identity function
const util = require('util');
const fs = require('fs');
/**
* identity function f(v) -> v
* Using ES6 Promise
*
* async/await approach:
* async function identityAsync(v) {
* return v;
@franher
franher / fs-read-promisify-test.js
Created June 18, 2017 14:02
fs.read promisified version
const { promisify } = require('util');
const { read, open } = require('fs');
const readPromisified = promisify(read);
const openPromisified = promisify(open);
const expected = Buffer.from('xyz\n');
const buffer = Buffer.allocUnsafe(expected.length);
openPromisified('x.txt', 'r').then(fd => {