Skip to content

Instantly share code, notes, and snippets.

View camsong's full-sized avatar
🤖
GPTing

Cam Song camsong

🤖
GPTing
View GitHub Profile
@camsong
camsong / sources.list
Created January 10, 2012 11:18
The faster ubuntu 11.10 source in China by 163
deb http://mirrors.163.com/ubuntu/ oneiric main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ oneiric main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ oneiric-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-proposed universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-updates universe main multiverse restricted
@camsong
camsong / Forked——Repo_update.sh
Created February 8, 2012 03:26
first you fork ruby-china from huachlee, then you git clone you fork, then you find there some changes in huacnlee's ruby-china , you want to update your fork.
cd ruby-china
git remote add upstream git://github.com/huacnlee/ruby-china.git
git fetch upstream
git merge upstream/master
git push #you will update your forked repo now
#http://eggsonbread.com/2010/03/28/my-rspec-best-practices-and-tips/
describe User do
subject { user }
let(:user) { User.new }
context "when name empty" do
it { should_not be_valid }
specify { user.save.should be_false }
end
@camsong
camsong / dabblet.css
Created February 26, 2012 03:17
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height:100%;
@camsong
camsong / rspec-request-demo.rb
Created March 8, 2012 07:00
rspec request demo for login and sign up
#encoding: utf-8
require 'spec_helper'
describe "sign up and login" do
it "let user sign up and login to the site" do
visit '/'
click_link '注册'
fill_in '用户名', :with => 'jack'
fill_in 'Email', :with => '***@gmail.com'
@camsong
camsong / queue-concurrent-handler.java
Created March 9, 2012 06:36
Do some happy things asynchronously, use LinkedBlockingQueue, you can use this to write log to database asynchronously.
// start service, only run once
public void init() throws ServletException {
ExecutorService service = Executors.newFixedThreadPool(1);
service.execute(new MyQueueHandler());
super.init();
}
public class MyQueue {
public static BlockingQueue EVENT_QUEUE = new LinkedBlockingQueue();
public static void addToQueue(Obj obj) {
@camsong
camsong / chosen_change.js
Created April 6, 2012 02:38
Example to handle chosen update and change events.
<script language="javascript">
$(document).ready(function(){
//华丽初始化
$(".chzn-select").chosen();
//单选select 数据同步
chose_get_ini('#dl_chose');
//change 事件
$('#dl_chose').change(function(){
@camsong
camsong / create_uniq_string.rb
Created May 14, 2012 05:20
Don't like auto increment id? Use a String! This can generate a uniq string.
after_create {
begin
# 4 bytes => 32 bits => 4,294,967,296 unique values
self.profile_slug = ActiveSupport::SecureRandom.hex(4)
self.save!
rescue ActiveRecord::RecordNotUnique => e
retry
end
}
@camsong
camsong / db_backup.sh
Created June 27, 2012 14:26 — forked from happypeter/db_backup.sh
for linode sites
#!/usr/bin/env bash
ssh linode 'cd local_clone; cd happynewsdb; \
mysqldump --extended-insert=FALSE --complete-insert=TRUE -uroot authlove_development>authlove_development.sql; \
git commit -a -m"i"; \
git push;\
cd ../happyecdb/ ; \
mysqldump --extended-insert=FALSE --complete-insert=TRUE -uroot ec_development>ec_development.sql; \
git commit -a -m"i"; \
git push;\
@camsong
camsong / net_http_debug.rb
Created July 3, 2012 14:22 — forked from kaiwren/net_http_debug.rb
Enable debug for all Ruby HTTP requests
require 'net/http'
module Net
class HTTP
def self.enable_debug!
raise "You don't want to do this in anything but development mode!" unless Rails.env == 'development'
class << self
alias_method :__new__, :new
def new(*args, &blk)
instance = __new__(*args, &blk)
instance.set_debug_output($stderr)