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 / 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 / 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 },
@ariera
ariera / README.markdown
Created August 11, 2011 09:41
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

@teamon
teamon / guide.sh
Created July 28, 2011 19:11
Pow + nginx configuration aka give me back my 80 port!
# Install pow
$ curl get.pow.cx | sh
# Install powder
$ gem install powder
# See that firewall is fucked
$ sudo ipfw show
00100 0 0 fwd 127.0.0.1,20559 tcp from any to me dst-port 80 in <- THIS ONE!!!
65535 81005 28684067 allow ip from any to any
@marshluca
marshluca / gist:1105729
Created July 26, 2011 01:36
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules:
@marshluca
marshluca / UIScrollViewDelegate.m
Created July 15, 2011 06:02
UIScrollViewDelegate
@protocol UIScrollViewDelegate
@optional
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
@end
@interface UIScrollView : UIView
@property (assign) id <UIScrollViewDelegate> delegate;
@marshluca
marshluca / NSInvocationOperation.m
Created July 15, 2011 06:01
NSOperationQueue,NSInvocationOperation
- (void) clickButton
{
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(loadDataWithOperation)
object:nil];
[queue addOperation:operation]; // will start the operation
[operation release];
@marshluca
marshluca / detachNewThreadSelector.m
Created July 15, 2011 05:57
[NSThread detachNewThreadSelector]
- (IBAction)clickButton
{
[NSThread detachNewThreadSelector:@selector(startBackgroundJob)
toTarget:self
withObject:nil];
}
- (void)startBackgroundJob
{
[self performSelectorOnMainThread:@selector(makeProgressBarMoving)
@marshluca
marshluca / iOS_snnipets.m
Created July 14, 2011 01:10
iOS代码片段
1.倒序输出一个数组
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",nil];
NSArray* reversedArray = [[array reverseObjectEnumerator] allObjects];