Skip to content

Instantly share code, notes, and snippets.

View simonbyrne's full-sized avatar
🦘

Simon Byrne simonbyrne

🦘
View GitHub Profile
@generated function convertg{T<:Integer}(::Type{Rational{T}}, x::Irrational)
o = precision(BigFloat)
p = 256
while true
setprecision(BigFloat, p)
bx = BigFloat(x())
r = rationalize(T, bx, tol=0)
if abs(BigFloat(r) - bx) > eps(bx)
setprecision(BigFloat, o)
return r
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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`)
@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)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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);
@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 / winenv.jl
Created May 10, 2015 08:54
Test windows ENV interfaces
function winenvs(var)
# Win: ansi
len = ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,C_NULL,0)
if len > 0
val=zeros(Uint8,len)
ccall(:GetEnvironmentVariableA,stdcall,Uint32,(Ptr{Uint8},Ptr{Uint8},Uint32),var,val,len)
win_a = bytestring(val)
else
win_a = ""