Skip to content

Instantly share code, notes, and snippets.

View update_loc_xibs.sh
#!/bin/bash
set -o errexit
set -o pipefail
langs=(de es fr pt)
for path in en.lproj/*.xib; do
git diff --quiet $path && git diff --cached --quiet $path || {
echo -n "updating localizations for $path"
View ParseMobileProvision.m
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]];
const char *ptr = [data bytes], *start = NULL, *end = NULL;
for (size_t i = 0; i < [data length] - 8; i++) {
if (memcmp(ptr + i, "<plist", 6) == 0) {
start = ptr + i;
}
if (memcmp(ptr + i, "</plist>", 8) == 0) {
end = ptr + i + 8;
}
}
@nickdowell
nickdowell / auto_examples
Last active Aug 29, 2015
automount configuration examples
View auto_examples
# /etc/auto_examples
afp_vol -fstype=afp afp://user:password@server/afp_vol
smb_vol -fstype=smbfs ://user:password@server/smb_vol
#note: no password can be specified for NFS
nfs_vol server:/nfs_vol
View ReadEntitlementsFromCodeSignature.m
#import <dlfcn.h>
#import <mach-o/dyld.h>
#import <mach-o/loader.h>
int main(int argc, char *argv[]) {
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] executablePath]];
NSData *codeSignatureData = nil;
View ios_device_lockstate.m
#import <Foundation/Foundation.h>
#import <notify.h>
void test()
{
int notify_token;
notify_register_dispatch("com.apple.springboard.lockstate", &notify_token, dispatch_get_main_queue(), ^(int token) {
uint64_t state = UINT64_MAX;
notify_get_state(token, &state);
NSLog(@"com.apple.springboard.lockstate = %llu", state);
@nickdowell
nickdowell / gist:2236186
Last active Oct 2, 2015
GetPluginBundle()
View gist:2236186
#include <CoreFoundation/CoreFoundation.h>
#include <dlfcn.h>
static CFBundleRef GetPluginBundle()
{
static CFBundleRef bundle;
if (bundle) {
return bundle;
}
@nickdowell
nickdowell / gist:4492320
Created Jan 9, 2013
parsing query parameters from an NSURL
View gist:4492320
NSMutableDictionary *queryParameters = [NSMutableDictionary dictionary];
for (NSString *string in [[URL query] componentsSeparatedByString:@"&"]) {
NSArray *array = [string componentsSeparatedByString:@"="];
if ([array count] == 2)
[queryParameters setObject:[array objectAtIndex:1] forKey:[array objectAtIndex:0]];
}
View coremidi_virtual_source.c
#include <assert.h>
#include <CoreMIDI/CoreMIDI.h>
char buffer[1024];
MIDIClientRef client = 0;
MIDIEndpointRef endpoint = 0;
MIDIPacketList *packetList = (void *)buffer;
MIDIPacket *packet = 0;
MIDIPortRef port = 0;
@nickdowell
nickdowell / gist:5336704
Created Apr 8, 2013
mkv to mp4 conversion (no transcoding) using ffmpeg
View gist:5336704
ffmpeg -loglevel verbose -i input.mkv -acodec copy -vcodec copy output.mp4
View gist:5678403
alias bbc6music='open -a "QuickTime Player" $(curl -s http://www.bbc.co.uk/radio/listen/live/r6_aaclca.pls | grep File1= | sed s/File1=//)'