This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pip | |
from subprocess import call | |
for dist in pip.get_installed_distributions(): | |
call("pip install --upgrade " + dist.project_name, shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __COMMON__ | |
#define __COMMON__ | |
#include "Arduino.h" | |
//#define DEBUG_ON | |
#ifdef DEBUG_ON | |
#define initLog(speed) Serial.begin(speed) | |
#define log(buf) Serial.print(buf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Webkit browsers set the height and width property after the image is loaded. | |
This results in zero being returned on trying to get the height and width. | |
So to get the right width and height using Javascript/jQuery | |
(.height() and .width()) consider using a img loaded callback as shown in the | |
example below. | |
*/ | |
$('img').load(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I kept solving the puzzles until I reached the donation page. I give up. No dollars please. | |
################################################################################ | |
# For challenge 5 | |
def challenge5(): | |
import pprint | |
import pickle | |
f = open('banner.p', 'rb') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(BOOL)isWholeNumber:(double)number | |
{ | |
double integral; | |
double fractional = modf(number, &integral); | |
return fractional == 0.00 ? YES : NO; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSURLRequest *)getURLRequestForResource:(NSString *)fileName ofType:(NSString *)type | |
{ | |
NSString *bundleFilePath = [[NSBundle mainBundle] pathForResource:fileName | |
ofType:type]; | |
NSURL *bundleURL = [NSURL fileURLWithPath:bundleFilePath]; | |
NSURLRequest *bundleFileRequest = [NSURLRequest requestWithURL:bundleURL]; | |
return bundleFileRequest; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a random integer between min and max | |
* Using Math.round() will give you a non-uniform distribution! | |
*/ | |
function getRandomInt (min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import floor | |
from collections import namedtuple | |
Rect = namedtuple('Rect', ('x1', 'y1', 'x2', 'y2')) | |
class SpatialHash(object): | |
def __init__(self, cell_size=10.0): | |
self.cell_size = float(cell_size) | |
self.d = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from collections import Sequence,defaultdict | |
#making code python3-compatible | |
if sys.version_info[0] == 3: | |
basestring = str | |
def buildLocator(tree): | |
locator = defaultdict(list) | |
def fillLocator(tree, locator,location): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Works for nicely ordered data | |
import numpy as np | |
RECIPES = ( | |
('apple', 'sugar', 'extreme_Force'), | |
('banana', 'syrup', 'magical_ends'), | |
('caramel', 'chocolate', 'pancake_MONSTER'), | |
) | |
np_recipes = np.array(recipes) | |
indices = zip(*np.where( np_recipes == 'banana' ) ) #[(1, 0)] |
OlderNewer