Skip to content

Instantly share code, notes, and snippets.

@bjhomer
bjhomer / class_name_ideas.md
Last active December 28, 2015 08:59
Naming things is hard

Naming things is hard

So let's work together

Instead of having one controller object that does everything, I've been trying to split things out into various task-focused. This means I have to come up with names for these objects, such as "CoverAnimationDriver", etc. Naming things is hard, so I want your help. Aside from domain-specific bag-of-properties model objects, what nouns have you used in class names? In my experience, these are usually used as a suffix on the class name.

Here's what I've come up with so far:

  • View
  • Controller
  • Manager
  • Data Source
@bjhomer
bjhomer / delay.m
Last active December 29, 2015 09:29
An ObjC-level equivalent to dispatch_after
[[NSOperationQueue mainQueue] addOperationAfterDelay:2 withBlock:^{
NSLog(@"I'm in the future!");
}];
@bjhomer
bjhomer / glyph_crash.md
Last active December 30, 2015 20:39
Any idea what could cause this crash?

A user is reporting a crash, and I cannot see how it could possibly be happening.

The code in question (in frame #18 below) is this:

NSFont *font = [NSFont fontWithName:@"Helvetica Neue" size:13];
// some other code
NSGlyph typicalGlyph = [font glyphWithName:@"e"];
@bjhomer
bjhomer / gist:8047113
Last active December 31, 2015 21:29
I lived in Spain for two years, but don't speak it regularly any more. So it's possible I've missed the nuance in a word here or there. The overall content is correct, though.

Biscuit, the app that returns "beautiful" to Reddit.

Although Reddit is one of the most important communities in the Internet, its aesthetics might lead you to believe otherwise. To fix this problem, an app has been created.

We're talking about Biscuit, an app for iPad that profoundly changes the appearance of this social news website.

Reddit is a platform that allows any person to upload images, share news, or create topics for community debate. Other users can comment and contribute to the topic.

Biscuit transforms all this disorder into something more pleasant to the eyes. Following the minimalist line of Apple's products, it intends to organize all the articles and categories.

@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-|
@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: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: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 / 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 / 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()