Skip to content

Instantly share code, notes, and snippets.

View jwmerrill's full-sized avatar

Jason Merrill jwmerrill

View GitHub Profile
@jwmerrill
jwmerrill / gbm.jl
Last active June 29, 2018 04:49
Faster geometric brownian motion
function genS_jl(I)
s0 = 600.0
r = 0.02
sigma = 2.0
T = 1.0
M = 100
dt = T/M
a = (r - 0.5*sigma^2)*dt
b = sigma*sqrt(dt)
@jwmerrill
jwmerrill / fzero_vs_bisect_benchmark.jl
Created February 15, 2014 01:16
Benchmark simple bisection against Roots.fzero polyalgorithm
using Roots
# Alternative "mean" definition that operates on the binary representation
# of a float. Using this definition, bisection will never take more than
# 64 steps.
function _middle(x::Float64, y::Float64)
# Use the usual float rules for combining non-finite numbers
if !isfinite(x) || !isfinite(y)
return x + y
end
@jwmerrill
jwmerrill / a-series-representation-benchmark
Last active December 30, 2015 18:09
Benchmark of PowerSeries.jl
using PowerSeries
function series_loop()
accum = 0.0
for i = 1:10000
accum += sin(Series(1.0*i, 1.0)).ep
end
end
function dual_loop()
@jwmerrill
jwmerrill / gist:6502014
Created September 9, 2013 21:50
Example of validating an e-mail address by looking up the SMTP server and seeing how it responds to RCPT TO: messages.
jason:knox jm843$ host gmail.com
gmail.com has address 74.125.239.53
gmail.com has address 74.125.239.54
gmail.com has IPv6 address 2607:f8b0:4010:801::1016
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
jason:knox jm843$ nc alt3.gmail-smtp-in.l.google.com 25
run(`wget http://julialang.org/images/logo.png`)
# Open png file for reading
fp = ccall(:fopen, Ptr{Uint8}, (Ptr{Uint8}, Ptr{Uint8}), "logo.png", "r")
# Read first 8 bytes
initial_bytes = Array(Uint8, 8)
ccall(:fread, Ptr{Uint8}, (Ptr{Uint8}, Uint8, Uint8, Ptr{Uint8}), initial_bytes, 1, 8, fp)
# Check that we actually have a png file