Skip to content

Instantly share code, notes, and snippets.

@hechien
hechien / gist:899313
Created April 2, 2011 07:38
UITableView Section Touch detection.
id touchedView = [[touches anyObject] view];
if([[touchedView class] isEqual: [NSClassFromString(@"UITableHeaderFooterView") class]]){
NSLog(@"Text: %@", [touchedView performSelector:@selector(text)]);
}
@hechien
hechien / git_backup
Created May 6, 2011 07:22
Git Repositories auto pull for backup
#!/usr/bin/ruby
USER = "git"
HOST = "ssh://#{USER}@github.com/"
COMMAND = "git clone #{HOST}"
EMAIL = ["xxx@xxx.com", "ooo@xxx.com"]
repos = []
repos << %w"1 2 3 4"
repos << %w"5"
@hechien
hechien / factorial.rb
Created May 12, 2011 01:50
[Ruby] factorial; 數學階乘
=begin
(1..10).each{|i|
puts i.!
}
=end
class Integer
def !
_return_val = 1
self.times{|_current|
#!/usr/bin/env ruby
# PHP version: http://www.josephj.com/entry.php?id=346
EMAILS_CONFIG_FILE = File.join(File.dirname(__FILE__), "..", "emails")
if(File.exist?(EMAILS_CONFIG_FILE))
emails = File.read(EMAILS_CONFIG_FILE).split("\n").join(", ")
`git config hooks.mailinglist "#{emails}"`
puts "E-mail receivers: #{emails}"
end
class Store
attr_accessor :name
def initialize
@name = "N/A"
@@root = "Apple"
end
def root
@@root
@hechien
hechien / gist:1062853
Created July 4, 2011 03:06
A basic block example in Objective-C.
^{
NSLog(@"I'm in a block");
};
@hechien
hechien / gist:1062855
Created July 4, 2011 03:09
jQuery in JavaScript example.
(function(){
console.log("I'm running.");
})(jQuery);
@hechien
hechien / gist:1062862
Created July 4, 2011 03:18
Make block as a function in JavaScript & Objective-C
var run_to_me = function(lonely){
if(lonely)
console.log("whenever you're lonely");
else
console.log("f**k off");
}
run_to_me(true);
run_to_me(false);
@hechien
hechien / gist:1062874
Created July 4, 2011 03:34
Objective-C Block in C function and Object.
@interface Worker : NSObject {
}
+(void)something:(void (^)(BOOL))block;
@end
@implementation Worker
@hechien
hechien / main.m
Created July 4, 2011 03:43
Closure access variables.
int age = 23;
^{
NSLog(@"My age is: %d", age);
}();