This is a simple hash extension which imitates behaviour of ruby's 2.1 keyword arguments. Check out examples below and spec file for sample usage.
def foobar(args = {})
package utils | |
import ( | |
"net/http" | |
"strings" | |
"github.com/golang/glog" | |
) | |
func AllowCORS(h http.Handler) http.Handler { |
# app/models/concerns/tokenable.rb | |
module Tokenable | |
extend ActiveSupport::Concern | |
included do | |
before_create :generate_token | |
end | |
protected |
class Hash | |
def flatten_with_dotted_keys(&block) | |
stack = [] | |
flattened = {} | |
flatten_dfs(self, stack, flattened, block) | |
flattened | |
end | |
private |
# Usage: | |
# 1) Ctr+S downloads page to ~/Desktop/books.html | |
# 2) Run script | |
# 3) Find your books in /tmp/humble_books | |
# 4) Read them | |
# 5) Profit | |
cat ~/Desktop/books.html | | |
grep "https://dl.humble.com" | | |
sed -n -E 's/.data-web\=\"(https://dl.humble.com/([.]+).([a-z]+)?["]+)./\1 \2 \3/p' | | |
sed 's/&/&/g' > /tmp/humble_books_list && cat /tmp/humble_books_list | |
#!/bin/bash | |
# Prints ports used by given process (PID) | |
# | |
# Usage: | |
# pid2port 123 | |
function pid2port() { | |
lsof -Pan -p $1 -i | awk '{print $1,$3,$4,$8,$9}' | |
} |
#/bin/bash | |
ICONV_CHARSET="$(enca -i -L polish $1)" | |
iconv -f $ICONV_CHARSET -t utf-8 < $1 > $2 |
class Container | |
SETTER_METHOD_REGEX = /^(?<name>\w+)=$/.freeze | |
def initialize(params = {}) | |
@registry = {} | |
@registry.merge(params.symbolize_keys) if params.present? | |
end | |
def method_missing(method_name, *args, &block) | |
matched = method_name.to_s.match(SETTER_METHOD_REGEX) |
perl -nle 'BEGIN { $l = 0; $SIG{ALRM} = sub { print $l; $l = 0; alarm(1) }; alarm(1) }; $l += 1' |
Hello Bundler doc reader! |