Skip to content

Instantly share code, notes, and snippets.

@hlung
hlung / iOS - Equality.h
Last active August 29, 2015 14:02
An example for class equality method implementation
@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
@hlung
hlung / iOS - comparing class objects.m
Last active August 29, 2015 14:02
Calling `-isKindOfClass` on a class object doesn't raise any warning and will give wrong comparison results. We have to use `+isSubclassOfClass:` instead.
+ (NSString*)levelName {
if ([self isSubclassOfClass:[FGRoom class]]) {
return @"Room";
}
}
@hlung
hlung / POS Store log.txt
Created April 2, 2015 11:29
POS Store log
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 05:47
Test various JSON values through NSJSONSerialization and see Bool results
{
"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 September 8, 2015 08:15
Objective-C In-line block declaration can be hard to remember. Here are example declaration and usage.
// 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 September 9, 2015 11:15
NSArray of US state names and abbreviations :)
- (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 November 25, 2015 07:41
iOS - how to create constants in private and public scope
// ----------------------------------
//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 December 9, 2015 19:28
Let's make Hubot say what you want in a particular room! :D
# Description:
# Let's make Hubot say what you want in a particular room! :D
#
# Dependencies:
# -
#
# Configuration:
# -
#
# Commands:
@hlung
hlung / standup.coffee
Last active December 11, 2015 04:29
Automatically nags "non-offline" people in a room at a particular time to enter something.
# 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 January 29, 2013 09:21
Returns a global unique identifier for the process.
NSString *token = [[NSProcessInfo processInfo] globallyUniqueString];