Skip to content

Instantly share code, notes, and snippets.

View npinto's full-sized avatar

Nicolas Pinto npinto

View GitHub Profile
#!/bin/bash
watch -n 10 'curl https://data.mtgox.com/api/2/BTCUSD/money/ticker | tee data/ticker.$(date +"%Y-%m-%d_%R:%S.%N").json | python -mjson.tool; for f in data/*.json; do gzip $f; done;'
@npinto
npinto / imageOrientation.mm
Created January 31, 2013 09:07
imageOrientation.mm
UIImageOrientation imageOrientation;
if (UserDefaults.usingFrontCamera) {
switch (curDeviceOrientation) {
case UIDeviceOrientationLandscapeLeft:
imageOrientation = UIImageOrientationDown;
break;
case UIDeviceOrientationLandscapeRight:
imageOrientation = UIImageOrientationUp;
break;
case UIDeviceOrientationPortraitUpsideDown:
@npinto
npinto / exifOrientation.mm
Created January 31, 2013 09:05
exifOrientation.m
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
npinto / json_bundle.m
Created January 22, 2013 23:05
JSONKit w/ NSBundle file
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
npinto / __location__.py
Created October 17, 2012 08:33
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
npinto / theano_hacks.py
Created October 3, 2012 22:16
Theano Memory Hacks
import time
import gc
import numpy as np
def theano_memory_hack(func_exp, local_vars,
input_exps=('input',),
msize_best=None,
msize_start=1024, msize_factor=2,
verbose=False):
@npinto
npinto / subprocess_is_painful.py
Created September 12, 2012 07:52
Python shell interface is painful (subprocess, commands, etc.)
url = "http://www.youtube.com/watch?v=pkCTAeLsX7E"
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
npinto / cv2_detect.py
Created September 5, 2012 07:13
Simple face detection with OpenCV 'cv2' python bindings from 2.4.x
import cv2
import cv2.cv as cv
def detect(img, cascade_fn='haarcascades/haarcascade_frontalface_alt.xml',
scaleFactor=1.3, minNeighbors=4, minSize=(20, 20),
flags=cv.CV_HAAR_SCALE_IMAGE):
cascade = cv2.CascadeClassifier(cascade_fn)
rects = cascade.detectMultiScale(img, scaleFactor=scaleFactor,
@npinto
npinto / labels_to_integers.py
Created September 4, 2012 21:36
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
Out[14]:
array(['a', 'b', 'c'],
dtype='|S1')
In [15]: np.searchsorted(u, l)
@npinto
npinto / .gitignore
Created August 1, 2012 23:40
Cython 0.16 C++ Demo
*.so
_demo.cpp
build