Skip to content

Instantly share code, notes, and snippets.

View raine's full-sized avatar

Raine Virta raine

View GitHub Profile
@raine
raine / ws
Created September 23, 2015 09:50
#!/bin/sh
# Find files with trailing whitespace
for FILE in `exec git diff --name-only HEAD -- | sed '/^[+-]/d' | sed -E 's/:[0-9]+:.*//' | uniq` ; do
sed -i '' -E 's/[[:space:]]*$//' "$FILE"
done
@raine
raine / index.js
Last active September 23, 2015 05:58
const { Future, IO } = require('ramda-fantasy');
const join2 = curryN(2, require('path').join);
const npa = require('npm-package-arg');
const ALIAS = /:([^!]+)/;
const EXTEND = /!$/;
const parseAlias = pipe(
S.match(ALIAS), chain(nth(1)));
const parseExtend = pipe(
S.match(EXTEND), map(T));
@raine
raine / -
Last active September 11, 2015 11:48
~ ❯❯❯ cat ~/noderepl/myrepl.js
var repl = require('repl').start('> ');
require('repl.history')(repl, process.env.HOME + '/.node_history');
var R = repl.context.R = require('ramda');
R.functions(R).forEach(function(f) {
repl.context[f] = R[f];
});
repl.context.treis = require('treis');
const cachedReadFile = (function() {
const cache = new Map();
return (p) => {
if (cache.has(p)) return Promise.resolve(cache.get(p));
else return readFile(p).tap((file) => cache.set(p, file));
}
}());
require! ramda: {pipe, evolve, props, filter, join}
require! chalk: {grey, yellow, cyan, green, red}
color-status-code = ->
| it >= 500 => red it
| it >= 400 => yellow it
| it >= 300 => cyan it
| it >= 200 => green it
module.exports = pipe do
@raine
raine / index.js
Created June 26, 2015 10:38
requirebin sketch
var h = require('snabbdom/h');
var patch = require('snabbdom').init([]);
var container = document.getElementById('container');
var vnode = h('div#foo', {}, 'not id foo');
patch(container, vnode);
require! <[ watchify browserify gulp ]>
require! 'vinyl-source-stream': source
require! 'vinyl-buffer': buffer
require! 'gulp-util': gutil
require! 'liveify'
gulp.task \bundle !->
bundler = watchify browserify {} <<< watchify.args <<<
entries: ['./src/index.ls']
debug: true
@raine
raine / _post.md
Last active July 18, 2022 13:44
Parsing and rendering tori.fi categories with Acorn, archy and Ramda

Parsing and rendering tori.fi categories with Acorn, archy and Ramda

by @rane

Tori.fi, a Finnish online marketplace based on blocket.se, has a category selection input that dynamically reveals sub-categories as user selects them.

It works like this:

@raine
raine / .zshrc
Last active August 29, 2015 14:22
gist-clone
gist-clone() {
gist_id=`echo "$1" | sed -e 's/.*\///g'`
git clone git@gist.github.com:/$gist_id.git $2
}

reading a file with ISO-8859-1 encoding in node.js

npm install iconv-lite
var fs = require('fs');
var iconv = require('iconv-lite');
iconv.decode(fs.readFileSync('file.txt'), 'iso-8859-1');