Skip to content

Instantly share code, notes, and snippets.

@boredzo
boredzo / gist:8911626
Created February 10, 2014 07:11
Guess the bug!
/draw_rows
gsave
1 dict begin
/num_rows exch def
1 1 num_rows {
5 draw_one_row
} for
end
grestore
} def
@boredzo
boredzo / gist:ae47404dedec7930152a
Last active August 29, 2015 14:01
On the importance of an *explicit* code of conduct

First, some context.

I urged the AltConf organizers to publish a Code of Conduct for their attendees and speakers. In that Twitter conversation, I repeatedly cited Ashe Dryden's Code of Conduct 101 + FAQ.

This is what they published on their website as their code of conduct (as of 2014-05-06):

AltConf is provided free of charge, on a first-come, first-served basis, without warranty or liability, by volunteers, for the good of our community.

To participate in our conference in any way (attendee, speaker, sponsor, etc), you must agree to abide by the instructions of the volunteers and the decisions of the organizers, and acknowledge that you may be barred from participation at any time, for any reason.

@boredzo
boredzo / gist:edfba48ca9b52d7c09d8
Created May 11, 2014 21:25
Card dealing command-line program
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSArray *suits = @[
@"♠", @"♡", @"♢", @"♣"
];
NSArray *ranks = @[
@"A",
@"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9",
@boredzo
boredzo / README.md
Last active August 29, 2015 14:03
indexheaders/findheader

indexheaders/findheader

Ever wish you could do something like view $(findheader signal.h)—and have it be fast? Now you can.

(open -h is one alternative, but that opens it in Xcode, rather than a terminal-based or other editor.)

Basically, it's like “Open Quickly” for the command line.

Installation

@boredzo
boredzo / balloon-tail.ps
Last active August 29, 2015 14:03
Demonstration of how to draw a speech balloon tail, based on advice in http://stackoverflow.com/a/16782469/30461 .
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 120 260
/pt1 { 20 100 } def
/pt2 { 60 80 } def
/pt5 { 100 60 } def
/pt3 { 20 20 } def
/pt4 { 60 40 } def
/yoffset { 30 add } def
@boredzo
boredzo / git-ff.zsh
Created July 4, 2015 18:07
git helpers
#!/bin/zsh -f
exec git merge --ff-only $*
@boredzo
boredzo / with_scope.py
Created September 13, 2015 20:53
Experiment in making a “with” object that injects variables into the subjected scope and removes them at the end. One fatal flaw—see last comment. Inspired by: https://twitter.com/SwedishForSize/status/643146539897090048
class scope(object):
def __init__(self, **kargs):
self.values = kargs
def __enter__(self):
import inspect
frame, filename, lineno, module, code_context, idx = inspect.stack()[1]
caller_args, caller_fargs, caller_kargs, caller_locals = inspect.getargvalues(frame)
dest = caller_kargs if caller_kargs is not None else caller_locals
self.saved = dict(dest)
dest.update(self.values)
@boredzo
boredzo / gist:1363410
Created November 14, 2011 06:57
New CPU Usage object cache mechanism
New CPU Usage cache
Currently: Parallel C arrays of Cocoa text system objects, colors, etc.
drawRect: looks up the objects it needs in those arrays, indexed by the CPU usage percentage, and creates and caches whatever it doesn't already have.
Problem: drawRect: has a slow path where the cache does not contain the needed objects yet, so it must create them. Even the check itself slows down every pass through drawRect:.
Solution: A single array containing blocks.
Initially, this would be filled with all the same block, each of which creates the needed objects, creates a block that captures those objects and does the drawing, and replaces itself in the cache with the new block.
drawRect: simply calls the appropriate block in the array, unconditionally. The slow-path block will move itself out of the way when it's no longer needed.
#import <Foundation/Foundation.h>
@interface Foo: NSObject
- (void) takeBool:(BOOL)yorn;
- (void) takeDouble:(double)d;
@end
int main(int argc, char **argv) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@boredzo
boredzo / gist:1572986
Created January 6, 2012 23:30
Initialization code
@interface AutoScrollView ()
- (id) commonInit __attribute__((objc_method_family(init)));
@property(nonatomic, assign, getter=isAutoScrolling) BOOL autoScrolling;
@property(nonatomic, retain) NSTimer *autoScrollTimer, *delayedStartScrollingTimer;
@property(nonatomic, retain) UIGestureRecognizer *tapRecognizer;
@end