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
@marshluca
marshluca / explicit-vs-implicit-benchmark.rb
Created November 10, 2011 17:11
Explicit vs implicit
require 'benchmark'
def explicit
return "TEST"
end
def implicit
"TEST"
end
@marshluca
marshluca / MyAppDelegate.m
Created October 24, 2011 04:03 — forked from Nitewriter/MyAppDelegate.m
UINavigationController custom navigation bar
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Create a new window and assign directly to provided iVar
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Implementation of new init method
MyCustomNavigationBar *navigationBar = [[MyCustomNavigationBar alloc] initWithFrame:CGRectZero];
UINavigationController *navigationController = [[UINavigationController alloc] initWithCustomNavigationBar:navigationBar];
@marshluca
marshluca / rails3-mongoid-devise-template.rb
Created October 21, 2011 10:24
rails 3 template with mongoid, devise
# Application Generator Template
# Modifies a Rails app to use Mongoid and Devise
# Usage: rails new APP_NAME -m https://raw.github.com/gist/1303515/4f661b5cbc2a6d3ed25e85c78fa8ac4f21eafa83/rails3-mongoid-devise-template.rb -T -O
# Information and a tutorial:
# http://github.com/RailsApps/rails3-mongoid-devise/
# Generated using the rails_apps_composer gem:
# https://github.com/RailsApps/rails_apps_composer/
@marshluca
marshluca / rails3-devise-rspec-cucumber-template.rb
Created October 21, 2011 10:18
rails 3 template with devise, rspec, cucumber
# Application Generator Template
# Modifies a Rails app to use Devise with RSpec and Cucumber
# Usage: rails new APP_NAME -m https://gist.github.com/raw/1303508/f2c6643457fc246daf761a2488b10b28ba135538/rails3-devise-rspec-cucumber-template.rb -T
# Information and a tutorial:
# https://github.com/RailsApps/rails3-devise-rspec-cucumber
# Generated using the rails_apps_composer gem:
# https://github.com/RailsApps/rails_apps_composer/
@marshluca
marshluca / Delayed::Job daemon script for delayed_job
Created September 16, 2011 10:06 — forked from lukeredpath/Delayed::Job daemon script for delayed_job
An easy way to take the effort out of managing your background worker process is to write a simple wrapper script using the *daemons* gem.
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
daemon_options = {
:multiple => false,
:dir_mode => :normal,
:dir => File.join(dir, 'tmp', 'pids'),
:backtrace => true
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ') # super returns an array like this: ["-resize", "100x", "-crop", "100x100+0+0", "+repage"]
else
super
end
end
@marshluca
marshluca / after.html
Created August 26, 2011 10:26
Rails 3 PipeAssets
cache: [GET /intro] miss
Started GET "/intro" for 127.0.0.1 at Fri Aug 26 18:25:29 +0800 2011
Processing by HomeController#intro as HTML
==> Got Account:5343 from cache. (0.00065)
Rendered home/intro.html.erb within layouts/application (0.1ms)
Completed 200 OK in 233ms (Views: 4.1ms | ActiveRecord: 10.7ms | Mongo: 0.0ms | Sphinx: 0.0ms | Memcache: 0.0ms)
cache: [GET /assets/application-e808531739fb5e75ea9161663d738563.css] fresh
cache: [GET /assets/index-d16c1771b786ce3dc9730baa43e2fe87.css] fresh
@marshluca
marshluca / mongodb_restart.sh
Created August 26, 2011 09:55
restart mongodb on mac
sudo rm -rf /usr/local/mongodb_data/mongod.lock
sudo launchctl load /Library/LaunchDaemons/org.mongodb.mongod.plist
@marshluca
marshluca / README.markdown
Created August 26, 2011 07:03 — forked from ariera/README.markdown
A keyboard shortcut to run tests with watchr

A keyboard shortcut to run tests with watchr

When developing in rails I use watchr to run the tests each time a file is saved, but lots of times I find my self adding a whitespace or a newline and saving just to trigger watchr and run the tests.

I wanted to have is a simple keyboard shortcut (like F15) to tell watchr to run the last spec, and mpartel (thx! : ) gave me an idea on how to do it, so here it is:

Dependencies

Obviously you need watchr, but we're also going to need pgrep that will help us find out the pid of the watchr process. So go ahead and do

sudo port install proctools

@marshluca
marshluca / caches_action.rb
Created August 26, 2011 07:01
Rails Action Cache
class ListsController < ApplicationController
before_filter :authenticate, :except => :public
caches_page :public
caches_action :index, :if => proc do
!request.format.json? # cache if is not a JSON request
end
caches_action :show, :cache_path => { :project => 1 },