Skip to content

Instantly share code, notes, and snippets.

View Machx's full-sized avatar

Colin Wheeler Machx

View GitHub Profile
#!/usr/bin/python
# Nicolas Seriot
# 2011-01-06
# https://gist.github.com/768457
"""
Input: path of an Objective-C project
@Machx
Machx / gist:836685
Created February 21, 2011 05:18 — forked from Abizern/gist:836472
#!/usr/bin/python
import sys
import os
from collections import defaultdict
import hashlib
theRoot = '/Volumes/Stuff/Files/'
theTrashFolder = '/Volumes/Stuff/Trash/'
@Machx
Machx / gist:838075
Created February 22, 2011 01:41 — forked from mikeash/gist:837409
// NSURLConnection wrapper
// like NSURLConnection, requires a runloop, callbacks happen in runloop that set up load
@interface LDURLLoader : NSObject
{
NSURLConnection *_connection;
NSTimeInterval _timeout;
NSTimer *_timeoutTimer;
NSURLResponse *_response;
long long _responseLengthEstimate;
NSMutableData *_accumulatedData;
@Machx
Machx / gist:1164123
Created August 23, 2011 01:49
Mask based CALayer hit testing
#import "CALayer_HitTestExtensions.h"
#import <objc/runtime.h>
static void *kHitMask;
@implementation CALayer (CALayer_HitTestExtensions)
- (NSUInteger)hitMask
{
@Machx
Machx / gist:1452465
Created December 9, 2011 17:23
NSNumberWithValue function overloading in C
//
// NSNumber_Extensions.h
// TouchCode
//
// Created by Jonathan Wight on 12/8/11.
// Copyright (c) 2011 TouchCode. All rights reserved.
//
#import <Foundation/Foundation.h>
@Machx
Machx / gist:1950460
Created March 1, 2012 15:19 — forked from ddribin/gist:1946836
Animating with Autolayout
// Find out where the frames will be with the "after" layout
1. Remove the "before" constraints
2. Add the "after" constraints
3. Call [window layoutIfNeeded], to force the frames to update
4. Grab the frames of all the views I want to animate and save them off
// Go back to what the user sees
5. Remove the "after" constraints
6. Add the "before" constraints
7. Call [window layoutIfNeeded], to force the frames to update
@Machx
Machx / app_scanner.py
Created October 7, 2012 16:38
Look for iPhone apps that you have in iTunes on your Mac but not installed on any device...
#!/usr/bin/python
import zipfile
import glob
import fnmatch
import sys
import json
import os
import Foundation
@Machx
Machx / gist:4179161
Created November 30, 2012 22:29
Objc Blocks & C++ auto
// 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); };
self.startButton.rac_command = [RACCommand command];
self.stopButton.rac_command = [RACCommand command];
__unsafe_unretained id weakSelf = self;
id<RACSignal> tick = [[[[self.startButton.rac_command
map:^(id _) {
RTAFirstView *strongSelf = weakSelf;
// Map each start button click to a new signal that fires every second
// and stops when the stop button is clicked.
return [[RACSignal interval:1] takeUntil:strongSelf.stopButton.rac_command];
#import <Foundation/Foundation.h>
// Adapted from http://stackoverflow.com/a/11068850
/**
* @brief convert a hexidecimal string to a signed long
* will not produce or process negative numbers except
* to signal error.
*
* @param hex without decoration, case insensative.
*