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 / 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 / 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])
# 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()
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;'
@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 / routes_1.rb
Created February 25, 2010 01:54 — forked from ryanb/routes_1.rb
get "/about" => 'info#about', :as => 'about'
get "/privacy" => 'info#privacy', :as => 'privacy'
get "/license" => 'info#license', :as => 'license'
get "/mission" => 'info#mission', :as => 'mission'
get "/contact" => 'info#contact', :as => 'contact'
@lxneng
lxneng / readutf.java
Created February 25, 2010 01:51 — forked from mmalone/readutf.java
Java vs. Python
/**
* Reads from the
* stream <code>in</code> a representation
* of a Unicode character string encoded in
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
* this string of characters is then returned as a <code>String</code>.
* The details of the modified UTF-8 representation
* are exactly the same as for the <code>readUTF</code>
* method of <code>DataInput</code>.
*
@lxneng
lxneng / generic.py
Created February 25, 2010 01:50 — forked from jacobian/generic.py
#
# Further reading:
# Template builtins: http://docs.djangoproject.com/en/1.1/ref/templates/builtins/
# Generic view reference: http://docs.djangoproject.com/en/1.1/ref/generic-views/
#
#### entries/urls.py
from django.conf.urls.defaults import *
#!/bin/sh
# Install ImageMagick on Snow Leopard: by kain, improved by mislav and samsoffes
# http://www.icoretech.org/2009/08/install-imagemagick-in-leopard-snow-leopard/
# Work with 64bit kernel mode
set -e
PREFIX=/usr/local
# Passenger users: amend your Apache global configuration with the following directive
# SetEnv PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal