Skip to content

Instantly share code, notes, and snippets.

View simonbyrne's full-sized avatar
🦘

Simon Byrne simonbyrne

🦘
View GitHub Profile
@simonbyrne
simonbyrne / binary-parse.jl
Created May 26, 2015 15:07
Parsing of hex-float and bit-float strings
# converts bit-float and hex-float strings to floating point numbers
# assumes round-to-nearest
import Base: significand_mask, significand_bits, exponent_bias, tryparse
for B in (2,16)
@eval function tryparse{T<:Float64}(::Type{T}, s::String, ::Type{Val{$B}})
f_neg = false
r_ind = false # radix pt. indicator
r = 0 # no. of places after radix pt.
@simonbyrne
simonbyrne / interpolations_speed.jl
Created June 3, 2015 10:51
Test performance of interpolations
# based on https://github.com/tlycken/Interpolations.jl/pull/37
Pkg.checkout("Interpolations", "master")
Pkg.checkout("Ratios", "checked")
using Interpolations, Grid
A = rand(300,300,30);
itp = interpolate!(copy(A), BSpline(Quadratic(Flat)), OnCell);
yi = InterpGrid(copy(A), BCreflect, InterpQuadratic);
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
type DataFrame{N,D}
data::D
end
immutable Field{s}
end
Field(s::Symbol) = Field{s}()
function DataFrame(;kwds...)
@simonbyrne
simonbyrne / jbug.jl
Created October 15, 2012 19:48
A bugs-type sampler in julia
require("extras/distributions.jl")
require("slicesampler.jl")
import Distributions.*
macro buildslicesampler(model)
# pull apart the model into variables and distributions
variables = Dict{Symbol,Expr}()
unboundvars = Set{Symbol}()
for line in model.args
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
abstract UTree{T}
immutable UTreeBranch{T} <: UTree{T}
left::UTree{T}
right::UTree{T}
end
immutable UTreeLeaf{T} <: UTree{T}
v::T
end
@simonbyrne
simonbyrne / newparse.jl
Last active April 25, 2016 16:12
integer parsing
import Base: checked_add, checked_mul
function newparse{T}(::Type{T}, s, base=0)
0 <= base <= 62 || throw(ParseError("Invalid base"))
en = endof(s)
i = start(s)
done(s,i) && throw(ParseError("Invalid $T"))
c,i = next(s,i)
function setup(pkgname)
Pkg.cd() do
cd(pkgname) do
info("Generating ssh key")
run(`ssh-keygen -N "" -f .quickdocs_id_rsa`)
info("Encrypting private key")
run(`travis login --auto`)
run(`travis encrypt-file .quickdocs_id_rsa --add deploy`)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.