Skip to content

Instantly share code, notes, and snippets.

View huobazi's full-sized avatar
🎯
Focusing

Marble Wu huobazi

🎯
Focusing
View GitHub Profile
@huobazi
huobazi / so.rb
Created June 17, 2011 00:47 — forked from basicxman/so.rb
A horrible script for Stack Overflow Growl notifications
require 'nokogiri'
require 'open-uri'
require 'json/pure'
require 'ruby-growl'
class StackOverflowNotifier
def initialize(*args)
@data = if File.exists? "data.json"
JSON.parse(File.read("data.json"))
@huobazi
huobazi / gist:1037280
Created June 21, 2011 05:07
create some test topics
user = User.create :username => 'test', :email => '[email protected]', :password => 'test@123456', :password_confirmation => 'test@123456'
30.times do |n|
topic = user.topics.create :title => "My Topic #{n}", :content => "Here is topic content", :tags => "tag,Test"
10.times do
reply = Reply.new :content => 'Here is reply content'
reply.user = user
reply.topic = topic
reply.save
@huobazi
huobazi / gist:1039424
Created June 22, 2011 03:04
Password masking in C# console application
/// <summary>
/// Gets the console secure password.
/// </summary>
/// <returns></returns>
private static SecureString GetConsoleSecurePassword( )
{
SecureString pwd = new SecureString( );
while ( true )
{
if(!window.console) {
val names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i) {
window.console[names[i]] = function () {}
}
}
@huobazi
huobazi / 1
Created July 22, 2011 04:22
添加 删除ubuntu自启动服务 init.d
1. 装个 sysv-conf-rc
2. sudo update-rc.d -f mysql remove 删除mysql随机器启动的服务
sudo update-rc.d -f apache2 remove 删除apache2随机器启动的服务
3. 查看/etc/rc2.d/里面的apache和mysql启动脚本,通常都是两个阿拉伯数字后再接一个英文字母,再加脚本名称。英文字母 是S的都是会自动启动的,K则相反。所以只要找到apache和mysql的启动脚本,把S改成K就可以了
@huobazi
huobazi / gist:1101239
Created July 23, 2011 09:45
nginx css javascript image remove www
location ~* .(jpg|gif|png|js|css)$ {
if (-f $request_filename) {
expires max;
break;
}
}
@huobazi
huobazi / redis-server
Created July 23, 2011 13:47
在 Ubuntu 下安装 Redis 并使用 init 脚本启动
1. 下载安装:
cd /tmp
wget http://redis.googlecode.com/files/redis-2.2.4.tar.gz
tar -zxf redis-2.2.4.tar.gz
cd redis-2.2.4
make
sudo make install
2. 配置init脚本:
@huobazi
huobazi / gist:1108437
Created July 27, 2011 00:40
Javascript generate a pseudo-GUID
// Generate four random hex digits.
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
// Generate a pseudo-GUID by concatenating random hexadecimal.
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
};
@huobazi
huobazi / to_param.rb
Created July 28, 2011 00:20 — forked from pasberth/to_param.rb
Key Value To QueryString
# h = { "key0"=>"value0", "key1"=>"value1", "key2"=>"value2" }
h.map { |k, v| "#{k}=#{v}" }.join('&')
# => "key0=value0&key1=value1&key2=value2"
@huobazi
huobazi / to_param.py
Created July 28, 2011 00:24 — forked from pasberth/to_param.py
Dict To QueryString
#
# dict = { "key0": "value0", "key1": "value1", "key2": "value2" }
"&".join( [("%s=%s" % (k, v)) for k, v in dict.items()] )
# => 'key2=value2&key1=value1&key0=value0'