Skip to content

Instantly share code, notes, and snippets.

View raine's full-sized avatar

Raine Virta raine

View GitHub Profile
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));
}
}());

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');
@raine
raine / ramda
Last active May 4, 2020 12:14
Browse Ramda documentation in Terminal
#!/usr/bin/env bash
# Browse Ramda documentation in Terminal
# Requires jq and a tool such as fzf or peco for interactive filtering
LATEST="http://raine.github.io/ramda-json-docs/latest.json"
DOCS_URL="http://ramdajs.com/docs/"
json=$(curl -s $LATEST)
functions=$(echo "$json" | jq -r '.[] | if .sig and (.sig | length > 0) then .name + " :: " + .sig else .name end')
@raine
raine / tmux-zoom-out-vim
Last active May 3, 2020 12:42
tmux+vim: zoom into pane and resize windows to equal size in vim with CTRL-W =
#!/usr/bin/env bash
set -e
cmd="$(tmux display -p '#{pane_current_command}')"
cmd="$(basename "${cmd,,*}")"
tmux resize-pane -Z
if [ "${cmd%m}" = "vi" ]; then
sleep 0.1
@raine
raine / README.md
Created February 18, 2015 12:57
git alias for removing merged branches
git config --global alias.remove-merged-branches '!git branch --merged | grep -v "\*" | xargs -n 1 git branch -d'
```sh
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@paf31
paf31 / 24days.md
Last active August 8, 2023 05:53
24 Days of PureScript

This blog post series has moved here.

You might also be interested in the 2016 version.

Install

npm install funcoffee

Require

require('funcoffee').expose global
@branneman
branneman / better-nodejs-require-paths.md
Last active April 25, 2024 13:21
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@fritzy
fritzy / pushmaxlist.lua
Last active April 19, 2017 21:07
Appending to a Redis List, deleting entries to the left past a maximum size.
--EVAL "this script" 1 key_name new_item max_size
local key = KEYS[1];
local item, max = unpack(ARGV);
redis.call('RPUSH', key, item);
redis.call('LTRIM', key, -max, -1);