Skip to content

Instantly share code, notes, and snippets.

View Naereen's full-sized avatar
📝
Coder in long holidays - full time teacher

Lilian Besson Naereen

📝
Coder in long holidays - full time teacher
View GitHub Profile
@amueller
amueller / mlp.py
Created March 17, 2012 15:59
Multi-Layer Perceptron for scikit-learn with SGD in Python
import numpy as np
import warnings
from itertools import cycle, izip
from sklearn.utils import gen_even_slices
from sklearn.utils import shuffle
from sklearn.base import BaseEstimator
from sklearn.base import ClassifierMixin
from sklearn.preprocessing import LabelBinarizer
@dideler
dideler / bitwise-operators.md
Created April 12, 2012 08:25
Bitwise tricks

Inspired by this article. Neat tricks for speeding up integer computations.

Note: cin.sync_with_stdio(false); disables synchronous IO and gives you a performance boost. If used, you should only use cin for reading input (don't use both cin and scanf when sync is disabled, for example) or you will get unexpected results.

Multiply by a power of 2

x = x << 1; // x = x * 2

@masak
masak / explanation.md
Last active May 21, 2024 20:05
How is git commit sha1 formed

Ok, I geeked out, and this is probably more information than you need. But it completely answers the question. Sorry. ☺

Locally, I'm at this commit:

$ git show
commit d6cd1e2bd19e03a81132a23b2025920577f84e37
Author: jnthn <jnthn@jnthn.net>
Date:   Sun Apr 15 16:35:03 2012 +0200

When I added FIRST/NEXT/LAST, it was idiomatic but not quite so fast. This makes it faster. Another little bit of masak++'s program.

@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active June 9, 2024 10:41
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@fabianp
fabianp / coordinate_descent.py
Created July 12, 2012 07:47
minimalistic l1 coordinate descent
# -*- coding: utf-8 -*-
"""
Minimalistic implementation of l1 minimization via coordinate descent.
Reference: www.jstatsoft.org/v33/i01/paper
Author: Fabian Pedregosa <fabian@fseoane.net>
"""
import numpy as np
@tonicebrian
tonicebrian / GBT_CaliforniaHousing.py
Created November 5, 2012 16:22
Gradient Boosting Trees using Python
# =============
# Introduction
# =============
# I've been doing some data mining lately and specially looking into `Gradient
# Boosting Trees <http://en.wikipedia.org/wiki/Gradient_boosting>`_ since it is
# claimed that this is one of the techniques with best performance out of the
# box. In order to have a better understanding of the technique I've reproduced
# the example of section *10.14.1 California Housing* in the book `The Elements of Statistical Learning <http://www-stat.stanford.edu/~tibs/ElemStatLearn/>`_.
# Each point of this dataset represents the house value of a property with some
# attributes of that house. You can get the data and the description of those
@aflaxman
aflaxman / mpl_cfaces.py
Created November 9, 2012 01:12
Chernoff Faces in Python with Matplotlib
from pylab import *
def cface(ax, x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18):
# x1 = height of upper face
# x2 = overlap of lower face
# x3 = half of vertical size of face
# x4 = width of upper face
# x5 = width of lower face
# x6 = length of nose
# x7 = vertical position of mouth
@dideler
dideler / example.md
Last active February 17, 2024 20:24
A python script for extracting email addresses from text files.You can pass it multiple files. It prints the email addresses to stdout, one address per line.For ease of use, remove the .py extension and place it in your $PATH (e.g. /usr/local/bin/) to run it like a built-in command.

The program below can take one or more plain text files as input. It works with python2 and python3.

Let's say we have two files that may contain email addresses:

  1. file_a.txt
foo bar
ok ideler.dennis@gmail.com sup
 hey...user+123@example.com,wyd
hello world!
@chiiph
chiiph / chacha20.py
Created October 6, 2013 16:04
Python implementation of the stream cipher ChaCha20. The idea is to use numpy as the "numeric backend" to avoid side channel attacks. THIS IS JUST AN EXPERIMENT, DO NOT USE IN PRODUCTION.
# Based on http://cr.yp.to/streamciphers/timings/estreambench/submissions/salsa20/chacha8/ref/chacha.c
import binascii
import numpy as np
np.seterr(over='ignore')
def rotl32(v, c):
assert isinstance(v, np.uint32)
assert isinstance(c, np.uint32)
#!/usr/bin/env python
import svmpy
import logging
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import itertools
import argh