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
[11:42:38] [william@home ~]$ cat ~/bin/gitstat
#!/bin/bash
echo "working: `git diff | grep ^\- | wc -l | tr -d ' '` deletions, `git diff | grep ^\+ | wc -l | tr -d ' '` insertions"
echo "staged: `git diff --cached | grep ^\- | wc -l | tr -d ' '` deletions, `git diff --cached | grep ^\+ | wc -l | tr -d ' '` insertions"
@wjlafrance
wjlafrance / gist:3747142
Created September 19, 2012 01:43
Dot notation, you say?
(self = super.init).foo = bar;
@wjlafrance
wjlafrance / gist:4013407
Created November 4, 2012 20:04
delete node from linked list
#import <stdio.h>
#import <stdlib.h>
typedef struct node_s {
struct node_s *next;
void *data;
} node_t;
typedef node_t list_t;
list_t * populateList() {
// writing
[object setValue:[NSData dataWithBytes:&rect length:sizeof(rect)] forKey:@"rect"];
// reading
CGRect rect;
[[object valueForKey:@"rect"] getBytes:&rect];
#import <CoreFoundation/CoreFoundation.h>
void DescribeCFObject(CFTypeRef cfobject)
{
CFStringRef description = CFCopyDescription(cfobject);
printf("%s\n", CFStringGetCStringPtr(description, CFStringGetSystemEncoding()));
CFRelease(description);
}
const void *RetainCFObjectForCFArray(CFAllocatorRef allocator, const void *object)
#import <stdio.h>
int main(int argc, char **argv) {
void(^doHello)() = ^{
printf("Hello\n");
};
doHello();
return 0;
}
class MsgSend
{
/**
* Dynamically invoke a method, much like Objective-C message sending.
*
* This will ignore access restrictions, much like in Objective-C.
* Invoking private methods on other classes may cause harmful side-effects.
*
* @param object The object to "pass the message" to. If this is null,
* the result is always null.
// Hello world isn't hard.
jclass javaLangSystem = env->FindClass("java/lang/System");
jfieldID javaLangSystemOut = env->GetStaticFieldID(javaLangSystem, "out", "Ljava/io/PrintStream;");
jobject out = env->GetStaticObjectField(javaLangSystem, javaLangSystemOut);
jmethodID javaIoPrintStreamPrintln = env->GetMethodID(env->GetObjectClass(out), "println", "(Ljava/lang/String;)V");
jstring helloJava = env->NewStringUTF("Hello Java!");
env->CallVoidMethod(out, javaIoPrintStreamPrintln, helloJava);
@wjlafrance
wjlafrance / NSPredicate+KeyValue.h
Created February 16, 2013 19:39
A simple NSPredicate such as "username == wjl" can be parsed as a key-value pair.
//
// NSPredicate+KeyValue.h
// IncrementalAppnet
//
// Created by William LaFrance on 2/16/13.
//
#import <Foundation/Foundation.h>
@interface NSPredicate (KeyValue)
//
// AppUniqueIdentifier.h
// ReinstallationUdid
//
// Created by William LaFrance on 2/27/13.
// Copyright (c) 2013 William LaFrance. All rights reserved.
//
#import <Foundation/Foundation.h>