Skip to content

Instantly share code, notes, and snippets.

View nickdowell's full-sized avatar

Nick Dowell nickdowell

  • United Kingdom
View GitHub Profile
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
{
if (response != nil) {
[[self client] URLProtocol:self wasRedirectedToRequest:request redirectResponse:response];
}
return request;
}
@nickdowell
nickdowell / gist:2236186
Last active October 2, 2015 11:28
GetPluginBundle()
#include <CoreFoundation/CoreFoundation.h>
#include <dlfcn.h>
static CFBundleRef GetPluginBundle()
{
static CFBundleRef bundle;
if (bundle) {
return bundle;
}
@nickdowell
nickdowell / gist:4492320
Created January 9, 2013 11:01
parsing query parameters from an NSURL
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]];
}
#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 April 8, 2013 13:18
mkv to mp4 conversion (no transcoding) using ffmpeg
ffmpeg -loglevel verbose -i input.mkv -acodec copy -vcodec copy output.mp4
@nickdowell
nickdowell / gist:5678403
Created May 30, 2013 14:44
bash aliases
alias bbc6music='open -a "QuickTime Player" $(curl -s http://www.bbc.co.uk/radio/listen/live/r6_aaclca.pls | grep File1= | sed s/File1=//)'
void UIViewRecurse(UIView *view, void (^ apply)(UIView *subview))
{
static void (^ recurse)(UIView *subview, void (^ apply)(UIView *subview)) = nil;
if (recurse == nil)
recurse = ^(UIView *subview, void (^ apply)(UIView *subview)){
apply(subview);
for (UIView *v in subview.subviews)
recurse(v, apply);
};
recurse(view, apply);
#!/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"
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 August 29, 2015 14:01
automount configuration 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