LOCAL_LIB_PATH = expanduser("~/lib/julia") # My local package paths are in lib/julia append!(LOAD_PATH, [LOCAL_LIB_PATH]) # macro that implements import Module as Alias mostly used as a helper in the # repl. Not to be used in Packages since this macro is not guaranteed to exist # elsewhere. macro imports(mexpr, mod, sexpr) # enforce our syntax if mod != :as error("Expected as modifier for import got $mod") end # mexpr must be a symbol if typeof(mexpr) != Symbol error("invalid import statement, expected identifier got $mexpr") end # sexpr must be a symbol if typeof(sexpr) != Symbol error("invalid import statement, expected identifier got $mexpr") end # We can't just quote the import syntax so we construct the import # expression by hand iexpr = Expr(:import) iexpr.args = [mexpr] expr2 = quote $iexpr $sexpr = $mexpr end # finally we escape the whole thing since we need all the symbols to be # evaluated/created in the callers scope. return esc(:($(eval(expr2)))) end containedtypes(m::Module) = whos(m, r"[[:upper:]]") # non sampled versions of some statistics functions variance(v::Vector) = mean((v - mean(v)).^2) stddev(v::Vector) = sqrt(variance(v)) # multiprocess configuration helpers function procsetup() delta = CPU_CORES - nprocs() if delta > 0 addprocs(delta) end end # array utilities hasprefix(prefix::Vector, len, str) = length(str) >= len && str[1:len] == prefix hasprefix(prefix::Vector, str) = hasprefix(prefix, length(prefix), str) function eagerzip(iters...) numiters = length(iters) minlen = minimum(map(length, iters)) ar = [tuple(map(x->x[1], iters)...)] for i in 2:minlen push!(ar, tuple(map(x->x[i], iters)...)) end return ar end guid2base64(input) = base64(hex2bytes(replace(input, "-", ""))) #Using Codecs # #Tobytes(s) = convert(Vector{Uint8}, s) # #Base64decode(text::UTF8String) = base64decode(tobytes(text)) #Base64decode(text::ASCIIString) = base64decode(tobytes(text)) #Base64decode(text::Vector{Uint8}) = decode(Base64, filter(c -> c != '\n', text)) # all factors not just prime factors. function factors(n) f = [one(n)] for (p,e) in factor(n) f = reduce(vcat, f, [f*p^j for j in 1:e]) end return f end