Skip to content

Instantly share code, notes, and snippets.

View tralamazza's full-sized avatar

Daniel Tralamazza tralamazza

View GitHub Profile
@tralamazza
tralamazza / mehaddition+nsarray.h
Created February 20, 2012 14:48
nsarray additions
@interface NSArray (MehAdditions)
- (NSArray*) filter:(BOOL (^)(id)) block;
- (NSArray*) map:(id (^)(id)) block;
- (id) reduce:(id) value block:(id (^)(id, id)) aBlock;
@end
@tralamazza
tralamazza / mehaddition+nsarray.m
Created February 20, 2012 14:54
nsarray additions
@implementation NSArray (Mehdditions)
- (NSArray*) filter:(BOOL (^)(id)) block {
NSMutableArray* result = [NSMutableArray new];
for (id item in self)
if (block(item))
[result addObject:item];
return result;
}
@tralamazza
tralamazza / gist:1870564
Created February 20, 2012 18:35
objc addition declaration
@interface MyExistingClass (SomeRandomNamePreferablyWithAdditionsPostfixed)
- (void) extraMethod;
+ (void) extraStaticMethod;
@end
NSMutableArray* yay = [NSMutableArray new];
[yay addObject:@"1"];
[yay addObject:@"2"];
[yay addObject:@"3"];
NSNumber* reduced = [yay reduce:[NSNumber numberWithInt:0] block:^id(id sum, id i) {
return [NSNumber numberWithInt:[sum intValue] + [i intValue]];
}];
STAssertEquals([reduced intValue], 6, @"whut?!");
@tralamazza
tralamazza / node-install.sh
Created March 15, 2012 11:05
nodejs (debian) installer/bootstrap
#!/bin/sh
# $1 nodejs version, e.g. "0.6.12"
sudo apt-get install -y libssl-dev g++
if [ ! -d "node-v$1" ]; then
# download + extract
curl http://nodejs.org/dist/v$1/node-v$1.tar.gz | tar xzf -
fi
@tralamazza
tralamazza / skel-init.sh
Created March 18, 2012 15:11
skel init
#!/bin/sh
cd ~
git clone -n [email protected]:tralamazza/skel.git
mv skel/.git .
rm -rf skel
git checkout HEAD
@tralamazza
tralamazza / nodester-reg
Created March 21, 2012 09:29
register nodester coupon
#!/bin/sh
if [ $# -lt 3 ]; then
echo "Missing arguments"
exit 1
fi
COUPON=$1
PASSWORD=$2
EMAIL=$3
@tralamazza
tralamazza / googleio.json
Created April 9, 2012 20:32
google io thingie (developers.google.com/events/io/input-output)
[
{
"klass": "InputGate",
"params": {
"positionFromTop": 280,
"editable": true
}
},
{
"klass": "Redirector",
@tralamazza
tralamazza / node_mysql_reco.js
Created July 27, 2012 14:49
node mysql server disconnect
// source: https://github.com/felixge/node-mysql#server-disconnects
var mysql = require('mysql');
function supportReconnect(connection, cb) {
connection.on('error', function(err) {
if (!err.fatal) return;
if (err.code !== 'PROTOCOL_CONNECTION_LOST') throw err;
connection = mysql.createConnection(connection.config);
if (cb(connection))
supportReconnect(connection, cb);
@tralamazza
tralamazza / gist:3237619
Created August 2, 2012 14:54
intercept js func
function intercept(f, cb) {
return function() {
cb(arguments);
f.apply(f, Array.prototype.slice.call(arguments, 0));
};
}