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))
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'
## app/controllers/admin/users_controller.rb
def export_to_csv
@users = User.all
csv_string = FasterCSV.generate(:force_quotes => true) do |out|
out << ['Email Address', 'First Name', 'Last Name', 'Mobile Phone', 'Gender']
@users.each do |u|
out << [u.email, u.first_name, u.last_name, u.phone_number, u.gender]
end
end
send_data(csv_string,
1. 插入ubuntu live光盘,选择安装
2. 一直到磁盘分区
3. 选择手动分区
4. 把/ /boot /swap等等都对应到原先安装的
5. 不要格式化
6. 确认保存时,点”确定”
7. 会跳出错误,说不能安装…,不予理会,选择继续
8. 直到回到Ubuntu安装菜单,选择安装grub
或者
#push
rsync -avz -e ssh /some/small/directory/ [email protected]:/backup/destination/directory/
#pull
rsync -avz -e ssh [email protected]:/backup/destination/directory/ /some/small/directory/
#使用expect
#!/usr/bin/expect -f
#auto ssh login
set timeout 30
#set sshhost [lindex $argv 0]
spawn ssh -D 9527 [email protected]
expect "password:"
send "password\r"
interact