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
# Plotting clusterings with matplotlib | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def plot_clusterings(data, clusterings, k): | |
""" | |
Args: | |
data - n x d numpy array | |
clusterings - 1 x n numpy array, values from 0 to k-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
from random import randint | |
def random_string(n): | |
return ''.join(chr(randint(0, 25) + ord('a')) for i in range(n)) |
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 password_gen(num_chars, chars): | |
""" | |
This is a generator | |
that outputs all passwords of lowercase letters of length | |
num_chars. | |
Inputs: | |
num_chars- the length of the password | |
chars- a list of the characters that can be part of the password | |
""" |
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
import os | |
import binascii | |
print binascii.hexlify(os.urandom(10)) |
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
cimport cython | |
import numpy as np | |
cimport numpy as np | |
from libc.math cimport log2 | |
ctypedef fused int2: | |
short | |
int |
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
#!/bin/bash | |
for var in "$@"; do | |
filename=${var%.*} | |
#echo $filename | |
#echo $@ | |
echo "writing to $filename.html" | |
pandoc $var --self-contained --toc -c /home/yjzhang/Dropbox/Notes/buttondown.css -s --mathml -o $filename.html | |
done |
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
# code to draw a DNA sequence logo... | |
import matplotlib.pyplot as plt | |
from matplotlib import transforms | |
import matplotlib.patheffects | |
import numpy as np | |
def entropy(row): | |
return -sum(x*np.log2(x+0.0000001) for x in row) |
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
import numpy as np | |
from scipy.stats import norm | |
# particle filter for localization using echolocation | |
# given: measurements, accelerometer readings, heading | |
# user's state: [x, y, theta] | |
# control: d(theta), d(position) |
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
# simple implementation of quantile normalization? | |
import numpy as np | |
def quantile_norm(data): | |
""" | |
Source: https://en.wikipedia.org/wiki/Quantile_normalization | |
Note: this doesn't deal with ties very well. | |
Args: |
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
class TrieNode(object): | |
def __init__(self, char = '', children = {}, parent = None, wordEnd = False, value = True): | |
self.char = char | |
self.children = children | |
self.parent = parent | |
self.wordEnd = wordEnd | |
self.value = value |
OlderNewer