Skip to content

Instantly share code, notes, and snippets.

@mathyourlife
mathyourlife / faster_getsystemtime.m
Last active October 13, 2017 10:11
Testing faster methods to retrieve the current system time in Matlab m-files so that simulations are not slowed down as much.
duration_1 = 0;
duration_2 = 0;
iter = 100000;
for i=1:iter
if mod(i,2) == 0
tic;
a = now();
duration_1 = duration_1 + toc;
else
tic;
@mathyourlife
mathyourlife / heatmap.ipynb
Created December 3, 2013 05:00
Basic Heatmap of a Periodic Signal
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mathyourlife
mathyourlife / cdr.sh
Last active December 30, 2015 08:59
cdr function: cd up to a "root" directiory
# Add this function to your ~/.bashrc file to allow you to jump to the top of a complex dir tree
#
# Examples:
# user@host:~/git_stuff/git_repo1/dir1/subdir/subsubdir $ cdr
# user@host:~/git_stuff/git_repo1 $
#
# user@host:~/svn_stuff/svn_repo1/dir1/subdir/subsubdir $ cdr
# user@host:~/svn_stuff/svn_repo1 $
#
# user@host:~/just/a/normal/dir/structure $ cdr
@mathyourlife
mathyourlife / chef-dk.md
Last active August 29, 2015 14:04
chef-dk

Steps Used to Configure Ubuntu 14.04 Workstation with Chef-DK and Vagrant

wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.0-2_amd64.deb
sudo dpkg -i chefdk_0.2.0-2_amd64.deb
mkdir -p ~/.chefdk
echo 'eval "$(chef shell-init bash)"' >> ~/.bashrc
echo 'export PATH="/opt/chefdk/embedded/bin:${HOME}/.chefdk/gem/ruby/2.1.0/bin:$PATH"' >> ~/.bashrc
wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.3_x86_64.deb
sudo dpkg -i vagrant_1.6.3_x86_64.deb
sudo tcpdump -s 0 -A -i lo0 'tcp port 8080 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
@mathyourlife
mathyourlife / pre-post-R-filter.md
Created September 6, 2014 22:32
Demonstrate the more memory efficient method of filtering your data prior to reading into R

To Pre Filter or Post?

I recently worked on a project where I needed to pull in a reasonably sized data set only to filter away a large majority of it. Needless to say the memory implications for scaling this up were concerning. So here's a quick demo of a problem where we want to pull in a list of all the words that start with "B" from a dictionary. The two methods are 1) the original pull in the dictionary then filter down to the "B"'s and 2) filter the data on ingress. Option 2)'s maximum memory consumption is approximately 6% of option 1.

Post-Filter

library(pryr)

DICTIONARY <- '/etc/dictionaries-common/words'
@mathyourlife
mathyourlife / kafka.md
Created September 17, 2014 13:45
kafka notes

Apache Kafka

"A high-throughput distributed messaging system." site

Notes taken from source

Overview

  • Created at LinkedIn (open sourced in 2011)
@mathyourlife
mathyourlife / simple_clojure_tcp_server.md
Created September 27, 2014 03:41
clojure: listen to a port and parse lines

Clojure TCP Simple Server

Creates a clojure script that listens on TCP port 8000 and prints out lines received through the connection.

(require '[clojure.java.io :as io])
(import '[java.net ServerSocket])

(defn receive
 "Read a sequence of lines from the socket"
@mathyourlife
mathyourlife / csv_chunk generator.py
Created September 29, 2014 15:24
generate chunks of csv files
import csv
# cat First500000.lst
# 0,a
# 1,a
# 2,a
# 3,a
# 4,a
# 5,a
# 6,a
@mathyourlife
mathyourlife / LexPerm.go
Created May 5, 2015 22:02
Lexicographic Permutations - implementation of a method without recursion or state memory
/*
Lexicographic Permutations
source: http://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order
The following algorithm generates the next permutation lexicographically
after a given permutation. It changes the given permutation in-place.
1) Find the largest index k such that a[k] < a[k + 1].
If no such index exists, the permutation is the last permutation.