Skip to content

Instantly share code, notes, and snippets.

View zliang-min's full-sized avatar

Gimi Liang zliang-min

View GitHub Profile
@zliang-min
zliang-min / The Qlobe.rb
Created December 23, 2010 02:42
很有才的一段ruby代码,来自:http://d.hatena.ne.jp/ku-ma-me/20100905/p1
v=0416;eval$s=%q~d=%!^Lcf<LK8, _@7gj*LJ=c5nM)Tp1g0%Xv.,S[<>YoP
4ZojjV)O>qIH1/n[|2yE[>:ieC ".#####%.#% " 97N-A&Kj_K_><wS5rtWk@*a+Y5
yH?b[F^e7C/56j|pmRe+:)B " .#####%##% :" O98(Zh)'Iof*nm.,$C5Nyt=
PPu01Avw^<IiQ=5$'D-y? " #####%###: #" g6`YT+qLw9k^ch|K'),tc
6ygIL8xI#LNz3v}T=4W " %######## #." lL27FZ0ij)7TQCI)P7u
}RT5-iJbbG5P-DHB<. " :####### ###" R,YvZ_rnv6ky-G+4U'
$*are@b4U351Q-ug5 " ###: : ####" 00x8RR%`Om7VDp4M5
PFixrPvl&<p[]1IJ " %#... #####" EGgDt8Lm#;bc4zS^
y]0`_PstfUxOC(q " %### .#####" /,}.YOIFj(k&q_V
zcaAi?]^lCVYp!; " :. %% .#####" ;s="v=%04o;ev"%
@zliang-min
zliang-min / china_provinces.rb
Created January 13, 2011 07:06
中国省份及其简称的hash
# 所以收录中国所有省份信息。
CHINA_PROVINCES = {
'北京市' => '京',
'浙江省' => '浙',
'天津市' => '津',
'安徽省' => '皖',
'上海市' => '沪',
'福建省' => '闽',
'重庆市' => '渝',
'江西省' => '赣',
@zliang-min
zliang-min / memory_bloat.rb
Created January 25, 2011 08:21 — forked from quake/memory_bloat.rb
一个检查内存泄漏的rack中间件
module Rack
class MemoryBloat
def initialize(app, logger)
@app = app
@logger = logger
end
def call(env)
memory_usage_before = memory_usage
result = @app.call(env)
@zliang-min
zliang-min / ruby-1.9-tips.rb
Created February 6, 2011 03:52 — forked from igrigorik/ruby-1.9-tips.rb
ruby-1.9-tips
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@zliang-min
zliang-min / google_map.html
Created February 16, 2011 08:30
A simple google map api example.
<!doctype html>
<html lang='zh'>
<head>
<meta charset="UTF-8">
<!-- For mobile devices. -->
<title>Google map</title>
<style type="text/css">
#map_canvas { width:299px;height:234px; }
</style>
<script type="text/javascript" src="http://ditu.google.cn/maps/api/js?sensor=false"></script>
@zliang-min
zliang-min / rails_cache.md
Created February 18, 2011 08:37
Rails cache summary.

Rails 2

  • Specify RAILS_CACHE directly in environment.rb, like: RAILS_CACHE = ActiveSupport::Cache.lookup_store :memory_store.

  • Use config.cache_store=, like: config.cache_store = :memory_store. In fact, it calls ActiveSupport::Cache.lookup_store.

  • Another example of cache_store usage: config.cache_store = [:mem_cache_store, 'memhost:11211', {:namespace => 'gimi', :autofix_keys => true}]

  • By default, ActionController::Base.cache_store will be set to RAILS_CACHE, but it can be changed by using ActionController::Base.cache_store=.

  • About session store: ActionController::Base.session= will set ActionController::Base.session_options. ActionController::Base.session_store= decides which store will be used.

@zliang-min
zliang-min / highlight-cat.rb
Created February 24, 2011 17:13
The syntax highlighting cat.
#!/usr/bin/env ruby
require 'syntax/convertors/html'
require 'rainbow'
filename = ARGV[0]
puts ARGV[0]
line_num=0
tokenizer = Syntax.load "ruby"
@zliang-min
zliang-min / replica sets.md
Created March 1, 2011 02:14
A summary of MongoDB Replica Sets

MongoDB

Replica Sets

  • Supports more than two servers in the cluster
  • Better failover and recovery between nodes
  • Data center aware (rack aware too, eventually)
  • Can have passive set members (slaves) that are never primary

配置

启动命令

@zliang-min
zliang-min / jquery plugins.md
Created March 1, 2011 02:58
一些常用的plugin

jquery.maskedinput jquery.metadata

VALIDATION: jquery.validate metadataRules classRules attributeRules staticRules

jquery.blockUI[http://jquery.malsup.com/block/]

@zliang-min
zliang-min / crossdomain.xml
Created March 9, 2011 06:51
A flash crossdomain.xml sample.
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="your.domain.com" />
</cross-domain-policy>