Skip to content

Instantly share code, notes, and snippets.

Nicolas Pinto npinto

  • MIT
  • Boston, MA
Block or report user

Report or block npinto

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
watch -n 10 'curl | tee data/ticker.$(date +"%Y-%m-%d_%R:%S.%N").json | python -mjson.tool; for f in data/*.json; do gzip $f; done;'
npinto /
Created Jan 31, 2013
UIImageOrientation imageOrientation;
if (UserDefaults.usingFrontCamera) {
switch (curDeviceOrientation) {
case UIDeviceOrientationLandscapeLeft:
imageOrientation = UIImageOrientationDown;
case UIDeviceOrientationLandscapeRight:
imageOrientation = UIImageOrientationUp;
case UIDeviceOrientationPortraitUpsideDown:
UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation];
enum {
PHOTOS_EXIF_0ROW_TOP_0COL_LEFT = 1, // 1 = 0th row is at the top, and 0th column is on the left (THE DEFAULT).
PHOTOS_EXIF_0ROW_TOP_0COL_RIGHT = 2, // 2 = 0th row is at the top, and 0th column is on the right.
PHOTOS_EXIF_0ROW_BOTTOM_0COL_RIGHT = 3, // 3 = 0th row is at the bottom, and 0th column is on the right.
PHOTOS_EXIF_0ROW_BOTTOM_0COL_LEFT = 4, // 4 = 0th row is at the bottom, and 0th column is on the left.
PHOTOS_EXIF_0ROW_LEFT_0COL_TOP = 5, // 5 = 0th row is on the left, and 0th column is the top.
PHOTOS_EXIF_0ROW_RIGHT_0COL_TOP = 6, // 6 = 0th row is on the right, and 0th column is the top.
PHOTOS_EXIF_0ROW_RIGHT_0COL_BOTTOM = 7, // 7 = 0th row is on the right, and 0th column is the bottom.
npinto / json_bundle.m
Created Jan 22, 2013
JSONKit w/ NSBundle file
View json_bundle.m
NSString* jsonPath = [[NSBundle mainBundle] pathForResource:@"arr_fb" ofType:@"json"];
NSData* jsonData = [NSData dataWithContentsOfFile:jsonPath];
JSONDecoder* decoder = [[JSONDecoder alloc] initWithParseOptions:JKParseOptionNone];
NSDictionary* json = [decoder objectWithData:jsonData];
NSArray* shape = [json objectForKey:@"shape"];
NSUInteger fbn_ = [[shape objectAtIndex:0] intValue];
npinto /
Created Oct 17, 2012
How to reliably open a file in the same directory as a Python script
import os
from os import path
__location__ = path.realpath(path.join(os.getcwd(), path.dirname(__file__)))
npinto /
Created Oct 3, 2012
Theano Memory Hacks
import time
import gc
import numpy as np
def theano_memory_hack(func_exp, local_vars,
msize_start=1024, msize_factor=2,
npinto /
Created Sep 12, 2012
Python shell interface is painful (subprocess, commands, etc.)
url = ""
import os
import sysfrom sys import stderr
import tempfile
import commandsfrom os import path
from sys import stdout
from subprocess import Popen, PIPE, STDOUT
npinto /
Created Sep 5, 2012
Simple face detection with OpenCV 'cv2' python bindings from 2.4.x
import cv2
import as cv
def detect(img, cascade_fn='haarcascades/haarcascade_frontalface_alt.xml',
scaleFactor=1.3, minNeighbors=4, minSize=(20, 20),
cascade = cv2.CascadeClassifier(cascade_fn)
rects = cascade.detectMultiScale(img, scaleFactor=scaleFactor,
npinto /
Created Sep 4, 2012
String labels to sorted 0-based integers.
In [12]: l = ['a', 'a', 'c', 'c', 'c', 'b']
In [13]: u = np.unique(l)
In [14]: u
array(['a', 'b', 'c'],
In [15]: np.searchsorted(u, l)
npinto / .gitignore
Created Aug 1, 2012
Cython 0.16 C++ Demo
View .gitignore
You can’t perform that action at this time.