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:319166
Created March 2, 2010 05:26
to_safe_uri
class String
def to_safe_uri
self.strip.downcase.gsub('&', 'and').gsub(' ', '-').gsub(/[^\w-]/,'')
end
end
@lxneng
lxneng / gist:319171
Created March 2, 2010 05:41
change_password
def change_password?(passwords)
self.password_confirmation = passwords[:password_confirmation]
self.verify_password = passwords[:verify_password]
unless verify_password == unencrypted_password
errors.add(:password, "is incorrect")
return false
end
unless passwords[:new_password] == password_confirmation
errors.add(:password, "does not match confirmation")
return false
@lxneng
lxneng / gist:324781
Created March 8, 2010 02:09
mongodb
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <[email protected]>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
@lxneng
lxneng / gist:324783
Created March 8, 2010 02:19
/etc/init.d/nginx
#! /bin/sh
# chkconfig: - 58 74
# description: nginx is the Nginx daemon.
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro.
#
# Author: Ryan Norbauer
# Modified: Geoffrey Grosenbach http://topfunky.com
# Modified: David Krmpotic http://davidhq.com
## 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
# -l 统计行数
# 不加参数的话,显示行数,字符数,文件大小
wc -l test.txt
@lxneng
lxneng / gist:326553
Created March 9, 2010 13:13
install twisted, instal scrapy
# install twisted
$ cd /usr/local/src
$ svn co svn://svn.twistedmatrix.com/svn/Twisted/trunk twisted
$ cd twisted
$ sudo python setup.py install
# install libxml2
$ cd /usr/local/src
$ wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz
$ tar zxvf libxml2-2.7.6.tar.gz