Skip to content

Instantly share code, notes, and snippets.

View mysteriouspants's full-sized avatar
:shipit:
Help! I'm trapped in a fixed-width str

Christopher R. Miller mysteriouspants

:shipit:
Help! I'm trapped in a fixed-width str
View GitHub Profile
@mysteriouspants
mysteriouspants / Rakefile
Created February 15, 2012 22:11
Some weird random stuffs.
# encoding: utf-8
# a rakefile for working with Markdown-based prose.
#
# quotes: Change dumb quotes to smart quotes, and then back again.
# info: Various metrics for vanity's sake. "How many words and
# characters are in each file, & total" and other such nonsense.
# (Note that this chops off the very last file, which I generally
# use as the 'stuff I'm about to write' scratchpad - I don't want
# metrics on that!
#
@mysteriouspants
mysteriouspants / hex-parser.c
Created February 16, 2012 17:28
Why parse hex when you don't have to?
#include <stdio.h>
int main(int argc, char *argv[]) {
const char* c = "1A FF";
int a, b;
sscanf(c, "%2x %2x", &a, &b);
printf("a: %3d b: %3d\n", a, b);
printf("a: %3x b: %3x\n", a, b);
@mysteriouspants
mysteriouspants / Would You Kindly.txt
Created March 6, 2012 21:26
Would you kindly fix Radar? (duplicate of rdar://10993759)
Dear Apple,
We need to talk. We love your software, we really do. Or maybe we don't but we want to tell you why
so you can try to improve it. We are developers ourselves and we know how hard it is to write
software, to find and fix bugs, to know what your users want from your software. We want to file bug
reports and feature requests for every bug we find or feature we think of. As a community we want you
to know what is important to us, in a way that doesn't require you to trawl through countless blogs
and tweets. Unfortunately you're making it so incredibly hard to do so.
The only way to really communicate with Apple about what is broken and what we want is Radar. But
@mysteriouspants
mysteriouspants / COADocumentWindowController.m
Created April 17, 2012 18:30
Basic drag'n'drop functionality.
//
// COADocumentWindowController.m
// Co-Author
//
// Created by Christopher Miller on 4/13/12.
// Copyright (c) 2012 FSDEV. All rights reserved.
//
#import "COADocumentWindowController.h"
#import "COAManagedNode.h"
@mysteriouspants
mysteriouspants / foo.m
Created May 11, 2012 15:52
Save app delegates everywhere by shoving static data into C functions!
NSDictionary * sharedFoo() {
static NSDictionary * foo;
static dispatch_once_t f;
dispatch_once(f, ^{
foo = [NSDictionary dictionaryWithObjectsForKeys:
@"bar", @"foo"];
};
return foo;
}
@mysteriouspants
mysteriouspants / extconf.rb
Created August 1, 2012 19:00
Extconf for therubyracer v0.10.1 or so
require 'mkmf'
require 'set'
begin
require 'libv8'
rescue LoadError
require 'rubygems'
require 'libv8'
end
have_library('objc') if RUBY_PLATFORM =~ /darwin/
@mysteriouspants
mysteriouspants / 193_behavior.txt
Created August 13, 2012 22:00
Somewhere in Sprockets an encoding bug has reared its ugly head!
Last login: Mon Aug 13 15:54:31 on ttys005
Welcome back, commander!
cmiller@cmiller-iMac:~
> which irb
/Users/cmiller/.rvm/rubies/ruby-1.9.3-p194/bin/irb
cmiller@cmiller-iMac:~
@mysteriouspants
mysteriouspants / Rakefile
Created September 21, 2012 15:45
My blog's Rakefile
HOOLIGAN_STYLES={
'themes/hooligan/stylesheets/_sass/style.scss' => 'themes/hooligan/stylesheets/css/style.css'
}
module Rake
class Task
def has_dependency? task, inspected_tasks=[]
task= Rake::Task[task] if task.class != Rake::Task
return true if self == task
return false if inspected_tasks.include? self
@mysteriouspants
mysteriouspants / gist:3802099
Created September 28, 2012 21:13
FSURLOperation Example
NSURLRequest* req= [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://fsdev.net"]];
__block NSData* mySite= nil;
FSURLOperation* oper= [FSURLOperation URLOperationWithRequest:req completionBlock:^(NSHTTPURLResponse* resp, NSData* payload, NSError* asplosion) {
mySite = payload;
}];
NSBlockOperation* onFinish= [NSBlockOperation blockOperationWithBlock:^{
NSMutableURLRequest* spamReq= [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.fsdev.net/"]];
@mysteriouspants
mysteriouspants / gist:3802114
Created September 28, 2012 21:15
FSArgumentParser Sample Code
#import <Foundation/Foundation.h>
#import "FSArguments.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
FSArgumentSignature * helpFlag = [FSArgumentSignature argumentSignatureWithFormat:@"[-h --help]"];
FSArgumentSignature * inFileFlag = [FSArgumentSignature argumentSignatureWithFormat:@"[-i --in-file]={1,}"];
FSArgumentSignature * outFileFlag = [FSArgumentSignature argumentSignatureWithFormat:@"[-o --out-file]="];
NSSet * signatures = [NSSet setWithObjects:helpFlag, inFileFlag, outFileFlag, nil];