Skip to content

Instantly share code, notes, and snippets.

View lxneng's full-sized avatar
🎯
Focusing

Eric Luo lxneng

🎯
Focusing
View GitHub Profile
@lxneng
lxneng / resque.py
Created February 25, 2010 01:58 — forked from defunkt/resque.py
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))
@lxneng
lxneng / gist:314140
Created February 25, 2010 02:17
解决ubuntu中flash乱码
解决ubuntu中flash乱码
$ sudo vim /etc/fonts/conf.d/49-sansserif.conf
go to line 18
:s/sans-serif/sans
import re
p = re.compile(
r'(<b>|</b>|<i>|</i>|<blockquote>|</blockquote>|<a href="[^"]+">|</a>)',
re.IGNORECASE
)
escape = lambda s: s.replace(
'&', '&amp;'
).replace(
'>', '&gt;'
# 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()
@lxneng
lxneng / is_hard.py
Created February 25, 2010 06:15 — forked from simonw/is_hard.py
tell if two files are hard links to the same thing
#!/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])
@lxneng
lxneng / gist:314288
Created February 25, 2010 06:16 — forked from simonw/gist:127850
# 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
@lxneng
lxneng / ftpbackup.py
Created February 25, 2010 06:26 — forked from Lizdo/ftpbackup.py
#! /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'
@lxneng
lxneng / gist:315330
Created February 26, 2010 02:37
Find file in subdirectory
import os
def findFileInSubdirectory(filename, subdirectory=''):
'''
Find file in subdirectory
'''
if subdirectory:
path = subdirectory
else:
path = os.getcwd()
@lxneng
lxneng / gist:315334
Created February 26, 2010 02:47
Python sorting - A list of objects
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)]
@lxneng
lxneng / gist:315493
Created February 26, 2010 07:11
install sunpinyin on ubuntu
# 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