Skip to content

Instantly share code, notes, and snippets.

View wjlafrance's full-sized avatar
🐶
Wondering if Github is becoming a social network.

William LaFrance wjlafrance

🐶
Wondering if Github is becoming a social network.
View GitHub Profile
WORKSPACE = "MyAwesomeProject.xcworkspace"
SCHEME = "MyAwesomeProjectScheme"
CONFIGURATION = debug
TARGET_BUILD_DIR = ./build
BINARY = $(TARGET_BUILD_DIR)/MyAwesomeProject.app
IPA = MyAwesomeProject.ipa
# fill in from https://testflightapp.com/api/doc/
TF_API_TOKEN = ''
TF_TEAM_TOKEN = ''
@wjlafrance
wjlafrance / gist:2249975
Created March 30, 2012 08:51
Use you a CFUUID! No ARC for you!
NSString *uuid = [[NSUserDefaults standardUserDefaults] stringForKey:@"CFUUID"];
if (!uuid) {
CFUUIDRef cfuuid = CFUUIDCreate(NULL);
uuid = [(NSString *)CFUUIDCreateString(NULL, cfuuid) autorelease];
[[NSUserDefaults standardUserDefaults] setValue:uuid forKey:@"CFUUID"];
[[NSUserDefaults standardUserDefaults] synchronize];
CFRelease(cfuuid);
}
@wjlafrance
wjlafrance / gist:2466303
Created April 22, 2012 19:25
Processing pixels stored in 32-bit integers as AARRGGBB to create a negative image
//Slow:
int r = (pixels[i] & 0x00FF0000 >> 16) * -1 + 255;
int b = (pixels[i] & 0x0000FF00 >> 8) * -1 + 255;
int g = (pixels[i] & 0x000000FF) * -1 + 255;
pixels[i] = r << 16 | b << 8 | g;
//Fast:
pixels[i] ^= 0x00FFFFFF;
@wjlafrance
wjlafrance / ram.sh
Created May 3, 2012 20:12
Memory usage
total=`sysctl hw.memsize | awk '{print $2}'`
total=`echo $total / 1024 | bc`
physmem=`top -l 1| grep PhysMem: | sed s/M/*1024/g`
#wired=` echo $physmem | awk '{print $2}' | bc`
#active=` echo $physmem | awk '{print $4}' | bc`
#inactive=`echo $physmem | awk '{print $6}' | bc`
used=` echo $physmem | awk '{print $8}' | bc`
free=` echo $physmem | awk '{print $10}' | bc`
//
// ExternalViewController.m
//
// Created by William LaFrance.
// Public Domain
//
#import "ExternalViewController.h"
@interface ExternalViewController ()
Memory management in C
void *malloc(size_t size);
Allocates size bytes of memory
void *calloc(size_t count, size_t size);
Allocate count times size
void *realloc(void *ptr, size_t size);
malloc's size, copies memory, frees old pointer
Class newClass = NSClassFromString(@"UINewClassThatYouCantHave");
if (newClass) {
NSLog(@"We're on an iOS that has the new class");
id newObject = [[newClass alloc] init];
if ([self respondsToSelector:@selector(selectorThatUsesNewObject:)])
[self performSelector:@selector(selectorThatUsesNewObject:) withObject:newObject];
} else {
NSLog(@"Class doesn't exist!");
}
@wjlafrance
wjlafrance / gist:3382305
Created August 17, 2012 20:22
Retain and release!
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
struct SObject
{
uint32_t retainCount;
void *buffer;
};
jruby-1.6.7.2 :014 > multiplier = 1.0 / 3.0
=> 0.333333333333333
jruby-1.6.7.2 :015 > multiplier * 3
=> 1.0
# list largest files on your hard drive, down to a certain depth, ordered by size
find / -type f -maxdepth 3 -exec du {} \; | sort -n -r > ~/usage.txt