Skip to content

Instantly share code, notes, and snippets.

View marshluca's full-sized avatar
🏠
Working from home

Lucas Zhang marshluca

🏠
Working from home
View GitHub Profile
class DeferredGarbageCollection
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 15.0).to_f
@@last_gc_run = Time.now
def self.start
GC.disable if DEFERRED_GC_THRESHOLD > 0
end
# Reincarnation for classes
class Class
def reincarnate
buried = Object.__send__(:remove_const, self.name)
Object.const_set(self.name, Class.new(buried))
end
end
class Abc
# mongo_template.rb
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842)
#
# To use:
# rails project_name -m http://gist.github.com/gists/219223.txt
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
@marshluca
marshluca / twitter_proxy.rb
Created January 28, 2010 09:29
给twitter插件加上可用代理proxy
require 'forwardable'
require 'rubygems'
require 'uri'
gem 'oauth', '~> 0.3.6'
require 'oauth'
gem 'hashie', '~> 0.1.3'
require 'hashie'
@marshluca
marshluca / taobao_api.rb
Created February 23, 2010 01:45
淘宝Ruby API调用实例
#此DEMO的功能:查询手机类的淘客商品
require 'digest/md5'
require 'net/http'
require 'open-uri'
require 'iconv'
#获得当前时间
t = Time.new();
#组装参数
@marshluca
marshluca / define_class_dynamiclly.rb
Created February 23, 2010 05:54
动态定义class,连接database, 打印ddl
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:database => "myapp",
:username => "root",
:password => "root",
:encoding => "utf8")
@marshluca
marshluca / BonFire.m
Created March 9, 2010 10:40
iPhone中用图片流制作动画
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView* campFireView = [[UIImageView alloc] initWithFrame:self.view.frame];
campFireView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"campFire01.gif"],
[UIImage imageNamed:@"campFire02.gif"],
[UIImage imageNamed:@"campFire03.gif"],
[UIImage imageNamed:@"campFire04.gif"],
[UIImage imageNamed:@"campFire05.gif"],
@marshluca
marshluca / gist:382999
Created April 29, 2010 01:29
twitter timeline
# usr/bin/ruby
# encoding: UTF-8
require 'rubygems'
require 'open-uri'
require 'json'
#cmd = 'curl --basic --user username:password http://twitter.com/statuses/friends_timeline.json'
url = 'http://twitk.com/k/statuses/friends_timeline.json'
buffer = open(url, :http_basic_authentication => ["username", "password"]).read
@marshluca
marshluca / wordpress.txt
Created May 14, 2010 08:33
wordpress的mysql ddl
mysql> use wordpress;
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_wordpress |
+-----------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
@marshluca
marshluca / renren_api.rb
Created June 4, 2010 08:05
使用json,net/http解析人人API
require "net/http"
require "json"
USER = 'marshluca@163.com'
PASS = '123456'
API_URL = "http://api.renren.com/restserver.do"
def base_params
{
"api_key" => "f2570a570d56439784bfb69dbda699d1",