Skip to content

Instantly share code, notes, and snippets.

@pcperini
pcperini / gist:2091808
Created March 19, 2012 02:48
Port CSV to JSON
import sys
import json
raw_data = open(sys.argv[1]).read().split('\r\n')
csv_headers = raw_data[0].split(',')
csv_data = [piece.split(',') for piece in raw_data[1:]]
json_data = []
for csv_datum in csv_data:
json_datum = {}
@pcperini
pcperini / Objectify.h
Created March 22, 2012 03:18
Quickly Make Objects out of Primitives
//
// Objectify.h
//
// Created by Patrick Perini on 3/21/12.
// Copyright (c) 2012 Inspyre Technologies. MIT License
//
#import <Foundation/Foundation.h>
id __objectify__(char *type, ...);
@pcperini
pcperini / UIAlertView+Blocks.h
Created March 22, 2012 20:37
Create Block-Based UIAlertViews Without the Hassle
//
// UIAlertView+Blocks.h
//
// Created by Patrick Perini on 3/22/12.
// Copyright (c) 2012 Inspyre Technologies. MIT License.
//
#import <UIKit/UIKit.h>
@interface UIAlertView (Blocks) <UIAlertViewDelegate>
@pcperini
pcperini / gist:2829951
Created May 29, 2012 18:41
Quick (NS|UI)ViewController Loading
// .h
#if !TARGET_OS_IPHONE
#import <Cocoa/Cocoa.h>
#define APPLViewController NSViewController
#else
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#define APPLViewController UIViewController
#endif
@pcperini
pcperini / gist:2889493
Created June 7, 2012 15:37
Hashing Functions in Multiple Languages / Environments
// # Assume salt, password, and encodedPassword are all strings.
// # If you don't have a salt, just have a random number generator spit out > 16B of data, and turn that into a string.
// Java - SHA256 with Salt
import java.security.MessageDigest;
import sun.misc.BASE64Encoder;
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.reset();
@pcperini
pcperini / async.py
Created June 13, 2012 20:38
Run Methods Asynchronously with a Simple Decorator
import threading
def _async(func, *a, **kw):
thread = threading.Thread(target = func, args = a, kwargs = kw)
thread.start()
return thread
def async(func):
return lambda *a, **kw: _async(func, *a, **kw)
@pcperini
pcperini / eeroc.py
Created July 9, 2012 14:56
Get Up and Running with eero - get_eero to install, eeroc to compile/build
#!/usr/bin/python
import os
import sys
import subprocess
from optparse import OptionParser
# Superglobal Variables
TERMINAL_FORMATTERS = {
"BOLD": "\033[1m",
@pcperini
pcperini / demo.eero
Created July 10, 2012 01:23
eero Demo
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
interface FileHelper : Object // "Object" is the same as "NSObject"
property (readonly)
String volumeName // both are readonly properties
String volumeFormat //
+ pathStringWithComponents: Array, return String // class method
@pcperini
pcperini / NSNumber+Ranges.m
Created July 21, 2012 16:34
Quick Ranges from NSNumbers
// .h
@interface NSNumber (Ranges)
- (NSRange)to:(NSNumber *)rangeEnd;
- (BOOL)isInRange:(NSRange)range;
@end
// .m
@implementation NSNumber (Ranges)
@pcperini
pcperini / gist:3941614
Last active October 12, 2015 00:17
Objective-C Style Guide

General

Follow ALL Apple Naming Conventions!

Whitespace

  • Spaces, not tabs.

Documentation

  • Comments should be hard-wrapped at 80 characters.