Skip to content

Instantly share code, notes, and snippets.

View sodastsai's full-sized avatar

Tien-Che Tsai sodastsai

View GitHub Profile
@sodastsai
sodastsai / ISDirectlyStorage.h
Created November 23, 2012 12:29
Internal Storage with Directly writing to disk
#import <Foundation/Foundation.h>
@interface ISDirectlyStorage : NSObject
+ (ISDirectlyStorage *)sharedStorage;
- (id)valueForKeyInInternalStorage:(NSString *)key;
- (void)setValue:(id)value forKeyInInternalStorage:(NSString *)key;
@end
@sodastsai
sodastsai / gist:4212337
Created December 5, 2012 04:50
Load storyboard by iOS version
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *storyboardName = nil;
NSString *ios6 = @"6.0";
NSString *currentSystemVersion = [[UIDevice currentDevice] systemVersion];
if ([currentSystemVersion compare:ios6 options:NSNumericSearch] == NSOrderedAscending) {
// Older
storyboardName = @"MainStoryboard-iOS5";
} else {
storyboardName = @"MainStoryboard";
def add(a, b):
return a+b
c = add(1, 2)
print(c)
def func(*args, **kwargs):
print 'args: ' + str(args)
print 'kwargs: ' + str(kwargs)
func(1, 2, a='A', b='B')
@sodastsai
sodastsai / gist:6d4f8e31c1bfc59d168e
Created November 17, 2014 12:44
shared formatter
+ (NSNumberFormatter *)displayNumberFormatter {
static NSNumberFormatter *numberFormatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setPositiveFormat:@"0.###"];
});
return numberFormatter;
}
@sodastsai
sodastsai / object.md
Last active August 29, 2015 14:14
Object

簡單說就是(但下面的code只是示意 Swift-like 不是真的code)

一開始都只有資料可以用 你有 number (whatever int or float), string, list, dict 等等資料結構 所以你的 code 可能會寫成這樣

var mikeBalance: Int = 1000  // Swift 是 "var 參數名稱: 型態
var mikeName: String = "Mike"
var peterBalance: Int = 1500
var peterName: String = "Peter"
class E(Exception):
def __init__(self, *args, **kwargs):
super(E, self).__init__(*args, **kwargs)
print('Create exception')
def __del__(self):
print('Discard exception')
def __str__(self):
return 'my exception'
def f():
@interface SomeOtherClass : NSObject
@end
@implementation SomeOtherClass
- (void)performAction1:(id)param {
if ([param isKindOfClass:[NSNumber class]] || [param isKindOfClass:[NSString class]]) {
NSLog(@"%lf", [param doubleValue]);
} else {
import datetime
from itertools import permutations
def test_body(a, b, c, d, e, f, g, h, i):
mul_result = (a*10 + b) * c
add_result = mul_result + (f*10 + g)
return mul_result == d*10 + e and add_result == h*10 + i
now = datetime.datetime.now()
@sodastsai
sodastsai / guard-declare.h
Last active August 25, 2017 03:09
Swift `guard` in Objective-C
#define guard(CONDITION) if (CONDITION) {}