Skip to content

Instantly share code, notes, and snippets.

@quinnj
quinnj / example.jl
Created July 31, 2014 12:53
Macro-generated binary tree with if statements
# 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
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 August 29, 2015 14:05
Julia: Create Array from Range: Issue #4785
macro NO_GC(ex)
quote
gc_disable()
ret = $ex;
gc_enable()
gc()
end
end
# func1: vcat(range)
@quinnj
quinnj / gist:cf1e4e971d549dde8c7e
Created March 25, 2015 04:15
JSON Compiler Error
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
# 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
@quinnj
quinnj / gist:599ba66ea141ae91cbc4
Created May 20, 2015 21:43
Mmap.Array segfaults gdb
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]
# 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 / gist:2dc8bf55517906122b84
Created May 21, 2015 03:17
Reproducible segfault
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 / juliacon2015.jl
Last active August 29, 2015 14:23
Managing Data in Julia: Old Tricks, New Tricks Code
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 August 29, 2015 14:24
Base String Performance Benchmarks
### 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[],