Skip to content

Instantly share code, notes, and snippets.

@boredzo
boredzo / Falsehoods about version numbers.md
Last active December 21, 2015 01:39
Falsehoods programmers believe about version numbers

All of the following statements are false.

  • Version numbers are either two or three numbers, separated by periods.
  • Version numbers are two or three numbers, separated by periods, optionally followed by “a” or “b” or “rc” and optionally another number.
  • Any valid combination of numbers separated by periods is a valid version number. (CFBundleVersion will disagree with you for sufficiently high numbers of digits. See also.)
  • Version numbers can be parsed as floating-point/decimal numbers.
    • OK, but at least the part before the “b” (or other letter) can be, right?
  • Version numbers increase monotonically (e.g., 0.6 will never be greater than 1.0).
  • The only valid non-release categories are development, alpha, beta, and release candidate.
  • The version number will be prominently displayed to the user (e.g., Windows 4.0).
@boredzo
boredzo / gist:6090585
Created July 26, 2013 17:16
Generic NSMenuItem/NSControl validation method, so you can implement a separate -validate<Action>: method for each action
//This validation method is completely generic; it dispatches to validate<Action>:, where <Action> is the item's action, duly initially-capitalized.
- (BOOL) validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item {
SEL action = [item action];
if (![self respondsToSelector:action]) {
//We don't respond to the action, so unconditionally return NO.
return NO;
}
/*Determine the selector of the message to send ourselves for actual validation.
*/
import requests
import os, re, sys
RE_SD_VIDEO = re.compile(
r'<a href="(http://devstreaming.apple.com/videos/wwdc/2013/[^"]*-SD.mov)')
RE_WEBVTT = re.compile(r'fileSequence[0-9]+\.webvtt')
# stdin: dump of https://developer.apple.com/wwdc/videos/
for l in sys.stdin:
m = RE_SD_VIDEO.search(l)
@boredzo
boredzo / gist:6035031
Created July 19, 2013 03:56
Logging module interface draft
/*Usage:
*
*[debugLog log:@"Hello world"];
*
*Only logs anything in debug builds:
*[debugLogOptional log:@"Fetched items: %lu", items.count];
*
*/
@interface PRHLogger: NSObject
@boredzo
boredzo / @output.txt
Last active December 19, 2015 12:19
Program to determine how many microSD cards fit in the space of one Apple ProFile hard drive, and their total capacity
microSDs that fit in the space of a ProFile hard drive: 11 across * 10 up * 88 deep = 9680
Total volume: 1597200.000000 cubic mm / 1.597200 liters
Total capacity (at 64 GiB per card): 619520 GiB / 605 TiB
Total capacity as percentage of 5 MB ProFile: 133040906.960896%
Total capacity as percentage of 10 MB ProFile: 66520453.480448%
Weight of Apple ProFile hard drive: 5 kg
Total weight of microSD cards: 2.420000 kg
import requests
import os, re, sys
RE_SD_VIDEO = re.compile(
r'<a href="(http://devstreaming.apple.com/videos/wwdc/2013/[^"]*-SD.mov)')
RE_WEBVTT = re.compile(r'fileSequence[0-9]+\.webvtt')
# stdin: dump of https://developer.apple.com/wwdc/videos/
for l in sys.stdin:
m = RE_SD_VIDEO.search(l)
@boredzo
boredzo / gist:5855476
Created June 25, 2013 02:36
Summary of CPU Usage cached-drawing code
https://bitbucket.org/boredzo/cpu-usage/src/c7100209293b37d9df4142441eee51ef0fcac7ce/CPUUsageView.m?at=modernization
This object (CPUUsageView) is an NSView subclass that draws, among other things, a percentage (0%–100%). To do this, it has, among other things, a C array of 101 blocks (closures).
When -reinitializeCache is called (upon changing the colors, frame rectangle, etc.), every location in the array is set to the same block, called the “slow path” block.
When the “slow path” block is called (by drawRect:, which is called by the system whenever the view needs to draw), the slow path block:
- Creates all of the objects needed to draw—interpolated colors, a framesetter object for fast, mid-level text drawing, etc.
- Creates a new block, the “fast path” block, specifically for this percentage. Blocks capture anything they use, so the fast path block captures all of those colors, framesetters, etc., and keeps them without any need of instance variables besides the array of blocks. (And indeed I used to
@boredzo
boredzo / wwdc2013index-redacted.txt
Last active December 18, 2015 12:59
Script to rename WWDC videos and slides PDFs to include the session title in the name. Also included: A list of the session numbers and (redacted where necessary) titles, in TSV format, for use with this script.
100 Keynote
101 Platforms State of the Union
102 Apple Design Awards
109 Painting the Future
200 Accessibility in OS X
201 Building User Interfaces for iOS 7
202 Accessibility in iOS
203 What’s New in Cocoa Touch
204 What’s New with Multitasking
205 What’s New in Cocoa
@boredzo
boredzo / PRHAngleGradientFilter.h
Created June 1, 2013 21:48
Core Image custom filter to generate an angular gradient. The center is at the origin (0,0). You may want to use CIAffineTransform and/or CICrop on the output.
//
// PRHAngleGradientFilter.h
//
// Created by Peter Hosey on 2013-01-30.
// Copyright (c) 2013 Peter Hosey. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
@interface PRHAngleGradientFilter : CIFilter
@boredzo
boredzo / PRHOverlayLayer.m
Created May 9, 2013 01:31
Method that implements Python-style string formatting in NSString.
//Formats a string in which format specifiers look like %(key)@, similar to Python's %(key)s.
//Currently does not work with any other specifiers (i/d/u/x/f/g/e/s/c/C) or formatting guidance (space-padding, justification, etc.), and probably will never allow mixing positional and keyed format specifiers, just as Python doesn't.
- (NSString *) stringWithFormat:(NSString *)format values:(NSDictionary *)values {
NSRegularExpression *regularExpression = [NSRegularExpression regularExpressionWithPattern:@"%\\(([a-z_][a-z0-9_]*)\\)@"
options:NSRegularExpressionCaseInsensitive
error:NULL];
NSMutableString *resultString = [NSMutableString stringWithCapacity:format.length
+ [[[values allValues] valueForKeyPath:@"@sum.length"] unsignedIntegerValue]];
__block NSRange rangeSinceLastMatch = { 0, 0 };