Skip to content

Instantly share code, notes, and snippets.

View zafarali's full-sized avatar

Zafarali Ahmed zafarali

View GitHub Profile
@zafarali
zafarali / plot_polygon.py
Last active August 29, 2015 14:24
draw a polygon using vertices
import matplotlib.pyplot as plt
def plot_polygon(vertices):
plt.figure()
for i in range(len(vertices)-1):
vertex_set = [ vertices[i] ] + [ vertices[i+1] ]
x, y = zip(*vertex_set)
plt.plot(x,y)
vertex_set = [ vertices[0] ] + [ vertices[-1] ]
@zafarali
zafarali / preferences.sublime-keymap
Created July 22, 2015 20:18
Preferences in Sublime Text 2/3
[
//makes go to lines easier
{ "keys": ["super+;"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
// makes bookmarking easier
{ "keys": ["f5"], "command": "toggle_bookmark" },
{ "keys": ["f6"], "command": "next_bookmark" },
{ "keys": ["super+f6"], "command": "prev_bookmark" }
]
# Load the data streamer:
ds = IOutils.data_streamer(num_sets='all')
# obtains the unique rows in a dataset
def unique_rows(data):
uniq = np.unique(data.view(data.dtype.descr * data.shape[1]))
return uniq.view(data.dtype).reshape(-1, data.shape[1])
X, Y = ds.next()
Y = np.array(Y)
@zafarali
zafarali / polarstreamplot.m
Created December 1, 2015 15:59
A mathematica snippet to turn a polar dynamical system into a stream plot.
# your polar functions dr/dt and d\[Theta]/dt here:
field = {r (1 - r^2) (4 - r^2), 2 - r^2};
# Creates the stream plot
StreamPlot[
Evaluate@TransformedField["Polar" -> "Cartesian",
field, {r, \[Theta]} -> {x, y}], {x, -3, 3}, {y, -3, 3}]
@zafarali
zafarali / dataready.sh
Last active December 5, 2015 17:45
Bash Script to set up a data analysis VPS
apt-get update
apt-get install -y git
apt-get install -y tmux
apt-get install -y python-pip
apt-get install -y python-numpy python-scipy
apt-get install -y python-matplotlib
apt-get install -y python-pandas
pip install scikit-learn
apt-get install -y ipython
pip install -e git+https://github.com/Theano/Theano.git@15c90dd3#egg=Theano==0.8.git
# time_values is a signal of shape: (time, n_channels)
# window data tensor is of shape: (time, window_size, n_channels)
# where window_size just holds all the data for the T-window_size data.
window_data_tensor = np.zeros((time_values.shape[0], window_size, time_values.shape[1]))
for t in range(1, time_values.shape[0]):
if t <= window_size:
window_data_tensor[t, :, :] = np.pad(time_values[:t, :], ((0, window_size-t), (0,0)), mode='constant')
elif t > window_size and t < time_values.shape[0]-window_size+1:
@zafarali
zafarali / promise_plugins.js
Created May 11, 2016 15:09
how can we string together multiple promises especially those that have request()s in them?
var q = require('q');
var request = require('request');
var context = {
query: 'hello how are you?'
} // global context to be mutated by all "plugins"
function hello_plugin(context){
var query = context.query
var contains_hello = false;
import numpy as np
import time
# the population:
global population
population = np.random.normal(-10,10, size=(10**6, 3))
def sample(args):
centre, radii = args
# print centre, radii
@zafarali
zafarali / min-char-rnn.py
Created June 10, 2016 03:05 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
target friend strength class state
0 19 1 SCI1 0
1 85 1 HUM1 0
1 62 1 HUM1 0
1 38 1 HUM1 0
1 72 1 HUM1 0
2 61 1 SCI1 0
2 79 1 SCI1 0
2 48 1 SCI1 0
4 39 1 HUM1 0