Skip to content

Instantly share code, notes, and snippets.

from functools import wraps
def memoize(f):
cache = {}
kwargs_mark = object()
@wraps(f)
def memoized(*args, **kwargs):
key = args + (kwargs_mark,) + tuple(sorted(kwargs.items()))
try:
@shmatov
shmatov / thumb.sh
Created January 7, 2014 16:30
GraphicsMagick thumbnail.
gm convert original.jpg -thumbnail 200x200^ -gravity center -extent 200x200 +profile "*" thumbnail.jpg
grammar MathExpression;
INT : [0-9]+;
DOUBLE : [0-9]+'.'[0-9]+;
PI : 'pi';
E : 'e';
POW : '^';
WS : [ \t\r\n]+ -> skip;
ID : [a-zA-Z_][a-zA-Z_0-9]*;
PLUS : '+';
@shmatov
shmatov / client.hs
Last active December 18, 2015 01:39
import Prelude hiding (catch)
import Network
import Network.Socket
import System.IO
import Control.Exception
import Control.Concurrent
main :: IO ()
main = withSocketsDo $ do
addrInfos <- getAddrInfo Nothing (Just "localhost") (Just "1337")
[core]
autocrlf = input
safecrlf = true
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
@shmatov
shmatov / deploy.rake
Created November 15, 2012 13:17
rails + mina + unicorn
# lib/tasks/deploy.rake
namespace :deploy do
desc 'Deploy to staging environment'
task :staging do
exec 'mina deploy -f config/deploy/staging.rb'
end
end
@shmatov
shmatov / .bash_prompt
Last active January 20, 2020 10:49
Bash prompt with rvm, nvm, virtualenv and git integration.
function __git_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo " ↺ "
}
function __git_branch {
__git_ps1 "%s"
}
function __my_rvm_ruby_version {