Skip to content

Instantly share code, notes, and snippets.

@saberma
saberma / unicode_string.rb
Created April 14, 2009 12:54
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|
@saberma
saberma / my_rails_template.rb
Created September 12, 2009 08:50
rails template
#rails . -d mysql -m http://gist.github.com/185762.txt
#http://m.onkey.org/2008/12/4/rails-templates
run "rm doc/README_FOR_APP"
run "rm public/index.html"
run "rm README"
run "rm public/favicon.ico"
# Set up git repository
@saberma
saberma / populate.rake
Created September 14, 2009 03:42
生成测试数据
# lib/tasks/populate.rake
namespace :db do
desc "Erase and fill database"
task :populate => :environment do
require 'populator'
require 'faker'
[Conversation, Event, History, Dispatch, Record, Workitem, Duty, Person].each(&:delete_all)
#区划代码
@saberma
saberma / word.rb
Created November 25, 2009 09:20
源代码输出至Word
#源代码输出至Word
require 'win32ole'
WIN32OLE.codepage = WIN32OLE::CP_UTF8
class Word
def initialize
@word = WIN32OLE.new('Word.Application')
@word.visible=true #是否打开文件
@word.Documents.Add()
@word.Selection.Font.Size=10.5
deb http://mirrors.163.com/ubuntu/ hardy main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ hardy-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ hardy-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ hardy-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy-backports main restricted universe multiverse
@saberma
saberma / iptc.sh
Created February 25, 2010 02:53
install-open-toolchain-on-ubuntu
#!/bin/bash
# iPhone Toolchain Compiler - Automatic Generation Script
# Copyright (C) 2009 Jay Freeman (saurik)
# Redistribution and use in source and binary
# forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the
@saberma
saberma / .bashrc
Created April 2, 2010 06:18
useful command in bash
alias xp="VBoxManage startvm winxp"
alias g="git status"
alias zbs="cd ~/Documents/zbs && vim"
alias sqmy="cd ~/Documents/sqmy && vim"
alias r="sudo kill -9 `ps -A | grep mem | awk '{print $1}'` && memcached -m 20 -d && mongrel_rails restart"
export AUTOFEATURE=true
#use mxmlc to compile flex source
export FLEX_HOME=/usr/local/flex
@saberma
saberma / unicorn_restart.sh
Created April 21, 2010 07:57 — forked from defunkt/gist:206253
unicorn config
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
create table pop_temp_all as
select * from pop_populate;
create table pop_temp as
select * from pop_populate
where stroffice='440305008000';
alter table pop_populate disable primary key cascade;
truncate table pop_populate;
@saberma
saberma / domains.rb
Created June 28, 2010 13:31
批量查询域名
#!/usr/bin/env ruby
# sudo apt-get install libnotify-bin
# gem install bulkdom
# gem install notify
require 'bulkdom'
require 'notify'
letters = File.read('letters').chomp
size = letters.size