Skip to content

Instantly share code, notes, and snippets.

@quinnj
quinnj / example.jl
Created Jul 31, 2014
Macro-generated binary tree with if statements
View example.jl
# Recursively build binary search tree w/ known lookup values
# A is sorted array of lookup values
# R is return values for each index of A
# i.e. R[1] is returned for values < A[1], R[2] for < A[2], etc.
function searchsortedlasttree(A,R,var_name)
l = length(A)
mid = iseven(l) ? l>>>1 : (l>>>1)+1
# Handle base case
if mid == 1
if l == 1
View gist:2165fc05703b42843923
In [7]: for (i,b) in enumerate(ubt) # unique, nonzero backtrace points
@show i, b # this way you'll know which one crashed, and can exclude it on the next run
println(Profile.lookup(b))
end
(i,b) => (1,0x0000000065a0af1b)
LineInfo("jl_subtype_invariant","???",1705029403,true,1705029403)
(i,b) => (2,0x0000000065a0cd65)
LineInfo("jl_type_intersection","???",1705037157,true,1705037157)
(i,b) => (3,0x0000000065a0b5fb)
LineInfo("jl_subtype_invariant","???",1705031163,true,1705031163)
@quinnj
quinnj / range_create.jl
Last active Aug 29, 2015
Julia: Create Array from Range: Issue #4785
View range_create.jl
macro NO_GC(ex)
quote
gc_disable()
ret = $ex;
gc_enable()
gc()
end
end
# func1: vcat(range)
View gist:cf1e4e971d549dde8c7e
julia> @code_typed parse_value(ps,true)
1-element Array{Any,1}:
:($(Expr(:lambda, Any[:ps,:ordered], Any[Any[:ch,symbol("#s19"),symbol("#s18"),symbol("#s14"),symbol("#s13"),symbol("#s12"),symbol("#s11"),:ret],Any[Any[:ps,JSON.Parser.ParserState{ASCIIString},0],Any[:ordered,Bool,0],Any[:ch,Char,18],Any[symbol("#s19"),Bool,2],Any[symbol("#s18"),Bool,18],Any[symbol("#s14"),Bool,2],Any[symbol("#s13"),Bool,18],Any[symbol("#s12"),Bool,18],Any[symbol("#s11"),Bool,2],Any[:ret,Any,34]],Any[],Any[Bool,Bool,Char,Char,Char,Char,Char,Char,Char,Char,Char,Char]], :(begin # none, line 2:
((top(getfield))((top(getfield))(JSON,:Parser),:chomp_space)::Any)(ps::JSON.Parser.ParserState{ASCIIString})::Void # line 3:
unless (top(slt_int))((top(getfield))(ps::JSON.Parser.ParserState{ASCIIString},:e)::Int64,(top(getfield))(ps::JSON.Parser.ParserState{ASCIIString},:s)::Int64)::Bool goto 0
return nothing
0: # line 5:
ch = ((top(getfield))((top(getfield))(JSON,:Parser),:charat)::Any)(ps::JSON.P
View CSV Validation
# Validation Rules
# Each row must contain the same number of columns
# Each field must be formatted correctly and be of the right type and format, must be one of:
# Empty, missing value
# DATE
# DATETIME
# INTEGER
# DOUBLE
# STRING
# quoted by f.quotechar, with f.escapechar allowed within f.quotechar to specify literal f.quotechar, f.delim, or f.newline
View gist:2dc8bf55517906122b84
reload("/Users/jacobquinn/julia/base/mmap2.jl")
function seg(n)
file = tempname()
s = open(file, "w") do f
write(f, "Hello World\n")
end
for i = 1:n
m = Mmap2.Array(file)
m[1]
@quinnj
quinnj / gist:599ba66ea141ae91cbc4
Created May 20, 2015
Mmap.Array segfaults gdb
View gist:599ba66ea141ae91cbc4
Warning: replacing module Mmap2
Warning: replacing module Mmap2
Warning: replacing module Mmap2
Warning: replacing module Mmap2
Warning: replacing module Mmap2
signal (11): Segmentation fault: 11
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x121b of process 33745]
View gist:aa5d951e5722f4ede2fe
# This file is a part of Julia. License is MIT: http://julialang.org/license
module Mmap2
# platform-specific mmap utilities
pagesize() = Int(@unix ? ccall(:jl_getpagesize, Clong, ()) : ccall(:jl_getallocationgranularity, Clong, ()))
@unix_only begin
const SEEK_SET = Cint(0)
const SEEK_CUR = Cint(1)
@quinnj
quinnj / juliacon2015.jl
Last active Aug 29, 2015
Managing Data in Julia: Old Tricks, New Tricks Code
View juliacon2015.jl
Pkg.clone("https://github.com/quinnj/Mmap.jl")
Pkg.clone("https://github.com/quinnj/CSV.jl")
Pkg.add("ODBC")
Pkg.checkout("SQLite","jq/remodel")
Pkg.add("SQLite")
Pkg.checkout("SQLite","jq/updates")
reload("Mmap")
reload("CSV")
@quinnj
quinnj / gist:bb1b5d8170301801c012
Last active Aug 29, 2015
Base String Performance Benchmarks
View gist:bb1b5d8170301801c012
### Micro performance benchmarks
# Results Data
## String Type | Benchmark | DateTime Run |
## Julia Version | Strings.jl Version |
## Time Elapsed | Bytes Allocated | GC Time
# reload("Strings")
results = Dict("String Type"=>ASCIIString[],
"String Length"=>Int[],