Skip to content

Instantly share code, notes, and snippets.

@pinglamb
pinglamb / constant_helper.rb
Created January 27, 2015 02:32
Rspec Constant Redefine Helper
module ConstantHelper
def redefine_constant(namespace, const_name, new_value)
namespace.send(:remove_const, const_name) if namespace.const_defined?(const_name)
namespace.const_set(const_name, new_value)
end
end
@pinglamb
pinglamb / tennison.js
Created May 5, 2014 07:37
Tennison Bookmarklet
javascript:var%20s=document.createElement('script');s.setAttribute('src',%20'http://code.jquery.com/jquery.js');document.getElementsByTagName('body')[0].appendChild(s);void(s);$("img").attr("src", "http://lh4.googleusercontent.com/-RmrZDM1BSbk/U2bwuAKC6VI/AAAAAAAAD_I/PgK91Uc24xM/w456-h335-no/20140502_202731_852.jpg");
@pinglamb
pinglamb / README.md
Last active December 21, 2015 20:38 — forked from yachi/install.sh
  • $ brew install git-flow
  • $ brew uninstall git
  • $ brew install git --without-completions
  • enable git-flow in oh my zsh plugin
  • restart zsh
  • $ git flow init
  • $ git flow feature start myFeature
  • $ git commit -a
  • $ git commit -a
  • $ git flow feature finish myFeature
@pinglamb
pinglamb / wcw.json
Created November 21, 2012 17:14
Wong Chi Wah JSON
{
"data": [
{"title": "黃子華棟篤笑 1990 - 娛樂圈血肉史", "link": "http://www.youtube.com/watch?v=hWQoj0wVuKM"},
{"title": "黃子華棟篤笑 1991 - 色情家庭", "link": "http://www.youtube.com/watch?v=bxm1vKwzzis"},
{"title": "黃子華棟篤笑 1992 - 跟住去邊度", "link": "http://www.youtube.com/watch?v=UmliSnuWPDQ"},
{"title": "黃子華棟篤笑 1994 - 末世財神", "link": "http://www.youtube.com/watch?v=YzSyB4D06-M"},
{"title": "黃子華棟篤笑 1995 - 棟篤笑雙打之玩無可玩", "link": "http://www.youtube.com/watch?v=SyG_c9ziTvY"},
{"title": "黃子華棟篤笑 1997 - 秋前算帳", "link": "http://www.youtube.com/watch?v=MRsz2nMtOSs"},
{"title": "黃子華棟篤笑 1999 - 拾下拾下", "link": "http://www.youtube.com/watch?v=ZEj3bGS6sYc"},
{"title": "黃子華棟篤笑 2003 - 冇碳用", "link": "http://www.youtube.com/watch?v=PPGOSpiujPY"},
@pinglamb
pinglamb / Guardfile
Created September 27, 2012 08:33
Guard Config, Esp the Spin part
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'brakeman' do
watch(%r{^app/.+\.(erb|haml|rhtml|rb)$})
watch(%r{^config/.+\.rb$})
watch(%r{^lib/.+\.rb$})
watch('Gemfile')
end
@pinglamb
pinglamb / active.js
Created June 19, 2012 13:55
Select Active Item JS
var links = document.getElementsByClassName('link');
var choose = function() {
for(var j=0; j < links.length; j++) {
links[j].className = '';
}
this.className = 'active';
};
for(var i=0; i < links.length; i++) {
links[i].addEventListener('click', choose, false);
}
@pinglamb
pinglamb / Gemfile
Created March 1, 2012 17:36
Redmine Gemfile
# A sample Gemfile
source "http://rubygems.org"
gem "rails", "2.3.11"
gem "mysql"
gem "rdoc"
gem "rdoc-data"
gem "shoulda", "~> 2.10.3"
gem "edavis10-object_daddy", ">= 0"
gem "mocha", ">= 0"
@pinglamb
pinglamb / EventProvider.java
Created December 27, 2011 16:37
ContentProvider#query
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
if(sURIMatcher.match(uri) == EVENTS) {
String selectClauses = "";
for(int i=0; i < projection.length; i++) {
if(projection[i] == "participants_count") {
selectClauses += "(SELECT COUNT(*) FROM participants WHERE participants.event_id = events.event_id)";
} else {
selectClauses += projection[i];
@pinglamb
pinglamb / git.diff
Created November 21, 2011 07:26
Show sum of collections and hits count in RailsAdmin
diff --git a/app/models/photo.rb b/app/models/photo.rb
index 3c44e48..3fc12cc 100644
--- a/app/models/photo.rb
+++ b/app/models/photo.rb
@@ -190,4 +190,8 @@ class Photo < ActiveRecord::Base
def hide
update_attribute(:hidden, true)
end
+
+ def sum_of_collections_count_and_hits_count