Skip to content

Instantly share code, notes, and snippets.

@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)
@kimhunter
kimhunter / export_stashes.rb
Created August 17, 2011 23:24
Export Git stashes
require "yaml"
stash_list = `git stash list`.chomp.split("\n").map {|i| i.chomp }
stash_list.map!{|s|
b = s.match(/stash@\{([0-9]+)\}: (.*)/)
[b[1], b[2]]
}
stash_list.each do |s|
puts "{#{s[0]}}"