Skip to content

Instantly share code, notes, and snippets.

@boredzo
boredzo / buscard.ps
Created October 3, 2012 21:53
Program to generate a comparison of business card sizes
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 288 216
/pt_per_in 72 def
/mm_per_in 25.4 def
pt_per_in mm_per_in div dup scale
/in { mm_per_in mul } def
% All spatial units below are in millimeters unless otherwise stated.
@boredzo
boredzo / gist:4053177
Created November 11, 2012 00:41
Dock crash
Process: Dock [1006]
Path: /System/Library/CoreServices/Dock.app/Contents/MacOS/Dock
Identifier: com.apple.dock
Version: 1.8 (1040.42)
Build Info: Dock-1040042000000000~1
Code Type: X86-64 (Native)
Parent Process: launchd [222]
Date/Time: 2012-11-10 16:40:10.433 -0800
OS Version: Mac OS X 10.7.5 (11G56)
@boredzo
boredzo / gist:4158978
Created November 28, 2012 04:09
Proposal for a new kind of switch statement
I propose a new statement called (there is a better term for this, but I haven't thought of it) “bitswitch”.
It would work much like a regular switch statement, and could be implemented as a macro on top of it in many languages:
bitswitch(container, test) {
case all:
case single:
case multiple:
case none:
default: //Only meaningful if you don't use all four cases
@boredzo
boredzo / Untitled.out
Created December 18, 2012 05:30
Testing NSString compare:options:range: with a prefix range that is equal in both strings
2012-12-17 21:27:34.211 Untitled[10696:707] -1
2012-12-17 21:27:34.219 Untitled[10696:707] 0
@boredzo
boredzo / gist:4604459
Created January 23, 2013 11:04
Two-color angle gradient in Core Image
kernel vec4 coreImageKernel(__color startColor, __color endColor)
{
vec2 point = destCoord();
float angle = atan(point.y, point.x) + radians(180.0);
//Start from the upper middle, not the left middle
angle += radians(90.0);
angle = mod(angle, radians(360.0));
float fraction = angle / radians(360.0);
@boredzo
boredzo / makearmor.py
Created January 29, 2013 06:57
Program to create deletion armor. IMPORTANT: Create, set as invisible, and cd into ~/#Deletion-armor.noindex before you run this. (# makes it sort high; .noindex makes Spotlight skip it.)
#!/usr/bin/env python
import os
assert os.getcwd() != os.getenv('HOME'), "You REALLY don't want to run this in your Home directory; consider running it within ~/#Deletion-armor.noindex instead (which you should set invisible so Finder doesn't try to examine it)"
for x in xrange(100000000):
f = open('Armor shard #' + str(x), 'w')
f.close()
del f
@boredzo
boredzo / nowarninghere.m
Created February 15, 2013 23:52
Initialization of block pointer variable with incompatible block using wrong syntax passes without error or warning
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
/*Note the use of Objective-C method-style return type syntax.
*That's not actually the correct syntax, but the incorrect syntax passes compilation
*without a warning even though these blocks have different and incompatible signatures!
*/
id (^wat)(int x, int y) = (id)^(CGFloat x, CGFloat y) {
return @(hypot(x, y));
@boredzo
boredzo / fphex.c
Created February 16, 2013 01:07
Demonstrating properties of hexadecimal floating-point literals
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
double one = 0x100p-8;
printf("one: %f\n", one);
printf("0x100p-8 == 0x1p+0: %d\n", 0x100p-8 == 0x1p+0);
printf("0x100p-8 == 1.0: %d\n", 0x100p-8 == 1.0);
double n = 0xe5p-8, d = 0xffp-8;
@boredzo
boredzo / gist:5098941
Created March 6, 2013 12:21
You can't access instance variables of an object from any code that is outside of the @implementation of that object's class. You can access those ivars anywhere within that @implementation—*even within a C function*.
#import <Foundation/Foundation.h>
@class Foo;
static int geti1(Foo *foo);
static int geti2(Foo *foo);
@interface Foo: NSObject
@end
@boredzo
boredzo / gist:5127750
Last active December 14, 2015 18:09
Weird bit-printing behavior—run it and see what happens
#import <Foundation/Foundation.h>
static NSString *int32tostr(int value);
int main(int argc, char *argv[]) {
@autoreleasepool {
NSLog(@"%@", int32tostr(1));
NSLog(@"%@", int32tostr(2));
NSLog(@"%@", int32tostr(3));
}