Skip to content

Instantly share code, notes, and snippets.

View thoolihan's full-sized avatar

Tim Hoolihan thoolihan

View GitHub Profile
@thoolihan
thoolihan / sin_taylor.py
Created January 6, 2017 22:33
Implementing sin in numpy with a taylor series
import numpy as np
from math import factorial
def sin(x):
val = np.float64(0)
for n in range(0, 25):
term = (((-1) ** n) * (x ** (2*n+1)) / factorial(2*n + 1))
val += term
print("for x_{0}, term is {1}, sin({2}) approximation is {3}".format(
n, term, x, val))
@thoolihan
thoolihan / install-pymc-homebrew-os-x.sh
Created January 4, 2017 18:30
Installing pymc for homebrew users on OS X Sierra (1/4/2017)
brew install python3
brew install apple-gcc42
brew unlink gcc
ln -sf /usr/local/bin/gfortran-4.2 /usr/local/bin/gfortran
#optional: create virtualenv
python3 -mvenv ~/venvs/my_venv
source ~/venvs/my_venv/bin/activate
#end optional
@thoolihan
thoolihan / quote.py
Created December 11, 2016 12:29
searching for quoted text
import re
p = re.compile('\"([^\"]+)\"')
str = 'I said "Hello There." She replied "hi"'
matches = p.findall(str)
for m in matches:
print('found: {0}'.format(m))
@thoolihan
thoolihan / main.cpp
Created November 23, 2016 03:31
Poisson Probability Mass Function in C++
#include <iostream>
#include <iomanip>
#include "math.h"
using namespace std;
float pmf(int k, double lambda) {
// https://en.wikipedia.org/wiki/Poisson_distribution#Definition
return pow(M_E, k * log(lambda) - lambda - lgamma(k + 1.0));
}
@thoolihan
thoolihan / upload.py
Created November 12, 2016 00:56
S3 Upload From Python
import boto
import boto.s3
from boto.s3.key import Key
from glob import glob
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-p","--pattern", help="pattern to upload")
args = parser.parse_args()
@thoolihan
thoolihan / circle.py
Created October 27, 2016 03:27
Calculating and graphing a partial circle and inner circle in python
import numpy as np
import matplotlib.pyplot as plt
from math import pi, cos, sin
arc_size = pi / 2
points = 20
inner_ratio = .4
theta = np.arange(0, arc_size, arc_size / points)
@thoolihan
thoolihan / FixIcons.bat
Created March 20, 2016 23:18
Fix Windows Missing Desktop Icons (8, 8.1, 10)
# start cmd.exe as admin
# start taskmanager and close explorer.exe
cd %userprofile%\appdata\local
del iconcache.db /a
# start explorer.exe
@thoolihan
thoolihan / install_tensorflow_centos7.sh
Last active January 28, 2019 06:17
Install TensorFlow on CentOS7
sudo yum -y install epel-release
sudo yum -y install gcc gcc-c++ python-pip python-devel atlas atlas-devel gcc-gfortran openssl-devel libffi-devel
# use pip or pip3 as you prefer for python or python3
pip install --upgrade virtualenv
virtualenv --system-site-packages ~/venvs/tensorflow
source ~/venvs/tensorflow/bin/activate
pip install --upgrade numpy scipy wheel cryptography #optional
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp35-cp35m-linux_x86_64.whl
# or below if you want gpu, support, but cuda and cudnn are required, see docs for more install instructions
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0rc0-cp35-cp35m-linux_x86_64.whl
@thoolihan
thoolihan / trig_functions.R
Created October 17, 2015 17:43
mapping functions
library(ggplot2)
g <- qplot(c(0, 2 * pi), stat="function", fun=sin,
geom="line", color="sin", ylim=c(-2, 2),
ylab="ratio", xlab="radians") +
stat_function(fun=cos, aes(color="cos")) +
stat_function(fun=tan, aes(color="tan"))
print(g)
@thoolihan
thoolihan / Rakefile
Last active September 30, 2015 00:33
Image Sizing
skus = Dir.glob("*.jpg").collect do |file|
file.sub(".jpg","")
end
output = "final"
task :medium_images do
puts "creating medium images 250px wide..."
skus.each do |sku|
sh "convert #{sku}.jpg -strip -resize 250 -quality 100 #{output}/#{sku}_table.jpg"