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
# Function and alias for ~/.bashrc to checkout a private gist by hash | |
# TRY IT OUT | |
# checkout this very gist after you copy/pasted this file into your ~/.bashrc | |
# with this terminal command: | |
# gist 1343759 | |
# temp dir for checkouts | |
GIST_DIR=~/gist_tmp | |
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
/* btree traversal - most left to most right */ | |
pnode traverse(pnode root, void (*func)(pnode)) | |
{ | |
pnode ret, tmp = root; | |
if(!root) return root; | |
while((tmp = traverse(tmp->left, func))){; } | |
ret = traverse(root->right, fun |
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
def circle(x, y, radius): | |
iterations = int(2*radius*pi) | |
s = sin(2*pi / iterations) | |
c = cos(2*pi / iterations) | |
dx, dy = radius, 0 | |
glBegin(GL_TRIANGLE_FAN) | |
glVertex2f(x, y) | |
for i in range(iterations+1): |
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 file size in BYTES */ | |
int file_sizeof(FILE *fp) | |
{ | |
int filesize; | |
fseek(fp, 0L, SEEK_END); /* jump to end of file */ | |
filesize = ftell(fp); /* current byte of file == f |
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
p = ''.join(random.sample('ABCDEFGHJKLMNPQRSTUVWXYZ23456789', 6)) |
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
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
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
#Evaluate the linear regression | |
def compute_cost(X, y, theta): | |
''' | |
Comput cost for linear regression | |
''' | |
#Number of training samples | |
m = y.size | |
predictions = X.dot(theta).flatten() |
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
def feature_normalize(X): | |
''' | |
Returns a normalized version of X where | |
the mean value of each feature is 0 and the standard deviation | |
is 1. This is often a good preprocessing step to do when | |
working with learning algorithms. | |
''' | |
mean_r = [] | |
std_r = [] |
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
#!/usr/bin/env python | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from numpy import newaxis, r_, c_, mat | |
from numpy.linalg import * | |
def plotData(X, y): | |
plt.plot(X, y, 'rx', markersize=7) | |
plt.ylabel('Profit in $10,000s') | |
plt.xlabel('Population of City in 10,000s') |
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
// Remove all children DOM elements | |
while (node.hasChildNodes()) { | |
node.removeChild(node.lastChild); | |
} |
OlderNewer