Skip to content

Instantly share code, notes, and snippets.

1) tabs to spaces
:set tabstop=4 shiftwidth=4 expandtab
:retab
2) Whitespace found at end of line
:%s/^M\+$//g
:%s/\s\+$//g
NOTE: ^M must be inserted using CTRL-v RETURN
@tsterker
tsterker / fancyhdr_template.tex
Created August 9, 2012 19:38
[LaTeX] fancyhdr template
\usepackage{fancyhdr}
\setlength{\headheight}{15.2pt}
\pagestyle{fancy}
\fancyhf{}
\rhead{\bfseries\nouppercase\leftmark}
\cfoot{\bfseries\thepage}
@tsterker
tsterker / removeRandom.js
Created June 25, 2012 23:23
[js] remove random elements from array
var l = [1,2,3,4,5,6,7,8,9,10];
while(l.length){
var r = (Math.random()*1000)%l.length;
var removed = l.splice(r, 1);
console.log('Removed: ' + removed);
}
@tsterker
tsterker / gist:2408855
Created April 17, 2012 20:40
[js] argument unpacking
// Taken from:
// http://readystate4.com/2008/08/17/javascript-argument-unpacking-converting-an-array-into-a-list-of-arguments/
var item1 = ['Jack', '39', 'Panda'];
function hi(name, age, type){
console.log('Hi ' + name + '! You are ' + age + ' and a ' + type + '!');
}
@tsterker
tsterker / gist:2408805
Created April 17, 2012 20:31
[js] Remove all children DOM elements
// Remove all children DOM elements
while (node.hasChildNodes()) {
node.removeChild(node.lastChild);
}
@tsterker
tsterker / ex1.py
Created December 21, 2011 01:15 — forked from gorlum0/ex1.py
[py] ml-class - ex1
#!/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')
@tsterker
tsterker / multlin.py
Created December 21, 2011 01:14 — forked from marcelcaraciolo/multlin.py
[py] multivariate linear regression
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 = []
@tsterker
tsterker / linregr.py
Created December 21, 2011 01:12 — forked from marcelcaraciolo/linregr.py
[py] linear regression
#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()
@tsterker
tsterker / Evolution of a Python programmer.py
Created December 21, 2011 00:58
[py] programmer levels
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@tsterker
tsterker / gist:1503993
Created December 21, 2011 00:46 — forked from chrisgilmerproj/gist:1503913
[py] Password Generator
p = ''.join(random.sample('ABCDEFGHJKLMNPQRSTUVWXYZ23456789', 6))