Skip to content

Instantly share code, notes, and snippets.

View TheDataLeek's full-sized avatar

Zoë TheDataLeek

View GitHub Profile
#!/usr/bin/env python3
import sys
import os
import argparse
import re
from pprint import pprint as pp
import pytz
import dateutil
@TheDataLeek
TheDataLeek / politicalboundaries.py
Last active November 14, 2017 00:18
Code for Political Boundary Simulations
#!/usr/bin/env python3.6
"""
Simulated Annealing and Genetic Algorithm solutions to districting problem.
Notes on implementation:
* I like properties and I use them in a couple spots...
* Use `pip install --user -r requirements.txt` on the requirements file
available in the root of this git repository.
* If by some strange happenstance you only have this file, go to the
#!/usr/bin/env python3.6
import time
import math
import numpy as np
import random
def distance(coord1, coord2):
return math.sqrt(sum((coord1[i] - coord2[i])**2
for i in range(len(coord1))))
@TheDataLeek
TheDataLeek / bogosort.py
Last active March 14, 2017 18:30
Parallel Bogosort
#!/usr/bin/env python3.6
import sys
import time
import random
import multiprocessing as mp
from multiprocessing import Queue
from tqdm import tqdm
import numpy as np
{
"cells": [
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
{
"cells": [
{
"cell_type": "code",
"execution_count": 57,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
#!/usr/bin/env python2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as ptch
import matplotlib.lines as lne
import matplotlib.animation as ani
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@TheDataLeek
TheDataLeek / init.vim
Created August 1, 2016 22:14
init.vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Initialize Vundle
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.config/nvim/bundle/Vundle.vim
call vundle#begin('~/.config/nvim/bundle')
# Python # MATLAB
def bastard_svd(A, k, p): # function [U,D,V] = LOCAL_rsft(A,k,p)
m, n = A.shape # n = size(A,2);
# Create diagonal matrix of random numbers #
dd = np.exp(1j * 2 * np.pi * np.random.random(size=n)) # dd = exp(1i*2*pi*rand(1,n));
Y = A @ np.diag(dd) # Y = A*diag(dd);
# Apply full FFT to rows of AD, extract k + p columns #
Y = np.fft.fft(Y, axis=1) # Axis0 is columns, Axis1 is Rows # Y = fft(Y,[],2);
# Create vector J of length k + p from the set {1, 2, ..., n} #
J = np.random.choice(np.arange(n), # [~,ind] = sort(rand(1,n));