This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from redis import Redis | |
import simplejson | |
class Resque(object): | |
"""Dirt simple Resque client in Python. Can be used to create jobs.""" | |
redis_server = 'localhost:6379' | |
def __init__(self): | |
host, port = self.redis_server.split(':') | |
self.redis = Redis(host=host, port=int(port)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
解决ubuntu中flash乱码 | |
$ sudo vim /etc/fonts/conf.d/49-sansserif.conf | |
go to line 18 | |
:s/sans-serif/sans |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Depends on the OS X "say" command | |
import time, datetime, subprocess, math, sys | |
def say(s): | |
subprocess.call(['say', str(s)]) | |
def seconds_until(dt): | |
return time.mktime(dt.timetuple()) - time.time() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"is_hard.py - tell if two files are hard links to the same thing" | |
import os, sys, stat | |
def is_hard_link(filename, other): | |
s1 = os.stat(filename) | |
s2 = os.stat(other) | |
return (s1[stat.ST_INO], s1[stat.ST_DEV]) == \ | |
(s2[stat.ST_INO], s2[stat.ST_DEV]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Django: validate that an uploaded file is a valid PDF | |
import pyPdf # from http://pybrary.net/pyPdf/ | |
from pyPdf.utils import PdfReadError | |
class DocumentForm(forms.ModelForm): | |
pdf = forms.FileField() | |
class Meta: | |
model = Document | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
### Copy everything on a FTP server to a local folder | |
from ftplib import FTP | |
import os.path | |
import datetime | |
def main(): | |
#fill in the parameters here | |
ftpaddress = '1.1.1.1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def findFileInSubdirectory(filename, subdirectory=''): | |
''' | |
Find file in subdirectory | |
''' | |
if subdirectory: | |
path = subdirectory | |
else: | |
path = os.getcwd() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: import operator | |
In [2]: L = [('c', 2), ('d', 1), ('a', 4), ('b', 3)] | |
In [3]: sorted(L, key=operator.itemgetter(0)) | |
Out[3]: [('a', 4), ('b', 3), ('c', 2), ('d', 1)] | |
In [4]: sorted(L, key=operator.itemgetter(1)) | |
Out[4]: [('d', 1), ('c', 2), ('b', 3), ('a', 4)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install sunpinyin on ubuntu | |
sudo add-apt-repository ppa:ibus-dev/ibus-1.2-karmic | |
sudo apt-get update | |
sudo apt-get install ibus-sunpinyin |