Skip to content

Instantly share code, notes, and snippets.

@magsol
magsol / particles.js
Created March 15, 2013 15:28
A small modification of some public javascript code to simulate a bunch of particles exerting gravitational effects on one another. When enough particles gather in a small enough space, they explode outward.
// A great deal of this code was inspired by Codeflow.
// http://codeflow.org/entries/2010/aug/22/html5-canvas-and-the-flying-dots/
// I just added the bit where the particles explode :)
var Universe = function() { this.init.apply(this, arguments); };
Universe.prototype = {
init: function(numParticles, interval, maxVelocity, maxAcceleration, criticalMass, criticalRadius) {
var canvas = document.getElementById('particles');
var context = canvas.getContext('2d');
@magsol
magsol / sample_uniform.py
Last active December 15, 2015 00:09
Demonstrates how to sample from exponential and gaussian distributions using only a uniform distribution (useful for languages like PHP with no built-in statistical sampling libraries).
import numpy as np
import matplotlib.pyplot as plot
import sys
def exp(mean, samples = 100):
y = []
lambda_param = (1 / mean)
for i in range(0, samples):
rand = np.random.rand()
y.append(np.log(1 - rand) / (-1.0 * lambda_param))
@magsol
magsol / parse_hashmap.py
Created March 15, 2013 15:34
This script takes the output of an Apache Mahout job (in HashMap format) and converts it to a histogram.
import numpy as np
import sys
import matplotlib.pyplot as plot
import csv
# read the arguments - need two files
if len(sys.argv) < 3:
quit('python parse.py [raw data file] [mahout output]')
# read the files
@magsol
magsol / histogram_equalization_in_python.ipynb
Created September 19, 2013 18:47
IPython notebook about histogram equalization with images. Basic image processing.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@magsol
magsol / OpenCV Introduction.ipynb
Created December 2, 2013 20:14
IPython notebook introducing the basics of OpenCV.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@magsol
magsol / feret.py
Created June 2, 2015 18:57
FERET binary to PNG image parser
import argparse
import bz2
import os
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = 'FERET Parser',
epilog = 'lol moar p1cz', add_help = 'How to use',
prog = 'python feret.py <args>')
# Required parameters.
@magsol
magsol / python-packages.md
Last active May 23, 2017 18:47
Python packages I use.
@magsol
magsol / aws-dash.md
Last active January 29, 2019 08:47
Attempts to get the Amazon Dash button working with Hue lights.
@magsol
magsol / bluedata-worker-cleanup-and-reset.sh
Last active October 4, 2016 00:11
BlueData Worker reformat and reinstall
# Register each worker.
./bootstrap-uga-general.sh
# Make sure each worker is subscribed to the RHEL channels:
# - RHEL Server Optional
# - RHEL Server Supplementary
# - RHN Tools for RHEL
# Run on each worker.
yum -y update
@magsol
magsol / animated_rotated_3dtrajectory.py
Created May 4, 2017 19:36
An animated 3D matplotlib figure that rotates incrementally as the plot is drawn.
import argparse
import matplotlib.pyplot as plot
from matplotlib import animation
from mpl_toolkits.mplot3d.axes3d import Axes3D
import numpy as np
import scipy.io
import ar.ar as AR
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = 'Cilia AR Subspace Plotting',