Skip to content

Instantly share code, notes, and snippets.

View Machx's full-sized avatar

Colin Wheeler Machx

View GitHub Profile
#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.
*
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];
@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); };
@Machx
Machx / gist:4053388
Created November 11, 2012 02:17
CWErrorSet()
//NSError **error...
if(CWErrorSet(true, ^NSError *{
return CWCreateError(@"domain", 404, @"error message"); }, error)) {
return nil;
}
// alternate formatting
if (CWErrorSet(YES, ^NSError *{
@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 / Go.sublime-build
Created August 19, 2012 16:55
Go Sublime Text 2 Build System
{
"cmd": ["/usr/local/go/bin/go","build","$file"],
"selector" : "source.go",
"variants": [
{ "cmd": ["/usr/local/go/bin/go", "run", "$file"],
"name": "Run"
}
]
}
@Machx
Machx / crash-catching.m
Created June 23, 2012 21:58
Objective-C Crash Catching in 1992
// ObjectError.h -- Subclass of Object which handles errors.
// Copyright (c) 1992 by Proponent, Inc. All rights reserved.
// To make this work, the application must send a "setup" message
// to the class. This will poseAs: object and intercept a number of things.
#import <objc/Object.h>
@interface ObjectError : Object
@Machx
Machx / test.m
Created May 30, 2012 17:56
dispatch_queue_t size vs NSOperationQueue size
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
printf("dispatch_queue_t size: %lu bytes\n",sizeof(dispatch_queue_t));
printf("NSOperationQueue size: %lu bytes\n", class_getInstanceSize([NSOperationQueue class]));
}
return 0;
@Machx
Machx / test.m
Created April 1, 2012 21:04
Test isEqual & isEqualToString V2
#import <Foundation/Foundation.h>
#include <sys/sysctl.h>
#include <unistd.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#import <stdarg.h>
#import <mach/mach.h>
#import <mach/mach_time.h>
#import <unistd.h>
@Machx
Machx / results.txt
Created March 30, 2012 16:43
Test isEqual & isEqualToString
tail end of the results
2012-03-30 11:36:39.865 Untitled[78506:707] IsEqual: 1438 | isEqualToString 589
2012-03-30 11:36:39.875 Untitled[78506:707] IsEqual: 1377 | isEqualToString 590
2012-03-30 11:36:39.876 Untitled[78506:707] IsEqual: 956 | isEqualToString 560
2012-03-30 11:36:39.877 Untitled[78506:707] IsEqual: 860 | isEqualToString 451
2012-03-30 11:36:39.877 Untitled[78506:707] IsEqual: 824 | isEqualToString 433
2012-03-30 11:36:39.878 Untitled[78506:707] IsEqual Average 1212 - IsEqualToString Average 619