Skip to content

Instantly share code, notes, and snippets.

View pcperini's full-sized avatar

Patrick Perini pcperini

View GitHub Profile
@pcperini
pcperini / gist:4148848
Last active October 13, 2015 05:48
Categories in Python
# categories.py
class category(object):
def __init__(self, mainModule, override = True):
self.mainModule = mainModule
self.override = override
def __call__(self, function):
if self.override or function.__name__ not in dir(self.mainModule):
setattr(self.mainModule, function.__name__, function)
But our greatest triumph comes not from flexing the metacarpal bone and making a fist,
which always seems to be thirsting to be clenched…
No, no, no, no, no.
Our greatest moment is when we open our hand:
cradling a glass of wine, cupping a loved one’s chin.
And the best… the most expert of all… keeping all the objects of our life in the air at the same time.
My friends, for your amusement and bemusement, I give you the human person.
/*!
* Bootstrap Responsive v2.3.0
*
* Copyright 2012 Twitter, Inc
* Licensed under the Apache License v2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Designed and built with all the love in the world @twitter by @mdo and @fat.
*/.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;line-height:0;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}@-ms-viewport{width:device-width}.hidden{display:none;visibility:hidden}.visible-phone{display:none!important}.visible-tablet{display:none!important}.hidden-desktop{display:none!important}.visible-desktop{display:inherit!important}@media(min-width:768px) and (max-width:979px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-tablet{display:inherit!important}.hidden-tablet{display:none!i
@pcperini
pcperini / BlockChaining.swift
Created June 5, 2014 20:12
Chain blocks for asynchronous, callback-based execution. Always ends in main queue.
operator infix ~> { associativity right }
@infix func ~>(firstBlock: (() -> Void), secondBlock: (() -> Void)) -> (() -> Void) {
return {
dispatch_async(dispatch_get_global_queue(-32768, 0), {
firstBlock()
dispatch_async(dispatch_get_main_queue(), secondBlock)
})
}
}
operator infix ⏰ {}
@infix func ⏰(time: NSTimeInterval, block: (() -> Void)) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))), dispatch_get_current_queue(), block)
}
5.0 ⏰ {
println("HI!")
}
@pcperini
pcperini / gist:34d432adecc4f2d7ef0f
Created June 18, 2014 16:46
WorldPin Map Events
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
// Zoom to user location
MKMapCamera *camera = [mapView.camera copy];
camera.altitude = 1; // Zoom in
camera.centerCoordinate = userLocation.coordinate;
mapView.camera = camera;
}
@pcperini
pcperini / gist:7e5814b29bf80477d0b4
Created June 18, 2014 16:52
WorldPin Map Events
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass: [MKUserLocation class]])
return nil;
MKPinAnnotationView *pinAnnotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier: @"pinAnnotation"];
[pinAnnotationView setAnnotation: annotation];
if (!pinAnnotationView)
{
pinAnnotationView = [[MKPinAnnotationView alloc] initWithAnnotation: annotation
@pcperini
pcperini / gist:3a433523ce8e67c25444
Last active August 29, 2015 14:02
WorldPin Socket Events
- (void)viewDidLoad
{
[super viewDidLoad];
[SIOSocket socketWithHost: @"http://yourHost:3000" response: ^(SIOSocket *socket)
{
self.socket = socket;
}];
}
@pcperini
pcperini / gist:9e8535811117ee420883
Last active August 29, 2015 14:02
WorldPin Socket Events
- (void)viewDidLoad
{
[super viewDidLoad];
[SIOSocket socketWithHost: @"http://yourHost:3000" response: ^(SIOSocket *socket)
{
self.socket = socket;
__weak typeof(self) weakSelf = self;
self.socket.onConnect = ^()
@pcperini
pcperini / gist:5d54c823f835f7dd856b
Last active August 29, 2015 14:02
WorldPin Socket Events
[self.socket on: @"update" callback: ^(SIOParameterArray *args)
{
// pinData == @"pinID:lat,long"
// self.pins == @{@"pinID": <WPAnnotation @ (lat, long)>}
NSString *pinData = [args firstObject];
NSArray *dataPieces = [pinData componentsSeparatedByString: @":"];
NSString *pinID = [dataPieces firstObject];