Skip to content

Instantly share code, notes, and snippets.

View xianhuazhou's full-sized avatar

xianhua zhou xianhuazhou

View GitHub Profile
Array::uniq = (cmp = null)->
arr = this.slice(0)
if typeof(cmp) == 'function'
arr.sort(cmp)
else
arr.sort()
i = 0
size = arr.length
while i < size
while true
@xianhuazhou
xianhuazhou / gist:1415626
Created December 1, 2011 10:24
a fake sendmail script for testing mail related applications, can replace /usr/sbin/sendmail
#!/bin/sh
# chmod 666 /var/mails.txt
# all mails will be stored in this file
MAILS_FILE='/var/mails.txt'
while read x
do
echo $x >> $MAILS_FILE
done
@xianhuazhou
xianhuazhou / gist:1408232
Created November 30, 2011 06:07
show create tables from a database
#!/usr/bin/env ruby
# encoding: UTF-8
# show create tables from a database
require 'mysql2'
m = Mysql2::Client.new :username => 'root', :password => '', :host => 'localhost', :database => 'dbname'
result = m.query("SHOW TABLES").collect do |row|
table = row['Tables_in_dbname']
@xianhuazhou
xianhuazhou / gist:1393052
Created November 25, 2011 08:30
shell script as redis client
#!/bin/bash
# add_item.sh
expect << EOF
spawn telnet localhost 6379
send "SELECT 10\n"
expect "OK"
send "SADD items \"${1}\"\n"
expect ".*"
@xianhuazhou
xianhuazhou / gist:1353844
Created November 10, 2011 01:45
start openoffice as server
nohup soffice --headless --nofirststartwizard --accept="socket,port=8100;urp" &
require 'mysql'
db = Mysql.new('webdb', 'root', 'pa$$', 'home')
db.query("SHOW TABLES LIKE '%home%'").each do |row|
tb_status = db.query("CHECK TABLE #{row[0]}").fetch_row
puts tb_status.join("\t")
end
db.close
echo 8.8.8.8 >> /etc/resolv.conf
echo 8.8.4.4 >> /etc/resolv.conf
apt-get update
apt-get install \
gcc \
g++ \
nmap \
tree \
Warning: Invalid argument supplied for foreach() in /data/vhosts/xunlei.com/xmp.kankan/public_html/xmp_search_v2.php on line 943
Warning: Invalid argument supplied for foreach() in /data/vhosts/xunlei.com/xmp.kankan/public_html/xmp_search_v2.php on line 210
@xianhuazhou
xianhuazhou / convert_tables_character.rb
Created August 29, 2011 05:29
convert character for redmine tables
#!/usr/bin/env ruby
require 'rubygems'
require 'mysql'
conn = Mysql::connect("localhost", "redmine", "redmine", "redmine")
conn.list_tables.each do |table|
conn.query("ALTER TABLE `#{table}` CONVERT TO CHARACTER SET 'UTF8'")
end
conn.close
puts "Done"
http://mobile.tutsplus.com/category/tutorials/android/