Skip to content

Instantly share code, notes, and snippets.

View vinhnx's full-sized avatar
🍀
learn by doing

Vinh Nguyen vinhnx

🍀
learn by doing
View GitHub Profile
@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 / 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 / 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
//
// UIImageCreateUsingBlock.m
//
// Copyright (c) 2013 Zachary Waldowski.
// Licensed under MIT - Provided as-is.
//
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
// 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); };
#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;
@vinhnx
vinhnx / antischwa.cfg
Last active January 1, 2016 02:59
Uncrustify script that (no guarantees) matches twitter's internal obj-c style guide | Install uncrustify via home-brew
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.4.3 (252)
#
# Alignment
# ---------
## Alignment
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.4.3 (252)
#
# Alignment
# ---------
## Alignment
@vinhnx
vinhnx / objcabbr.mm
Created December 22, 2013 13:14 — forked from atg/objcabbr.mm
// Created by Alex Gordon on 11/02/2013.
#import <Foundation/Foundation.h>
#pragma mark Objects
static BOOL respondsTo(id x, SEL s) {
if (!x || !s)
return NO;
return [x respondsToSelector:s];

List of Block Declaration Syntaxes

Throughout, let

  • return_type be the type of object/primitive/etc. you'd like to return (commonly void)
  • blockName be the variable name of the block you're creating
  • var_type be the type object/primitive/etc. you'd like to pass as an argument (leave blank for no parameters)
  • varName be the variable name of the given parameter And remember that you can create as many parameters as you'd like.

Blocks as Variables

Possibly the most common for of declaration.