Skip to content

Instantly share code, notes, and snippets.

View Machx's full-sized avatar

Colin Wheeler Machx

View GitHub Profile
@Machx
Machx / gist:1950460
Created March 1, 2012 15:19 — forked from ddribin/gist:1946836
Animating with Autolayout
// Find out where the frames will be with the "after" layout
1. Remove the "before" constraints
2. Add the "after" constraints
3. Call [window layoutIfNeeded], to force the frames to update
4. Grab the frames of all the views I want to animate and save them off
// Go back to what the user sees
5. Remove the "after" constraints
6. Add the "before" constraints
7. Call [window layoutIfNeeded], to force the frames to update
@Machx
Machx / bluetooth.osa
Created February 6, 2012 02:24
Turn on Bluetooth via CLI
#from http://apple.stackexchange.com/questions/35602/turn-on-bluetooth-via-terminal-command-line
# This is only necessary, if AppleScripts are not yet allowed to change checkboxes
tell application "System Events" to set UI elements enabled to true
# Now change the bluetooth status
tell application "System Preferences"
set current pane to pane id "com.apple.preferences.bluetooth"
tell application "System Events"
tell process "System Preferences"
# Enabled is checkbox number 2
if value of checkbox 2 of window "Bluetooth" is 0 then
@Machx
Machx / gist:1452465
Created December 9, 2011 17:23
NSNumberWithValue function overloading in C
//
// NSNumber_Extensions.h
// TouchCode
//
// Created by Jonathan Wight on 12/8/11.
// Copyright (c) 2011 TouchCode. All rights reserved.
//
#import <Foundation/Foundation.h>
@Machx
Machx / gist:1164123
Created August 23, 2011 01:49
Mask based CALayer hit testing
#import "CALayer_HitTestExtensions.h"
#import <objc/runtime.h>
static void *kHitMask;
@implementation CALayer (CALayer_HitTestExtensions)
- (NSUInteger)hitMask
{
@Machx
Machx / vlcOpenYouTube_chrome
Created May 13, 2011 22:15
Tell VLC To play the YouTube video in the active tab of Google Chrome
tell application "Google Chrome"
set vurl to get URL of active tab of first window
tell application "VLC"
activate
OpenURL vurl
fullscreen
play
end tell
end tell
@Machx
Machx / gist:947308
Created April 28, 2011 20:52
Compiler does not warn/error on missing var in NSString format
NSString *someVar = @"a String";
NSMutableString *myString = [[NSMutableString alloc] initWithFormat:@"%@ %@",someVar];
//or
NSMutableString *myString = [NSMutableString stringWithFormat:@"%@ %@",someVar];
//LLVM 2.0 does not warn you that you are missing a 2nd var in the format
@Machx
Machx / gist:935558
Created April 21, 2011 21:45
Rebuild Launch Services on Mac OS X
samurai% /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
@Machx
Machx / gist:838075
Created February 22, 2011 01:41 — forked from mikeash/gist:837409
// NSURLConnection wrapper
// like NSURLConnection, requires a runloop, callbacks happen in runloop that set up load
@interface LDURLLoader : NSObject
{
NSURLConnection *_connection;
NSTimeInterval _timeout;
NSTimer *_timeoutTimer;
NSURLResponse *_response;
long long _responseLengthEstimate;
NSMutableData *_accumulatedData;
@Machx
Machx / gist:836685
Created February 21, 2011 05:18 — forked from Abizern/gist:836472
#!/usr/bin/python
import sys
import os
from collections import defaultdict
import hashlib
theRoot = '/Volumes/Stuff/Files/'
theTrashFolder = '/Volumes/Stuff/Trash/'
#ifndef __clang_analyzer__
// source here
#endif