Skip to content

Instantly share code, notes, and snippets.

@enil
enil / nginxmodules.sh
Created August 26, 2015 09:07
List modules compiled into nginx
#!/bin/bash
nginx -V | tr [[:space:]] "\n" | grep -E '^--with-.+_module$' | awk -F- '{ print $NF }'
@enil
enil / minmax.rb
Created August 27, 2015 05:59
Keeping track of the minimum and maximum value easily
class MinMax
def initialize
@minmax = []
end
def <<(element)
@minmax = (@minmax + [element]).minmax
element
end
@enil
enil / install-ruby.sh
Created August 28, 2015 11:23
Install the Ruby version from .ruby-version if missing
rbenv versions --bar | grep -qx "$(cat .ruby-version)" || rbenv install "$(cat .ruby-version)"
@enil
enil / string_to_proc.rb
Created September 1, 2015 07:55
String#to_proc implementation to understand Symbol#to_proc
class String
def to_proc
proc { |target,*args| target.send(self, *args) }
end
end
[1,2,3,4].reduce(&'+')
@enil
enil / not_set.rb
Last active September 21, 2015 08:09
class NotSetError < StandardError; end
class NotSet < BasicObject
def initialize(target, location = ::Kernel.caller.first)
@location = location
@target = target
end
def self.[](target, location = ::Kernel.caller.first)
new(target, location)
@enil
enil / clear-pods
Created December 16, 2015 09:39
Because pods is whack…
#!/bin/bash
local_cache_dir=$PWD/Pods
global_cache_dir=$HOME/Library/Caches/CocoaPods
if [ -d $local_cache_dir ]; then
rm -rf $local_cache_dir
rm -rf $global_cache_dir
else
>&2 "No local Pods directory, are you in the right directory?"
@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 $@
@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 / 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 / .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: