Skip to content

Instantly share code, notes, and snippets.

@enil
enil / ncat_http_server.sh
Last active October 5, 2016 06:06
Use ncat as an HTTP server
ncat -k -l 4000 -o /dev/stderr -c 'echo "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"'
@enil
enil / optional_map.kt
Created September 28, 2016 08:06
Map an optional value in kotlin
fun <T,U> T?.map(mapping: (T) -> U) = when (this) {
null -> null
else -> mapping(this)
}
@enil
enil / goenv.sh
Created July 29, 2016 10:49
Bash/ZSH shell for setting $GOPATH to its directory
if [ "$1" = "--reset" ]; then
if [ -n "$OLD_GOPATH" ]; then
export GOPATH="$OLD_GOPATH"
unset OLD_GOPATH
fi
return
fi
if [ -n "$BASH" ]; then
script_path=${BASH_SOURCE[0]}
@enil
enil / kv_for_erl.exs
Created July 21, 2016 07:00
Convert keyword list for erlang libraries
# convert every (binary) string value in the keyword list to a character list
args |> Enum.map(fn
v when is_binary(v) -> to_charlist(v)
{k, v} when is_binary(v) -> {k, to_charlist(v)}
any -> any
end)
@enil
enil / unfold-fib.ex
Created July 19, 2016 11:22
Implementing a fibonacci stream with Stream.unfold
Stream.unfold({0, 1}, fn {x, y} -> {x, {y, x + y}} end)
confirm() {
while true; do
read -p "$@" -n 1 answer
echo
case "$answer" in
[yY]) return 0 ;;
[nN]) return 1 ;;
esac
done
}
@enil
enil / .estlintrc.yaml
Created May 22, 2016 16:01
Personal ESLint configuration for node/ES6
---
parser: babel-eslint
parserOptions:
ecmaVersion: 6
sourceType: module
ecmaFeatures:
impliedStrict: true
environment:
node: true
rules:
@enil
enil / lkill.sh
Created April 25, 2016 11:47
Kill the process listening at a specific port
#!/bin/bash
print_error() {
1>&2 echo "$@"
}
fail() {
if [[ $# -gt 0 ]]; then
print_error "$@"
fi
@enil
enil / async-promise-test.js
Created April 22, 2016 10:20
Playing around with async and promises in Babel
function directly(value) {
return Promise.resolve(value);
}
function later(value) {
return new Promise(resolve => {
setTimeout(() => resolve(value), 500);
});
}
@enil
enil / Makefile
Last active April 12, 2016 07:00
Makefile for checking out git submodules
GIT=git
GIT_SUBMODULES=$(shell sed -nE 's/path = +(.+)/\1\/.git/ p' .gitmodules | paste -s -)
.PHONY: all
all: $(GIT_SUBMODULES)
$(GIT_SUBMODULES): %/.git: .gitmodules
$(GIT) submodule init
$(GIT) submodule update $*
@touch $@