Skip to content

Instantly share code, notes, and snippets.

View leepro's full-sized avatar
🏠
Working from home

DW Lee leepro

🏠
Working from home
View GitHub Profile
@leepro
leepro / bitsnoop_kr_show.py
Last active December 23, 2015 01:09
Get latest HANRel TV shows from bitsnoop.com.
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import requests, bs4, re
# <codecell>
re_date = re.compile(r'(?P<date>13[0-1]{1}[0-9]{1}[0-9]{1}[0-9]{1})')
@leepro
leepro / gist:7128223
Created October 23, 2013 22:48
Birthday Paradox
%pylab inline --no-import-all
import matplotlib.pyplot as plt
def prob_samebirthday(n):
prob_days = [ (1.0-(i/365.0)) for i in xrange(1,n+1) ]
return 100.0*(1.0-reduce(lambda x,y: x*y, prob_days))
def draw():
plt.figure()
plt.grid(True)
@leepro
leepro / gist:7596564
Last active December 29, 2015 01:58
git history by days
git log --date=iso --pretty=format:"%h|%an|%ad|%s" \
| awk '{ split($0,a,"|"); split(a[3],b," "); print b[1]; }' \
| uniq -c \
| awk '{ print $2,$1 }' \
| sort -r
@leepro
leepro / gist:7651250
Created November 26, 2013 00:13
git commit progress bars
#!/bin/sh
echo "================================"
echo "YYYY-MM-DD The number of commits"
echo "================================"
echo
git log --date=iso --pretty=format:"%h|%an|%ad|%s" | awk '{ split($0,a,"|"); split(a[3],b," "); print b[1]; }' | sort | uniq -c | python -c "import sys; print '\n'.join(map(lambda x:x[1]+' '+'*'*int(x[0])+' '+x[0], map(lambda x:x.strip().split(' '), sys.stdin.readlines())))" | sort -r
echo
@leepro
leepro / gist:7669110
Created November 27, 2013 01:06
Make a proxy for all methods of a class using metaclass.
from functools import wraps
class TraceMeta(type):
def __new__(meta, name, bases, dct):
for name,func in dct.items():
print "\"%s\"" % name, "-->", "\"%s\"" % func
if name[0]!="_" and len(repr(func))>10:
if repr(func)[:5] == "<func":
dct["_"+name] = dct[name]
dct[name].func_name = "_"+dct[name].func_name
@leepro
leepro / gist:8535317
Created January 21, 2014 06:31
ipython notebook: Understanding frame of Python
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@leepro
leepro / prettify_json.py
Created February 28, 2014 18:20
Sublime Text 2 script for Prettifying JSON
import sublime, sublime_plugin, json, traceback, sys, re
class PrettifyJsonCommand(sublime_plugin.TextCommand):
def run(self, edit):
# Get the current selection
if self.view.sel()[0].empty():
region = sublime.Region(0L, self.view.size())
source = self.view.substr(region).encode('utf-8')
@leepro
leepro / bytes.py
Created March 21, 2014 19:43
Human readable bytes conversions
## {{{ http://code.activestate.com/recipes/578019/ (r15)
#!/usr/bin/env python
"""
Bytes-to-human / human-to-bytes converter.
Based on: http://goo.gl/kTQMs
Working with Python 2.x and 3.x.
Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
License: MIT
@leepro
leepro / clock.sh
Created April 4, 2014 03:04
clock
#!/bin/sh
while [ 1 ]
do
clear
date +%T |toilet -F gay -f mono12
sleep 0.91;
done
"""
This example requires the body-streaming tornado fork at https://github.com/nephics/tornado.
Refer to http://groups.google.com/group/python-tornado/browse_thread/thread/791c67cb86c2dea2.
Supports uploading an unlimited number/size of files in a single
PUT multipart/form-data request. Each file is processed as the stream
finds the part in the form data.
==USAGE==