Skip to content

Instantly share code, notes, and snippets.

View vinhnx's full-sized avatar

Vinh Nguyen vinhnx

View GitHub Profile
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
typedef void (^JWLocationManagerCallback)(CLLocation *location);
typedef void (^JWLocationManagerErrorCallback)(NSError *error);
@interface JWLocationManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic, copy) NSString *purpose;
@property (nonatomic, copy) JWLocationManagerCallback locationUpdatedBlock;
// Creating a lambda in C++ with variable type inferred automatically
auto someLambda = [](float w, int x, int y) { return(x); };
// Creating a block in C/ObjC without the use of a typedef -- UGLY
int (^someBlock)(float, int, int) = ^(float w, int x, int y) { return(x); };
// Creating a block in CPP/ObjCPP with variable type inferred automatically -- NOT TOO BAD
auto someBlock = ^(float w, int x, int y) { return(x); };
//
// UIImageCreateUsingBlock.m
//
// Copyright (c) 2013 Zachary Waldowski.
// Licensed under MIT - Provided as-is.
//
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
@vinhnx
vinhnx / Cleanbar.py
Created December 23, 2013 06:00 — forked from drdrang/Cleanbar.py
Clean up the statusbar of an iOS screenshot. The time in the statusbar is maintained, but all other graphics are stripped out and replaced with graphics that show full battery and signal strength. The cellular provider is replaced with the Apple logo, . All graphics are built into the script, which works for any Retina iOS device in any orient…
#!/usr/bin/python
import Image
import base64, zlib
# Jay Parlar convinced me to turn this data structure
# from a dictionary into an object.
class PackedImage(object):
def __init__(self, mode, size, data):
self.mode = mode
@vinhnx
vinhnx / TXLocation.h
Created December 23, 2013 06:05 — forked from ryanmaxwell/TXLocation.h
Mantle JSON Mapping Example
@interface TXLocation : MTLModel <MTLJSONSerializing>
@property (strong, nonatomic, readonly) NSString *status;
@property (strong, nonatomic, readonly) NSNumber *sector;
@property (strong, nonatomic, readonly) NSString *macAddress;
@property (strong, nonatomic, readonly) NSNumber *facilityId;
@property (strong, nonatomic, readonly) NSNumber *departmentId;
@property (strong, nonatomic, readonly) NSNumber *mapId;
@property (strong, nonatomic, readonly) NSNumber *mapVersion;
@vinhnx
vinhnx / gist:8092459
Created December 23, 2013 06:20 — forked from jspahrsummers/gist:5676550
More complex RAC form validation
// Check name validity
RACSignal *nameValid = [RACAbleWithStart(self.name) map:^(NSString *name) {
return @(name.length > 0);
}];
RACSignal *nameValidationMessage = [nameValid map:^ id (NSNumber *valid) {
return valid.boolValue ? nil : @"Please enter a name that matches our bullshit rules";
}];
// Check email validity
@vinhnx
vinhnx / pr.md
Created December 23, 2013 07:00 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@vinhnx
vinhnx / _.txt
Last active October 6, 2019 15:51 — forked from floriankugler/gist:6870499
Mapping of NSURLConnection to NSURLSession delegate methods. Created by Mattt Thompson.
NSURLConnection | NSURLSession
------------------------------------------------------------------------------------------------------------+------------------------------------
NSURLConnectionDelegate connectionShouldUseCredentialStorage: |
------------------------------------------------------------------------------------------------------------+------------------------------------
NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge: | NSURLSessionDelegate URLSession:didReceiveChallenge:completionHandler:
| NSURLSessionTaskDelegate URLSession:task:didReceiveChallenge:completionHandler:
------------------------------------------------------------------------------------------------------------+-
@interface UIView (MPAdditions)
@end
@implementation UIView (MPAdditions)
- (id)debugQuickLookObject {
if (self.bounds.size.width < 0.0f || self.bounds.size.height < 0.0f) {
return nil;
}
static NSString * BCP47LanguageCodeFromISO681LanguageCode(NSString *ISO681LanguageCode) {
if ([ISO681LanguageCode isEqualToString:@"ar"]) {
return @"ar-SA";
} else if ([ISO681LanguageCode hasPrefix:@"cs"]) {
return @"cs-CZ";
} else if ([ISO681LanguageCode hasPrefix:@"da"]) {
return @"da-DK";
} else if ([ISO681LanguageCode hasPrefix:@"de"]) {
return @"de-DE";
} else if ([ISO681LanguageCode hasPrefix:@"el"]) {