Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
'''
image_convert.py
~~~~~~~~~~~~~~~~~
A small tool to resize/compress/rotate image.
:copyright: Copyright (C) 2012 Yue Du <[email protected]>
:license: BSD 2-Clause License
'''
@ifduyue
ifduyue / gist.py
Last active December 10, 2015 06:28
A small tool to upload a gist.
#!/usr/bin/env python
'''
gist.py
~~~~~~~~~
A small tool to upload a gist.
:copyright: Copyright (C) 2012 Yue Du <[email protected]>
:license: BSD 2-Clause License
'''
@ifduyue
ifduyue / httplib.py
Created July 11, 2012 02:10
sae modified httplib.py
"""HTTP/1.1 client library
<intro stuff goes here>
<other stuff, too>
HTTPConnection goes through a number of "states", which define when a client
may legally make another request or fetch the response for a particular
request. This diagram details these state transitions:
(null)
@ifduyue
ifduyue / 2_urlfetch.py
Last active October 2, 2015 01:48
2_urlfetch.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# http://pypi.python.org/pypi/urlfetch
import urlfetch
r = urlfetch.get('https://api.github.com', auth=('user', 'pass'))
print r.status
print r.headers['content-type']
@ifduyue
ifduyue / clone_all_github_repos.py
Last active September 30, 2015 08:28
clone_all_github_repos
#!/bin/env python
#-*- coding: utf-8 -*-
import sys
import os
from urlfetch import get
user = sys.argv[1]
r = get('https://api.github.com/users/%s/repos' % user)
@ifduyue
ifduyue / strip_tags.cpp
Created January 13, 2012 02:37
c++ strip_tags replace_all
string &replace_all(string &content, const string &from, const string &to)
{
size_t i = 0;
size_t j;
while((j = content.find(from, i)) != string::npos) {
content.replace(j, from.size(), to);
i = j + to.size();
}
return content;
}
@ifduyue
ifduyue / p_in_html.py
Created January 11, 2012 15:04
content between <p> and </p>
def txt_wrap_by(begin, end, html):
if not html:
return ''
start = html.find(begin)
if start >= 0:
start += len(begin)
end = html.find(end, start)
if end >= 0:
return html[start:end].strip()
import timeit
def f1(list):
string = ""
for item in list:
string = string + chr(item)
return string
def f2(list):
return reduce(lambda string, item: string + chr(item), list, "")
@ifduyue
ifduyue / lib.py
Created December 18, 2011 12:51
some convenient functions
#coding: utf8
from __future__ import with_statement, absolute_import
import os
import re
import sys
import signal
import string
import random
@ifduyue
ifduyue / bash script
Created December 18, 2011 05:46
shurl_shorten
$ cat ~/bin/shurl
#!/bin/bash
curl -i http://shurl.im/ -F "url=$1" -s | grep Location | awk '{print $2}'
$ shurl http://lyxint.com/
http://shurl.im/1