Skip to content

Instantly share code, notes, and snippets.

@hlung
hlung / iOS - comparing class objects.m
Last active Aug 29, 2015
Calling `-isKindOfClass` on a class object doesn't raise any warning and will give wrong comparison results. We have to use `+isSubclassOfClass:` instead.
View iOS - comparing class objects.m
+ (NSString*)levelName {
if ([self isSubclassOfClass:[FGRoom class]]) {
return @"Room";
}
}
@hlung
hlung / iOS - Equality.h
Last active Aug 29, 2015
An example for class equality method implementation
View iOS - Equality.h
@interface FGEntityLine : NSObject
@property (readonly, nonatomic) NSUInteger companyId;
@property (readonly, nonatomic) NSUInteger brandId;
@property (readonly, nonatomic) NSUInteger propertyId;
/** Returns YES if all identifiers are equal. */
- (BOOL)isEqualToEntityLine:(FGEntityLine *)line;
@end
View POS Store log.txt
2015-04-02 18:27:43.897 Baccarat[18273:1755018] INFO: POST [START] : https://api.fingi-develop.com/v3/companies/12/brands/20/properties/30/rooms/1624/store_shopping_cart_items
2015-04-02 18:27:43.897 Baccarat[18273:1755018] VERBOSE: body : {
"store_name" = "pos_store";
"store_shopping_cart_item" = {
"item_quantity" = 1;
"item_selection" = "";
"item_tag" = "pos_bagel";
"pos_item_id" = 10026;
};
}
@hlung
hlung / test.json
Created May 22, 2015
Test various JSON values through NSJSONSerialization and see Bool results
View test.json
{
"name": "hahaha",
"a_null": null,
"a_true": true,
"a_false": false,
"a_n1": -1,
"a_0": 0,
"a_1": 1,
"a_2": 2,
}
@hlung
hlung / iOS - In-line block declaration.m
Last active Sep 8, 2015
Objective-C In-line block declaration can be hard to remember. Here are example declaration and usage.
View iOS - In-line block declaration.m
// using block in interface property, use "copy"
@property (copy, nonatomic) void (^simpleBlock)(void);
@property (copy, nonatomic) BOOL (^blockWithParamter)(NSString *input);
// block variable declaration
void (^addButton)(SEL, NSString *) = ^(SEL action, NSString *imageName) {
};
// block typedef shorthand
typedef BOOL (^FailureHandler)(NSError *error);
@hlung
hlung / gist:0f30addbda7cc0510bb3
Created Sep 9, 2015
NSArray of US state names and abbreviations :)
View gist:0f30addbda7cc0510bb3
- (NSArray*)usStateAbbreviations {
static NSArray *array = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
array = @[@"AL", @"AK", @"AZ", @"AR", @"CA", @"CO", @"CT", @"DE", @"FL", @"GA", @"HI", @"ID", @"IL", @"IN", @"IA", @"KS", @"KY", @"LA", @"ME", @"MD", @"MA", @"MI", @"MN", @"MS", @"MO", @"MT", @"NE", @"NV", @"NH", @"NJ", @"NM", @"NY", @"NC", @"ND", @"OH", @"OK", @"OR", @"PA", @"RI", @"SC", @"SD", @"TN", @"TX", @"UT", @"VT", @"VA", @"WA", @"WV", @"WI", @"WY"];
});
return array;
}
- (NSArray*)usStateNames {
@hlung
hlung / iOS - constants declaration.m
Last active Nov 25, 2015
iOS - how to create constants in private and public scope
View iOS - constants declaration.m
// ----------------------------------
//declaration in PRIVATE scope (for using only in your class)
// ----------------------------------
// declare in .m
static const int kTweetMaxCharacters = 140;
static NSString * const kHelloString = @"HELLO!";
// ----------------------------------
// declaration in PUBLIC scope (for using in other classes too)
// ----------------------------------
@hlung
hlung / roomsay.coffee
Last active Dec 9, 2015
Let's make Hubot say what you want in a particular room! :D
View roomsay.coffee
# Description:
# Let's make Hubot say what you want in a particular room! :D
#
# Dependencies:
# -
#
# Configuration:
# -
#
# Commands:
@hlung
hlung / standup.coffee
Last active Dec 11, 2015
Automatically nags "non-offline" people in a room at a particular time to enter something.
View standup.coffee
# Description:
# Automatically nags "non-offline" people in a room at a particular time interval to enter something.
#
# Dependencies:
# cron, time, node-xmpp
#
# Configuration:
# HIPCHAT_STANDUP_ROOM_JID e.g. '13184_botlab@conf.hipchat.com'
# HIPCHAT_STANDUP_TIMEZONE e.g. "Asia/Bangkok" or "Europe/Paris" or "America/New_York"
# HIPCHAT_STANDUP_CRON_TIME e.g. '0 0 14-18 * * 1-5' means weekdays, every hour from 2-6PM
@hlung
hlung / gist:4662942
Created Jan 29, 2013
Returns a global unique identifier for the process.
View gist:4662942
NSString *token = [[NSProcessInfo processInfo] globallyUniqueString];