Skip to content

Instantly share code, notes, and snippets.

View eiffelqiu's full-sized avatar

Eiffel.GM eiffelqiu

  • Beijing, P.R.China
View GitHub Profile
@eiffelqiu
eiffelqiu / gist_cloner.rb
Created May 19, 2011 00:49 — forked from fairchild/gist_cloner.rb
gist_cloner github_username
#!/usr/bin/env ruby
require 'rubygems'
require 'fileutils'
require 'net/http'
require 'uri'
require "open-uri"
require 'nokogiri'
=begin rdoc
Clone all the public gists of a user.
Place each gist in a folder named for the gist_id
@eiffelqiu
eiffelqiu / fetch_gist_snippet
Created May 19, 2011 01:07
ruby fetch gist snippet
#!/usr/bin/env ruby -w
require 'rubygems'
require 'hpricot'
require 'net/http'
require 'net/https'
require 'uri'
require 'tempfile'
test_http = "https://gist.github.com/69457.txt"
@eiffelqiu
eiffelqiu / gist:979981
Created May 19, 2011 01:27 — forked from darkseed/gist:967518
Singletons in Objective C
// A normal singleton
static AppInfo * sharedAppInfo = nil;
+ (AppInfo *) sharedAppInfo
{
if ( sharedAppInfo == nil )
{
[[self alloc] init];
}
return sharedAppInfo;
@eiffelqiu
eiffelqiu / Delegate.h
Created May 22, 2011 08:44 — forked from kgn/Delegate.h
Objective-c delegate
@protocol MyControlDelegate <NSObject>
@optional
- (void)delegateAction:(id)value;
@end
@interface MyControl : NSObject{
id<MyControlDelegate> delegate;
}
@eiffelqiu
eiffelqiu / Enumerable.h
Created May 23, 2011 01:46 — forked from ssoper/Enumerable.h
Injection in Objective-C
// Enumerable.h
#import <Foundation/Foundation.h>
typedef id (^InjectBlock)(id, id);
@interface NSArray (Enumerable)
- (id) inject:(id) initial block:(InjectBlock) block;
@end
@eiffelqiu
eiffelqiu / gist:986132
Created May 23, 2011 02:50 — forked from runeb/gist:218921
Get IP address
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
- (NSString *)getIPAddress
{
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
@eiffelqiu
eiffelqiu / Essential Objective-C libs
Created May 24, 2011 04:34
Essential Objective-C libs
ASIHTTPRequest: https://github.com/pokeb/asi-http-request
JSONKit: https://github.com/johnezang/JSONKit
EGOImageLoading: https://github.com/enormego/EGOImageLoading
EGOCache: https://github.com/enormego/EGOCache
FMDB: https://github.com/ccgus/fmdb
three20: https://github.com/facebook/three20
-------------------------------
Facebook SDK: https://github.com/facebook/facebook-ios-sdk
-------------------------------
@eiffelqiu
eiffelqiu / Singleton.m
Created May 24, 2011 06:17 — forked from rebelzach/Singleton.m
An Objective-C template for singleton classes
static MySingleton *sharedInstance = nil;
@implementation MySingleton
#pragma mark -
#pragma mark class instance methods
#pragma mark -
#pragma mark Singleton methods
//
// NSArray+BinarySearch.h
// BinarySearch
//
// Created by Ole Begemann on 19.04.10.
// Copyright 2010 Ole Begemann. All rights reserved.
//
#import <Foundation/Foundation.h>
// Load html from local file
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"localpage" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]];