Skip to content

Instantly share code, notes, and snippets.

@kimhunter
kimhunter / testSeeEl.c
Last active December 20, 2015 01:29
Test if any OpenCL GPU device is available.
//
// main.cpp
// testSeeEl
//
// Created by Kim on 21/07/2013.
// Copyright (c) 2013 Kim. All rights reserved.
//
//
// clang -framework OpenCL -o testSeeEl testSeeEl.c && ./testSeeEl
//
@kimhunter
kimhunter / wwdc_rename.rb
Created June 18, 2013 04:28
WWDC2013 session video renaming script
require 'nokogiri'
doc = Nokogiri::HTML(File.open("Videoswwdc.html"))
items = {}
doc.xpath("//li[@class='session']").each do |session|
session_id = session['id'].sub('-video', '').to_i
title = session.children.xpath("li[@class='title']").text
items[session_id] = title
end
@kimhunter
kimhunter / missing_vids.rb
Created June 18, 2013 04:32
Missing wwdc2013 videos from my own renaming format
require 'nokogiri'
doc = Nokogiri::HTML(File.open("Videoswwdc.html"))
items = {}
doc.xpath("//li[@class='session']").each do |session|
session_id = session['id'].sub('-video', '').to_i
title = session.children.xpath("li[@class='title']").text
items[session_id] = title
end
@kimhunter
kimhunter / block_op.m
Last active December 17, 2015 21:29
Operation Queue with in block cancellation
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool
{
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 1;
__block NSBlockOperation *operation = [[NSBlockOperation alloc] init];
@kimhunter
kimhunter / wwdc2012check.rb
Created April 22, 2013 21:27
wwdc 2012 cron check
#!/usr/bin/env ruby
require 'open-uri'
require 'date'
require 'nokogiri'
URL = "https://developer.apple.com/wwdc/"
MP3 = "~/Projects/wwdc-check/giants.mp3"
found = false
def wwdc_is_here
@kimhunter
kimhunter / gist:4535555
Created January 15, 2013 02:37
How to make dock icon clicks reopen your application.
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)visibleWindows
{
if (!visibleWindows)
{
// do what ever here to reopen your window
[[CoverStoryDocumentController sharedDocumentController] openDocument:self];
return NO;
}
return YES;
}
@kimhunter
kimhunter / compare_dispatch_apply.m
Created November 6, 2012 22:56
Compare Dispatch Concurrent to for loop
#import <Foundation/Foundation.h>
#define LOGV(V) NSLog(@"%s = %@", #V, V);
#define LOGD(I) NSLog(@"%s = %d", #I, I);
int main(int argc, const char * argv[])
{
@autoreleasepool
{
dispatch_queue_t dqueue = NULL;
@kimhunter
kimhunter / callme.applescript
Created April 26, 2012 13:16
Call someone with Skype
property phoneNumber : "55522332"
tell application "Skype" to activate
delay 20
tell application "System Events"
tell application process "Skype"
try
tell window "Dial Pad" to click
tell window "Dial Pad"
keystroke phoneNumber
click button "Call"
@kimhunter
kimhunter / merge_sort.rb
Created October 13, 2011 15:08
Merge sort ruby
#!/usr/bin/env ruby
# 2011-10-10 20:57:53 +1000
def merge_sort a
return a if a.size <= 1
l,r = split_array a
result = combine merge_sort(l), merge_sort(r)
end
def split_array a
@kimhunter
kimhunter / kmprofile.m
Created October 1, 2011 06:10
objective-c code inline code block profiling
#define KMProfile(MSG, CODE_TO_PROFILE) { \
NSDate *KMStartDate = [NSDate date]; \
NSTimeInterval KMduration; \
CODE_TO_PROFILE \
KMduration = [[NSDate date] timeIntervalSinceDate:KMStartDate]; \
NSLog(@"KMProfile: %@ TOOK %.0lfms (%.1lfs) ", MSG,(KMduration*1000) , KMduration); \
}
// Usage: (works well with something a bit more intensive but you get the gist)