Skip to content

Instantly share code, notes, and snippets.

@rainly
rainly / unicode_string.rb
Created March 17, 2011 10:22 — forked from saberma/unicode_string.rb
utf8码转中文
equire 'cgi'
def unicode_utf8(unicode_string)
unicode_string.gsub(/\\u\w{4}/) do |s|
str = s.sub(/\\u/, "").hex.to_s(2)
if str.length < 8
CGI.unescape(str.to_i(2).to_s(16).insert(0, "%"))
else
arr = str.reverse.scan(/\w{0,6}/).reverse.select{|a| a != ""}.map{|b| b.reverse}
# ["100", "111000", "000000"]
hex = lambda do |s|
@rainly
rainly / ComputerHelper.cs
Created March 17, 2011 10:23 — forked from alvin2ye/ComputerHelper.cs
得到MAC 和 CPU 序号
class ComputerHelper
{
public static string GetMac()
{
string mac = string.Empty;
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
System.Management.ManagementObjectCollection moc2 = mc.GetInstances();
foreach (System.Management.ManagementObject mo in moc2)
{
@rainly
rainly / nginx
Created March 17, 2011 10:24 — forked from alvin2ye/nginx
nginx in init.d
#! /bin/sh
### BEGIN INIT INFO
# curl https://gist.github.com/870478.txt > nginx
# mv nginx /etc/init.d
# chmod +x /etc/init.d/nginx
# update-rc.d -f nginx defaults
### END INIT INFO
PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@rainly
rainly / sync2s3.bash
Created March 17, 2011 10:24 — forked from alvin2ye/sync2s3.bash
sync file to amazon
#!/bin/bash
# http://wiki.agideo.com/agideowiki/show/S3Rsync
# require http://s3.amazonaws.com/ServEdge_pub/s3sync/s3sync.tar.gz
# install curl http://gist.github.com/631872.txt > sync2s3.bash
export AWS_ACCESS_KEY_ID=YOUR_ID
export AWS_SECRET_ACCESS_KEY=YOUR_PWD
export AWS_CALLING_FORMAT=SUBDOMAIN
# How to install Ruby on Rails on Ubuntu 10.04 (Server) Lucid Lynx
# ---
# Disclaimer: This are my own install of ruby env / rails steps. They work in my setups.
# Tested on x32 & x64 fresh copies of Ubuntu 10.04 server.
# ---
# TODO: add rvm/rails3 version of this steps
# ---
# you definitely want git installed ;)
sudo apt-get install git-core
# install ruby env
@rainly
rainly / check_used.rb
Created March 17, 2011 10:26 — forked from alvin2ye/check_used.rb
rails check_used for destroy
# customer.rb
before_destroy :check_used
def allow_destroy?
@allow_destory ||= LoadingBill.exists?(:author_id => self.id)
end
protected
def check_used
# 不是我的,也不知道原作者
require 'date'
class NongLi
@@lunarInfo = [0x04bd8, 0x04ae0, 0x0a570,
0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0,
0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50,
0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566,
# http://stackoverflow.com/questions/517219/ruby-see-if-a-port-is-open
require 'socket'
require 'timeout'
def is_port_open?(ip, port)
begin
Timeout::timeout(1) do
begin
s = TCPSocket.new(ip, port)
s.close
rainux@immortal ~/devel/twi_meido
% YUKI.N> ruby d.rb
user system total real
0.770000 0.020000 0.790000 ( 0.802016)
0.730000 0.000000 0.730000 ( 0.740943)
0.760000 0.020000 0.780000 ( 0.793928)
user system total real
1.160000 0.010000 1.170000 ( 1.182798)
1.230000 0.030000 1.260000 ( 1.268377)
@rainly
rainly / Debian Packages
Created March 17, 2011 10:33 — forked from rainux/Debian Packages
My favorite debian packages.
autoconf
bison
build-essential
checkgmail
colordiff
colorgcc
colormake
curl
cvs
devtodo