Skip to content

Instantly share code, notes, and snippets.

@bjhomer
bjhomer / keyDown.m
Last active August 29, 2015 14:04
Looking for the best way to use switch based on a single character. Seems like I have to convert everything to Int(), which can be very verbose.
-(void)keyDown:(NSEvent *)event
{
unichar ch = [[event charactersIgnoringModifiers] characterAtIndex:0];
if (ch == NSUpArrowFunctionKey && (event.modifierFlags & NSCommandKeyMask)) {
// Scroll to top
return;
}
else if (ch == NSDownArrowFunctionKey && (event.modifierFlags & NSCommandKeyMask)) {
// Scroll to bottom
//
// DOXLabelWrapper.m
// Autolayout
//
// Created by BJ Homer on 7/11/14.
// Copyright (c) 2014 BJ Homer. All rights reserved.
//
#import "DOXLabelWrapper.h"
@bjhomer
bjhomer / fish_prompt.fish
Last active August 29, 2015 14:03
My fish prompt
function fish_prompt --description 'Write out the prompt'
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
set -l delim '$'
switch $USER
// Does this code create 10000 live instances of MyObj before returning?
// Or will each one be released on the following iteration?
void foo() {
NSLog(@"Starting!");
int i=0;
start:
id obj = [MyObj new];
if (++i<10000) {
goto start;
@bjhomer
bjhomer / pprofile.py
Created June 25, 2014 16:39
A simple python script to more easily inspect provisioning profiles.
#! /usr/bin/python
import sys
import os
def main():
if len(sys.argv) < 2:
print "Usage: profile.py <path> | <UUID>"
sys.exit()
@bjhomer
bjhomer / capturing.swift
Last active May 21, 2016 03:57
Testing whether swift captures by value or by reference.
func testCapturing() -> () {
var x = 3
let c1 = { () -> () in
println( "unmodified x: \(x)")
}
let c2 = { () -> () in
x += 1
@bjhomer
bjhomer / gist:b633149338ed4114d2a8
Last active August 29, 2015 14:00
Requirements for a good UIAlertView+Blocks implementation
  1. Must have a method similar to -addButtonWithTitle:handler:
  2. Must still work if some buttons are added using the old -addButtonWithTitle: API.
  3. Must still allow setting a delegate, and the delegate must work.

Note that #2 means that handler blocks must not simply be added to an array and located by button index, as there may be more buttons than there are handlers. This is a common error in popular implementations.

@bjhomer
bjhomer / gist:8af670a31944b54bdfef
Last active August 29, 2015 14:00
Tokenizer comparison
Input: @"This is a puppy that is happy. 🐶❄️ = 😀🐶. 你好,我喜欢汉字。"
kCFStringTokenizerUnitWordBoundary results:
token:[This]
token:[ ]
token:[is]
token:[ ]
token:[a]
token:[ ]
token:[puppy]
@bjhomer
bjhomer / gist:9393869
Last active July 7, 2021 20:26
Starting and stopping VoiceOver from the terminal
//The very slow, but more semantically correct way
osascript -e 'tell application "VoiceOver" to activate'
osascript -e 'tell application "VoiceOver" to quit'
// The really fast way. (96 is the keycode for F5.)
osascript -e 'tell application "System Events" to key code 96 using command down'
@bjhomer
bjhomer / gist:8446132
Last active January 3, 2016 09:59
Positioning the center of viewB a fraction of the way along viewA
You can't do this directly, but it can be done by using a hidden spacer view. (Here, viewC)
viewC.left = viewA.left
viewC.width = viewA.width * multiplier
viewB.centerX = viewC.right
Produces this.
|----------viewA----------|
|-viewC-|