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
# 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
## 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, |
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
1. 插入ubuntu live光盘,选择安装 | |
2. 一直到磁盘分区 | |
3. 选择手动分区 | |
4. 把/ /boot /swap等等都对应到原先安装的 | |
5. 不要格式化 | |
6. 确认保存时,点”确定” | |
7. 会跳出错误,说不能安装…,不予理会,选择继续 | |
8. 直到回到Ubuntu安装菜单,选择安装grub | |
或者 |
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
#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/ |
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
#使用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 |