Skip to content

Instantly share code, notes, and snippets.

View dstnbrkr's full-sized avatar

Dustin Barker dstnbrkr

View GitHub Profile
From 0be864d8f6eac17afb245b44020e53b932412770 Mon Sep 17 00:00:00 2001
From: Dustin Barker <dustin.barker@gmail.com>
Date: Thu, 15 Oct 2009 19:24:08 -0700
Subject: [PATCH] If a mock dir exists and is a symlink, resolve it.
Fixes specs that fail on Mac OS X due to symlink /var -> /private/var
---
core/dir/fixtures/common.rb | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
From 092ae12aec59cc8883f6f6454f111df56260338e Mon Sep 17 00:00:00 2001
From: Dustin Barker <dustin.barker@gmail.com>
Date: Thu, 15 Oct 2009 20:49:22 -0700
Subject: [PATCH] If a mock dir exists and is a symlink, resolve it
Fixes specs that fail on Mac OS X due to symlink /var -> /private/var
---
core/dir/fixtures/common.rb | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
@dstnbrkr
dstnbrkr / server.js
Created January 19, 2011 16:57
Simple server that writes raw HTTP post data to a file.
var http = require("http");
var fs = require("fs");
var path = require("path");
http.createServer(function(request, response) {
unique_filename(function(filename) {
upload_file(filename, request, response);
});
}).listen(8000);
@dstnbrkr
dstnbrkr / node static server anywhere
Created February 12, 2011 01:47
Launch a webserver anywhere, the current working directory will be the document root
#!/usr/local/bin/node
var
sys = require('sys'),
path = require('path'),
http = require('http'),
paperboy = require('/usr/local/lib/node/paperboy'),
PORT = 8003,
WEBROOT = process.cwd();
@dstnbrkr
dstnbrkr / prime-factors.rkt
Created March 4, 2011 21:02
racket prime factorization
(define (eratosthenes n)
(define (sift list p)
(filter (lambda (n)
(not (zero? (modulo n p))))
list))
(define (iter nums primes)
(let ((p (car nums)))
(if (> (* p p) n)
(append (reverse primes) nums)
(iter (sift (cdr nums) p) (cons p primes)))))
@dstnbrkr
dstnbrkr / fermat.rkt
Created March 4, 2011 21:38
fermat test for primality
(define (is-fermat-prime? n iterations)
(or (<= iterations 0)
(if (= (modulo (expt (+ (random (- n 1)) 1) (- n 1)) n) 1)
(is-fermat-prime? n (- iterations 1))
#f)))
@dstnbrkr
dstnbrkr / UIColorFromRGB
Created March 28, 2011 19:32
Convert hex value to UIColor
UIColor* UIColorFromRGB(NSInteger rgb) {
return [UIColor colorWithRed:((float) ((rgb & 0xFF0000) >> 16)) / 0xFF
green:((float) ((rgb & 0xFF00) >> 8)) / 0xFF
blue:((float) (rgb & 0xFF)) / 0xFF
alpha:1.0];
}
@dstnbrkr
dstnbrkr / xcode-remove-unused
Created December 6, 2011 23:47
Remove unused resources from xcode project.
#!/bin/sh
for f in `find Resources/Images -type f ! -name '*@2x.png' ! -name 'Default*.png'`; do
FILENAME=`basename $f`;
NUSAGES=`usages $FILENAME | wc -l | awk '{print $1}'`;
if [ $NUSAGES = 0 ]; then
echo $f;
fi;
done;
@dstnbrkr
dstnbrkr / xcode-usages
Created December 6, 2011 23:50
Find references to a resource
grep -Rl "$1" * | grep -v build | grep -v BankSimple.xcodeproj | grep -v Icon*.png | grep -v Assets
filename=$1
extension=${filename##*.}
filename=${filename%.*}
grep -Rl $filename * | grep -v build | grep -v BankSimple.xcodeproj | grep -v Icon*.png | grep -v Assets
@dstnbrkr
dstnbrkr / git-merge-combine
Created January 13, 2012 21:15
git-merge-combine
#!/bin/sh
# Combines two versions of a file by removing all conflict markers
# Usage: git-merge-combine MyProject.xcodeproj/project.pbxproj
FILE=$1
TMPFILE=$1.tmp
sed -e 's/<<<<<<< HEAD//; s/=======//g; s/>>>>>>> .*$//' $FILE > $TMPFILE
if [ $? -ne 0 ]; then