Skip to content

Instantly share code, notes, and snippets.

@bil-bas
bil-bas / gist:3221023
Created July 31, 2012 21:57
Random hash picker
heftig:
first, do target = rand(a.inject(0){|m,h| m + h[:prob]})
to get a value between 0 and (sum of all probs - 1)
then just a.find { |h| target -= h[:prob]; target < 0 }
steps through the array, reducing target by prob until it's < 0
@Kevinwlee
Kevinwlee / gist:3226002
Created August 1, 2012 11:31
Date stuff
- (NSString *)currentDateString {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"d"];
NSString *day = [df stringFromDate:self.currentDate];
return day;
}
- (NSString *)currentMonthString {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MMMM"];
NSString *day = [df stringFromDate:self.currentDate];
@raulandrisan
raulandrisan / dabblet.css
Created August 1, 2012 14:34
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@KentaAkimoto
KentaAkimoto / gist:3227521
Created August 1, 2012 14:55
NSString -> NSNumber
[NSNumber numberWithInt:[@"12345" intValue]];
/*
http://arduino.cc/en/Tutorial/AnalogInput
*/
#define SENSOR_PIN A0 // select the input pin for the potentiometer
#define NUM_PINS 8
#define START_PIN 1
int pin_interval;
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int brightness = 0; // how bright the LED is
@t3db0t
t3db0t / eeprom_rw_test.ino
Created August 1, 2012 19:53
Arduino EEPROM Read-Write Example
/******************************************************
Arduino EEPROM Read-Write Test
by Ted Hayes 2012
[email protected]
Demonstrates the usage of the EEPROM Library for checking the state of a single value,
changing it, and resetting it. To use:
1) Put a momentary switch between ground and pin 11 on your Arduino.
@fogus
fogus / family-trees.txt
Created August 2, 2012 00:58 — forked from zerokarmaleft/family-trees.txt
Game of Thrones Challenge #65
AA = Rickard Stark (M) AB = Eddard Stark (M) AC = Catelyn Tully (F)
AD = Brandon Stark (M) AE = Benjen Stark (M) AF = Jon Snow (M)
AG = Robb Stark (M) AH = Sansa Stark (F) AI = Arya Stark (F)
AJ = Bran Stark (M) AK = Rickon Stark (M) AL = Hoster Tully (M)
AM = Minisa Whent (F) AN = Edmure Tully (M) AO = Lysa Tully (F)
AP = Jon Arryn (M) AQ = Robert Arryn (M) AR = Tytos Lannister (M)
AS = Tywin Lannister (M) AT = Joanna Lannister (F) AU = Kevan Lannister (M)
AV = Cersei Lannister (F) AW = Jamie Lannister (M) AX = Tyrion Lannister (M)
AY = Robert Baratheon (M) AZ = Joffrey Baratheon (M) BA = Myrcella Baratheon (F)
BB = Tommen Baratheon (M) BC = Lancel Lannister (M) BD = Steffon Baratheon (M)
@briangonzalez
briangonzalez / gist:3242283
Created August 2, 2012 23:57
Running Applescript from Cocoa
NSString *someScript = [[NSBundle mainBundle] pathForResource:@"some_script" ofType:@"osascript"];
NSString *contents = [NSString stringWithContentsOfFile:someScript encoding:NSUTF8StringEncoding error:nil];
NSAppleScript *script =[[NSAppleScript alloc] initWithSource:contents];
[script executeAndReturnError:nil];