Skip to content

Instantly share code, notes, and snippets.

@stucchio
stucchio / mle_compute_z.jl
Last active August 29, 2015 14:01
Maximum likelihood computation of ad probability
#Pkg.add("Optim")
using Optim
function logLikelihood(z::Float64, clicks::Array{Float64,1}, shows::Array{Float64,1}, alpha::Array{Float64,1})
@assert size(clicks) == size(shows)
@assert size(shows) == size(alpha)
az = z * alpha
return sum(clicks .* log(az) .+ (shows .- clicks) .* log(1-az))
end
using PyPlot
function em_exact(a, b, c, d)
total = 0.0
for i = 0:(c-1)
total += exp(lbeta(a+i, d+b) - log(d+i) - lbeta(1+i, d) - lbeta(a, b))
end
return total
end
@stucchio
stucchio / ActorBenchmark.scala
Created September 11, 2014 16:31
Actor benchmark
package benchmark
import akka.actor._
object ActorBenchmark {
class IntermediateMapper(target: ActorRef) extends Actor {
var state: Wrapper = Wrapper(0,0)
def receive = {
case (w:Wrapper) => {
@stucchio
stucchio / StreamBenchmark.scala
Created September 11, 2014 16:35
Stream benchmark
package benchmark
import scala.concurrent._
import scala.concurrent.ExecutionContext
import scalaz._
import Scalaz._
import scalaz.stream._
import scalaz.stream.async._
import scalaz.concurrent.{Task, Strategy}
@stucchio
stucchio / Dockerfile
Created October 28, 2014 11:02
Dockerfile for Julia
FROM ubuntu:14.04
MAINTAINER Chris Stucchio <stucchio@gmail.com>
# Necessary to add a ppa
RUN apt-get update && apt-get install -y python-software-properties software-properties-common
# Julia repository
RUN add-apt-repository ppa:staticfloat/juliareleases && apt-get update
# Yay julia
@stucchio
stucchio / Dockerfile
Created October 28, 2014 11:05
Dockerfile for julia web stack
FROM stucchio/juliabase:0.3.2
MAINTAINER Chris Stucchio <stucchio@gmail.com>
# Julia libs we want
ADD REQUIRE /.julia/v0.3/REQUIRE
RUN julia -e "Pkg.resolve()"
# C Libraries we need
RUN apt-get install -y unixodbc unixodbc-dev libsqliteodbc odbc-postgresql libhttp-parser-dev libicu-dev # Utility libs
module Storage
DB_HOST = ENV["POSTGRES_PORT_5432_TCP_ADDR"]
DB_PORT = ENV["POSTGRES_PORT_5432_TCP_PORT"]
DB_NAME = ENV["POSTGRES_DBNAME"]
DB_USER = ENV["POSTGRES_PGUSER"]
DB_PASS = ENV["POSTGRES_PGPASS"]
conn = connect(Postgres, DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT)
@stucchio
stucchio / Dockerfile
Created November 4, 2014 14:03
dockerfile for nginx reverse proxy
FROM ubuntu:14.04
MAINTAINER Chris Stucchio <stucchio@gmail.com>
# Nginx
RUN apt-get update && apt-get install -y nginx nginx-extras && mkdir /var/www
ADD nginx.conf /etc/nginx/nginx.conf
ADD run_nginx.sh /bin/run_nginx.sh
RUN chmod +x /bin/run_nginx.sh
@stucchio
stucchio / gist:630918
Created October 17, 2010 14:56
Coroutine paren matcher
def matchparen():
ct = 0
msg = None
result = None
while (msg != True):
msg = (yield ct)
if msg == '(':
ct += 1
@stucchio
stucchio / gist:630921
Created October 17, 2010 15:00
Python coroutines
def cr():
state = False
for i in range(100):
new_state = None
if state:
new_state = (yield i)
else:
new_state = (yield "Off")
if not (new_state is None):
state = new_state