Skip to content

Instantly share code, notes, and snippets.

View lukaszx0's full-sized avatar

Lukasz Strzalkowski lukaszx0

  • Column
View GitHub Profile
package utils
import (
"net/http"
"strings"
"github.com/golang/glog"
)
func AllowCORS(h http.Handler) http.Handler {
@lukaszx0
lukaszx0 / tokenable.rb
Created January 28, 2018 23:12
Tokenable concern for Rails models
# 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 |
@lukaszx0
lukaszx0 / pid2port.sh
Last active February 1, 2016 22:50
pid to port
#!/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}'
}
@lukaszx0
lukaszx0 / subenc.sh
Created August 31, 2015 13:26
Subtitles encoding converter
#/bin/bash
ICONV_CHARSET="$(enca -i -L polish $1)"
iconv -f $ICONV_CHARSET -t utf-8 < $1 > $2
@lukaszx0
lukaszx0 / container.rb
Created July 27, 2015 11:30
container class
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)
@lukaszx0
lukaszx0 / README.md
Last active August 29, 2015 14:21
kwargs polyfill

kwargs

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.

Examples

Required args

def foobar(args = {})
perl -nle 'BEGIN { $l = 0; $SIG{ALRM} = sub { print $l; $l = 0; alarm(1) }; alarm(1) }; $l += 1'
@lukaszx0
lukaszx0 / ohhai.txt
Created June 19, 2014 16:56
Bundler gist
Hello Bundler doc reader!