Skip to content

Instantly share code, notes, and snippets.

@sspencer
sspencer / FormatThousandsSeparator.m
Created July 27, 2012 19:18
Format Decimal Number with Thousands Separator
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSLog(@"formatted: %@", [formatter stringFromNumber:[NSNumber numberWithInt:1234567]]);
@sspencer
sspencer / unitedstates.php
Created March 3, 2012 00:10
United States in PHP array
$UnitedStates = array(
"AL" => "Alabama",
"AK" => "Alaska",
"AZ" => "Arizona",
"AR" => "Arkansas",
"CA" => "California",
"CO" => "Colorado",
"CT" => "Connecticut",
"DE" => "Delaware",
"FL" => "Florida",
@sspencer
sspencer / unitedstates.html
Created March 3, 2012 00:08
United States in select options tag
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
@sspencer
sspencer / location.sql
Created February 21, 2012 01:18
Mysql Location Search
--
-- Mysql Functions and Idea from http://www.xarg.org/2009/12/people-near-you-with-mysql/
-- Stored procedures from Steve.
-- Not using `point`, could leave out field from location table.
--
CREATE TABLE IF NOT EXISTS `location` (
`vendor_id` INT unsigned NOT NULL,
`lat` decimal(10,6) NOT NULL,
`lon` decimal(10,6) NOT NULL,
@sspencer
sspencer / keep_current_file_open.sh
Created February 9, 2012 23:08 — forked from wearhere/keep_current_file_open.sh
Keep your current source file open in Xcode after a run completes (a.k.a don't die in main.m)
#! /bin/sh
# On alternate invocations, this script
# saves the path of the source file currently open in Xcode
# and restores the file at that path in Xcode.
#
# By setting Xcode (in Behaviors) to run this script when "Run Starts"
# and when "Run Completes", you can prevent it from switching to main.m
# when a run finishes.
# See http://stackoverflow.com/questions/7682277/xcode-4-2-jumps-to-main-m-every-time-after-stopping-simulator
@sspencer
sspencer / Star6.c
Created January 26, 2012 08:55
Find Star of David 26 Solutions
// Given the Star of David, arrange the numbers 1-12 (there are 12 intersections) so that
// each line (there are 6 lines and 4 intersections per line) adds up to 26.
//
// Intersections on array are numbered TDLR, from a0 to a11.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// prototypes
@sspencer
sspencer / StarOfDavid.py
Created January 26, 2012 07:43
Make each line in star of david add up to 26
import random
import sys
"""
Given the Star of David, arrange the numbers 1-12 (there are 12 intersections) so that
each line (there are 6 lines and 4 intersections per line) adds up to 26.
Intersections on array are numbered TDLR, from a0 to a11.
"""
@sspencer
sspencer / AFNetworkingRequest.m
Created November 18, 2011 23:58
AFNetworking Request
// using ARC, so no release / autorelease
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://localhost"]];
[client setAuthorizationHeaderWithUsername:@"steve" password:@"mypass"];
NSURLRequest *request = [client requestWithMethod:@"GET" path:@"/auth.php" parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation
setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success: %@", operation.responseString);
@sspencer
sspencer / rgb.c
Created July 20, 2011 17:39
RGB Conversion
int rgb = ((r&0x0ff)<<16)|((g&0x0ff)<<8)|(b&0x0ff);
int red = (rgb>>16)&0x0ff;
int green=(rgb>>8) &0x0ff;
int blue= (rgb) &0x0ff;
@sspencer
sspencer / multiproxy-working.js
Created April 13, 2011 21:54
Working Multi Proxy
var http = require('http');
// Working multiproxy - can call setTimeout multiple times.
function sendRequest(hostname) {
var client = http.createClient(80, hostname);
client.setTimeout(5000);
var req = client.request('GET', '/');
client.addListener('timeout', function (error) {