Skip to content

Instantly share code, notes, and snippets.

View mrkschan's full-sized avatar
😀

KS Chan mrkschan

😀
View GitHub Profile
from datetime import datetime, timedelta
import functools
import pickle
def days_ago(days):
dt = datetime.now() - timedelta(days=days)
return dt.strftime('%y%m%s')
print pickle.dumps(functools.partial(days_ago, 1))
@mrkschan
mrkschan / gist:7942083
Created December 13, 2013 09:46
my vim statusline
" Taglist integration
let Tlist_Process_File_Always = 1
" statusline config
set laststatus=2
set statusline=
set statusline+=%< " cut at start
set statusline+=%f " relative path
set statusline+=\ -\ %{Tlist_Get_Tagname_By_Line()} " taglist
@mrkschan
mrkschan / gist:6936112
Created October 11, 2013 14:56
dynamic object in Python via type()
o = type('anonymous', (object,), {'attr_1': 'value_1', 'attr_2': 'value_2'})
print o.attr_1, o.attr_2
@mrkschan
mrkschan / git-graph
Created February 1, 2013 09:19
entire git graph from cli
#!/bin/bash
git log --graph --pretty="format:%C(yellow)%h%Cgreen%d%Creset %s %C(cyan) - %an, %Cred%ar%Creset"
{
'subtotal_price': Decimal('38.0'),
'buyer_accepts_marketing': True,
'shipping_lines': [{
'source': 'shopify',
'price': Decimal('10.0'),
'code': 'Standard Shipping',
'title': 'Standard Shipping'
}],
'cart_token': None,
# Fuck off httplib2 reporting failed SSL cert verification.
import httplib2
import certifi
httplib2.CA_CERTS = certifi.where()
@mrkschan
mrkschan / gist:4077171
Created November 15, 2012 07:15
vim smartindent config for Python
" Smart indenting for Python
autocmd FileType python set smartindent
autocmd FileType python set cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd FileType python set tabstop=4
autocmd FileType python set shiftwidth=4
autocmd FileType python set expandtab
@mrkschan
mrkschan / fakesmtp
Created October 3, 2012 09:22
A fake SMTP server (smtp-sink shortcut)
#!/usr/bin/env bash
sudo smtp-sink -R /tmp -u root -d "mail.%Y-%m-%dT%H%M." 127.0.0.1:25 1024
@mrkschan
mrkschan / gist:3522031
Last active October 9, 2015 14:27
bash completion for git, with files and directory
#!bash
#
# Enable file/directory completion for git.
#
# bashref - http://is.gd/PHQRX1
# bashlib - http://code.google.com/p/bash-completion-lib/
have git && {
_git_completion()
{
@mrkschan
mrkschan / urldecode.py
Created August 21, 2012 07:13
a shortcut program to decode URL
#!/usr/bin/env python
# Usage: urldecode.py url
import urllib
import sys
print urllib.unquote_plus(sys.argv[1])