Skip to content

Instantly share code, notes, and snippets.

View sodastsai's full-sized avatar

Tien-Che Tsai sodastsai

View GitHub Profile
@sodastsai
sodastsai / gist:1906102
Created February 25, 2012 03:45
NSRegularExpression
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *original = @"a\nb";
NSLog(@"%@", original);
NSMutableString *string = [NSMutableString stringWithString:original];
NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:@"\n+" options:0 error:nil];
@sodastsai
sodastsai / gist:2148182
Created March 21, 2012 15:11
Indentation
function someFunc() {
// Indent
alert('this is a function');
if (1) {
// Indent on each '{'
alert('2-level indentation');
}
alert('function end');
}
@sodastsai
sodastsai / gist:2212557
Created March 27, 2012 04:32
UIView animation
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor = [UIColor yellowColor];
[self.window addSubview:view];
void (^keyframe1)(void) = ^{
#define kFilePath [NSString stringWithFormat:@"%@/uuid.wuuid", kDocumentPath]
#import <Foundation/Foundation.h>
@interface WTuuid : NSObject
+ (NSString *)stringWithUUID;
@end
@sodastsai
sodastsai / Fraction.py
Created October 19, 2012 10:20
Fraction
'''
Created on Feb 11, 2012
@author: sodas
'''
class Fraction (object):
def __init__(self, numerator, denominator):
self.numerator = numerator
if denominator == 0:
@sodastsai
sodastsai / converter.py
Created October 22, 2012 01:47
Convert CSV to PLIST
#!/usr/bin/env python3
import sys
import csv
import plistlib
import os
csv_file = sys.argv[1]
with open(csv_file, 'r', encoding='utf-8') as f:
result = list(csv.DictReader(f))
@sodastsai
sodastsai / Books.m
Created November 8, 2012 01:14
11/08 Code snippets
DMAuthor *author1 = [DMAuthor authorWithFirstName:@"Jo" lastName:@"Walton"];
DMAuthor *author2 = [DMAuthor authorWithFirstName:@"Connie" lastName:@"Willis"];
DMAuthor *author3 = [DMAuthor authorWithFirstName:@"J.K." lastName:@"Rowling"];
DMBook *book1 = [[DMBook alloc] initWithTitle:@"Among Others" subtitle:nil price:10.19 andAuthor:author1];
DMBook *book2 = [[DMBook alloc] initWithTitle:@"Blackout" subtitle:nil price:11.68 andAuthor:author2];
DMBook *book3 = [[DMBook alloc] initWithTitle:@"Harry Potter with Philisopher's Stone" subtitle:nil price:10.0f andAuthor:author3];
DMBook *book4 = [[DMBook alloc] initWithTitle:@"Harry Potter with Chamber of Secrets" subtitle:nil price:12.0f andAuthor:author3];
DMBook *book5 = [[DMBook alloc] initWithTitle:@"Harry Potter with Prisoner of Azkaban" subtitle:nil price:14.0f andAuthor:author3];
@sodastsai
sodastsai / Block_no_arc.m
Created November 19, 2012 15:36
Block and Closure
#import <Foundation/Foundation.h>
@interface BCObject : NSObject
+ (int(^)(int, int))magicFunction:(int)seed;
+ (BOOL(^)(id))lengthValidator:(NSUInteger)validLength;
@end
@implementation BCObject
+ (int(^)(int, int))magicFunction:(int)seed {
@sodastsai
sodastsai / ISStorage.h
Created November 23, 2012 12:23
Internal Storage with KVO
#import <Foundation/Foundation.h>
@interface ISStorage : NSObject
+ (ISStorage *)sharedStorage;
- (id)valueForKeyInInternalStorage:(NSString *)key;
- (void)setValue:(id)value forKeyInInternalStorage:(NSString *)key;
@end
@sodastsai
sodastsai / ISTimerStorage.h
Created November 23, 2012 12:27
Internal Storage with NSTimer
#import <Foundation/Foundation.h>
@interface ISTimerStorage : NSObject
+ (ISTimerStorage *)sharedStorage;
- (id)valueForKeyInInternalStorage:(NSString *)key;
- (void)setValue:(id)value forKeyInInternalStorage:(NSString *)key;
@end