Skip to content

Instantly share code, notes, and snippets.

View iosdevzone's full-sized avatar

idz iosdevzone

View GitHub Profile
@iosdevzone
iosdevzone / gist:5676451
Created May 30, 2013 08:17
Leveraging the preprocessor to lessen boilerplate. L(X) is the crux. It allows the me to apply different transformations over the same list.
#define S(_s) @selector(application##_s:) // selector generator
#define N(_n) UIApplication##_n##Notification // name generator
#define L(X) X(WillResignActive), X(DidEnterBackground), \
X(WillEnterForeground), X(DidBecomeActive), X(WillTerminate) // apply X over list
#define C(_a) sizeof((_a))/sizeof((_a)[0]) // array count
- (void)monitorAppState:(BOOL)start
{
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
@iosdevzone
iosdevzone / icons.rb
Created June 7, 2013 03:08
A ruby script to produce an Objective C literal from the information in FontAwesome's icons.yml file.
#
# Ruby Script to convert FontAwesome
# glyph information into Objective-C literals
# (Ends up being a big array of NSDictionary objects)
# Output is to stdout. Assumes icons.yml is in working directory.
# Copyright (c) 2013 iOSDeveloperZone.com
# MIT license -- See: http://opensource.org/licenses/MIT
require 'yaml'
#
/*
CommonHMac defines the following enumeration
enum {
kCCHmacAlgSHA1,
kCCHmacAlgMD5,
kCCHmacAlgSHA256,
kCCHmacAlgSHA384,
kCCHmacAlgSHA512,
kCCHmacAlgSHA224
@iosdevzone
iosdevzone / CommonCryptoHack
Created September 21, 2014 03:14
A shell script to write a dummy CommonCrypto.framework module into the directory where playgrounds look for frameworks.
#!/bin/bash
if [[ $BASH_SOURCE != $0 ]]; then echo "$BASH_SOURCE must be executed, not sourced."; return 255; fi
#
# A script to fool iOS playgrounds into allowing access to CommonCrypto
#
# The script creates a dummy CommonCrypto.framework in the SDK's System
# Framework Library Directory with a module map that points to the
# umbrella header
#
# Usage:
@iosdevzone
iosdevzone / Foo2.swift
Created October 2, 2014 00:18
File to demonstrate very slow compilation times on swift when string concatenation operator used rather than string interpolation.
class Foo
{
let a = "a"
let b = "b"
let c = "c"
let values = [ "A", "B", "C", "D", "E" ]
var rawValues: String
{
let a = self.a
/* ==== KeychainItem.swift === */
public class KeychainItem {
public var dictionary : KeychainDictionary
public init() {
self.dictionary = KeychainDictionary()
}
public init(dictionary: KeychainDictionary) {
OS X 10.10.1/Xcode 6.3 6D520o
inu:Radars idz$ swiftc main.swift
inu:Radars idz$ ./main -radar "is fixed"
[radar: is fixed]
- (void)drawRect:(CGRect)rect {
[[UIColor lightGrayColor] setFill];
[[UIColor darkGrayColor] setStroke];
UIBezierPath *path = [[UIBezierPath alloc] init];
CGPoint touchPoint = [self.lastTouch locationInView:self];
CGFloat y0 = self.bounds.origin.y;
CGFloat weight = 0.75; // Vary from 0 - 1. Values closed to 1 are more pointy.
CGFloat y1 = y0 + (touchPoint.y - y0) * weight; // between top of screen and touch
CGFloat y2 = touchPoint.y;
CGFloat y4 = CGRectGetMaxY(self.bounds);
@iosdevzone
iosdevzone / gist:fb06b61dab4ec2dc1801
Created May 22, 2015 22:06
Filtering array based on indexSet
func objectsAtIndexes<T:AnyObject>(array: [T], indexes:NSIndexSet) -> [T]
{
return ((array as NSArray).objectsAtIndexes(indexes) as [T])
}
@iosdevzone
iosdevzone / BasicAuthPlaygroundSeed.swift
Last active September 19, 2015 11:09
Minimal Basic Authentication Demo. Paste into playground & replace username and password. You must be on GitHub for this to work.
import Foundation
let username = "username"
let password = "password"
let base = "https://api.github.com"
let user = "\(base)/user"
let url = NSURL(string: user)
let request = NSMutableURLRequest(URL: url!)