Skip to content

Instantly share code, notes, and snippets.

View ananfang's full-sized avatar

ananfang ananfang

View GitHub Profile
// This gist explains how to setup scalable Parse LiveQuery server on Heroku
// Because there is one and only 'web' process on Heroku, it will divide into two Heroku apps: Main and LiveQuery.
// A: Main app - All features except for LiveQuery server
// Step A1. Setup a Parse app on Heroku
// Step A2. Add a Heroku Redis (free plan is enough for testing)
// Step A3. Configure Parse app, add redisURL for liveQuery
var api = new ParseServer({
...
liveQuery: {
dispatch_async(dispatch_get_main_queue(), ^{
// Do something here
});
@ananfang
ananfang / yieldWithParamenters.rb
Created July 27, 2012 05:03
The yield statement: yield with paremeters
def who_loves_who
yield('Openchan', 'Chikuwa')
end
who_loves_who do |boy, girl|
puts "#{boy} loves #{girl}"
end
# Results:
#
@ananfang
ananfang / blockAssociateToMethod.rb
Created July 27, 2012 04:54
The yield statement: Block associates to method call
# Associate to a method call with no parameter
just_say_hi { puts 'Hi!'}
# Associate to a method call with parameters
say_hi_to('Andy') { puts 'Hi!' }
@ananfang
ananfang / yieldDefinition.rb
Created July 27, 2012 04:43
The yield statement: Definition
def do_twice
puts 'Start'
yield
yield
puts 'End'
end
do_twice { puts 'Hello world!' }
# Results:
@ananfang
ananfang / block.rb
Created July 25, 2012 05:17
Block in Ruby
{ puts "Hello World!" } # this is a block
do #
puts "Hello World!" # this is also a block
end #
@ananfang
ananfang / SymbolAsKey.rb
Created July 25, 2012 03:32
Symbols in Ruby: Symbol as Key
# 1.8.* and under
player1 = { :name => 'ananfang' }
player2 = { :name => 'fatandy' }
# 1.9.*
player1 = { name: 'ananfang' }
player2 = { name: 'fatandy' }
@ananfang
ananfang / StringAsKey.rb
Created July 25, 2012 02:40
Symbols in Ruby: String as Key
player1 = { 'name' => 'ananfang' }
player2 = { 'name' => 'fatandy' }
@ananfang
ananfang / CustomView.h
Created February 3, 2012 10:18
Load nib file as GUI component
//
// CustomView.h
//
// Created by Fang Andy on 12/2/3.
// Copyright (c) 2012年 Openmouse Studio. All rights reserved.
//
#import <UIKit/UIKit.h>
#define UPLOADING_WORDING @"Uploading %i photo(s)..."
@ananfang
ananfang / UIViewController+TopViewController.h
Created February 2, 2012 05:28
TopViewController category for UIViewController
//
// UIViewController+TopViewController.h
//
// Created by Fang Andy on 12/2/2.
// Copyright (c) 2012年 Openmouse Studio. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (TopViewController)