Skip to content

Instantly share code, notes, and snippets.

@mdengler
mdengler / gist:7042133
Created October 18, 2013 14:11
mpl_tm.py
{
"metadata": {
"name": "Untitled0"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
import numpy as np
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction.text import CountVectorizer
def get_vectors(vocab_size=5000):
newsgroups_train = fetch_20newsgroups(subset='train')
vectorizer = CountVectorizer(max_df=.9, max_features=vocab_size)
vecs = vectorizer.fit_transform(newsgroups_train.data)
vocabulary = vectorizer.vocabulary
terms = np.array(vocabulary.keys())
#!/usr/bin/python
# to use:
# 1) git clone git@github.com:jszakmeister/nose.git nose-711
# 2) cd nose-711
# 3) python setup.py build
# 4) cd build/lib
# 5) put this file there as test.py
# 6) PYTHONPATH=$PWD python -m nose ./test.py
# # observe the error:
@mdengler
mdengler / test.py
Created May 14, 2014 23:23
test case for nose #711
#!/usr/bin/python
# to use:
# 1) git clone git@github.com:jszakmeister/nose.git nose-711
# 2) cd nose-711
# 3) python setup.py build
# 4) cd build/lib
# 5) put this file there as test.py
# 6) PYTHONPATH=$PWD python -m nose ./test.py
# # observe the error:
@mdengler
mdengler / README.md
Last active August 29, 2015 14:02 — forked from mbostock/.block
Wilson's algorithm by mbostock, with quicker-completion starting conditions

Wilson’s algorithm uses loop-erased random walks to generate a uniform spanning tree — an unbiased sample of all possible spanning trees. Most other maze generation algorithms, such as Prim’s, random traversal and randomized depth-first traversal, do not have this beautiful property.

The algorithm initializes the maze with eight arbitrary starting cells. Then, a new cell is added to the maze, initiating a random walk (shown in magenta). The random walk continues until it reconnects with the existing maze (shown in white). However, if the random walk intersects itself, the resulting loop is erased before the random walk continues.

The global structure of the maze can be more easily seen by flooding it with color.

To play with this yourself, [instructions from Uehreka on http://news.yco

### Keybase proof
I hereby claim:
* I am mdengler on github.
* I am mdengler (https://keybase.io/mdengler) on keybase.
* I have a public key whose fingerprint is 565C 8F33 ABF7 2DAA 33DE B9CB 81B4 44DD 75C7 D2F8
To claim this, I am signing this object:
@mdengler
mdengler / install-tmux
Last active October 19, 2015 22:46 — forked from rothgar/install-tmux
Install tmux 2.1 on rhel/centos 6
# Install tmux on Centos release 6.5
# install deps
yum install gcc kernel-devel make ncurses-devel
# DOWNLOAD SOURCES FOR LIBEVENT AND MAKE AND INSTALL
curl -OL https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -xvzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=$HOME &&
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
every_nth = [2, 3]
index = pd.Series(range(len(df.index))) # or just df.index if it's already the 0-indexed indices
mask = reduce(np.logical_or, [index % i == 0 for i in every_nth])
df[mask.astype(bool).values]