Skip to content

Instantly share code, notes, and snippets.

@apatil
apatil / user-data-test.yml
Last active August 29, 2015 13:58
user-data-test.yml
#cloud-config
coreos:
units:
- name: test.service
content: "[Unit]\nDescription=Test\n\n[Service]\nExecStart=/usr/bin/echo \"hi\"\nType=oneshot\n\n[Install]\nWantedBy=multi-user.target\n"
@apatil
apatil / gist:11001937
Created April 17, 2014 18:06
Fibrous pattern
f = (cb) =>
fibrous.run =>
a.sync()
b.sync()
, cb
@apatil
apatil / test.sh
Last active August 29, 2015 14:04
How to get Docker to choose the ports using the remote API?
curl -v -H "Content-Type: application/json" -X POST \
-d '{"Cmd":["/bin/sleep","infinity"],"Image":"ubuntu:14.04", "ExposedPorts":{"22/tcp":{}}}' \
http://127.0.0.1:4243/containers/create?name=testcontainer
curl -v -H "Content-Type: application/json" -X POST \
-d '{"PortBindings": { "22/tcp": [{ "HostPort": "11022" }]} }' \
http://127.0.0.1:4243/containers/testcontainer/start
@apatil
apatil / gist:9cb3dde2dd8f3183ffa1
Created February 25, 2015 20:49
apidoc markup
@api {get} /engines Request Available Engines
@apiVersion 1.0.0
@apiName GetEngines
@apiGroup Engines
@apiDescription Gets a list of the currently available engines on Sense.
@apiError (404) user not found.
@apiSuccess (200) {Object[]} engines List of available engines.
# Illustrates why log-sums are better than direct sums for probability integrals
# when probabilities are initially computed on the log scale
import pymc
import numpy
lp_big = numpy.random.normal(loc=0,scale=2,size=1000)
print numpy.log(numpy.mean(numpy.exp(lp_big)))
print pymc.flib.logsum(lp_big)-numpy.log(len(lp_big))
import numpy as np
import pylab as pl
import pymc as pm
Tau_test = np.matrix([[ 209.47883244, 10.88057915, 13.80581557],
[ 10.88057915, 213.58694978, 11.18453854],
[ 13.80581557, 11.18453854, 209.89396417]])
C_test = Tau_test.I
@apatil
apatil / ballast.py
Last active September 24, 2015 03:57
Figures out the mass of your narrowboat and how much ballast you need to add to achieve a desired result.
from __future__ import division
import numpy as np
# A boat is a dict with keys
# mass, center_of_mass, cm_depth, front_depth, back_depth, pitch, length, width
# units are radians (angles), meters (depths and lengths), tons (mass)
# Boats are idealized as rectangular prisms
water_density = 1
#!/usr/bin/env python
import pymc
from pymc import gp
from pymc.gp.cov_funs import matern,gaussian
from pylab import *
# Load some data generated from a GP with mean=0, scale=1, amp=1
xdata,ydata = loadtxt('train.txt', unpack=1)
@apatil
apatil / pymc_335.py
Created February 3, 2011 13:00
Tracking down PyMC issue 335
#!/usr/bin/env python
import numpy as npy
from pymc.gp import Mean, Covariance, Realization, observe, plot_envelope, NearlyFullRankCovariance, FullRankCovariance
from pymc.gp.cov_funs import matern #, thinplate1d
import matplotlib
matplotlib.rcParams['axes.facecolor']=[1,1,1]
__all__ = ['surface_mean', 'M', 'C']
def surface_mean(x, val):
"""docstring for parabolic_fun"""
@apatil
apatil / history_steps.py
Created February 24, 2011 18:27
Step methods that try to sample in 'isotropic position' using histories of their parameters
import pymc as pm
import numpy as np
# FIXME: Need to store duplicates too, when jumps are rejected. That means some mechanism
# for making sure the history is full-rank needs to be employed.
class HistoryCovarianceStepper(pm.StepMethod):
_state = ['n_points','history','tally','verbose']