Skip to content

Instantly share code, notes, and snippets.

View johnmyleswhite's full-sized avatar

John Myles White johnmyleswhite

View GitHub Profile
@johnmyleswhite
johnmyleswhite / impossible_benchmarking.txt
Created November 4, 2014 15:07
This is why benchmarking is nearly impossible to get right
JMWMacBookPro:CSVTools johnmyleswhite$ julia test/benchmark.jl
0.201432656
0.206143505
0.204748861
0.201648006
0.204058938
0.200518181
0.208433545
0.19637816
0.210459992
@johnmyleswhite
johnmyleswhite / getindex.jl
Last active August 29, 2015 14:09
Making NullableVector's Fast
immutable NullableVector{T}
isnull::BitVector
values::Vector{T}
end
Base.length(nv::NullableVector) = length(nv.isnull)
function Base.getindex(nv::NullableVector{Float64}, i::Integer)
if nv.isnull[i]
return Nullable{Float64}()
@johnmyleswhite
johnmyleswhite / replace.jl
Last active August 29, 2015 14:10
Safely replace specify "positions" in a string
function replace(s::String, pos::Integer, val::Char)
io = IOBuffer()
i = 0
for c in s
i += 1
if i != pos
write(io, c)
else
write(io, val)
end
@johnmyleswhite
johnmyleswhite / na_integer.R
Created December 6, 2014 17:58
Integer Sentinel Values and Overflow
> 2147483647L + 1L
[1] NA
Warning message:
In 2147483647L + 1L : NAs produced by integer overflow
> 46341L * 46341L
[1] NA
Warning message:
In 46341L * 46341L : NAs produced by integer overflow
@johnmyleswhite
johnmyleswhite / ids.csv
Created December 12, 2014 16:34
The 64-bit integer nightmare in base R continues
ID64 ID32
9223372036854775807 1
@johnmyleswhite
johnmyleswhite / sql_vs_df.jl
Last active August 29, 2015 14:11
Navigating the gaps between SQL tables and DataFrames in a typed language
##############################################################################
# Problem 1: SELECT COUNT(DISTINCT(column_1)) from table_1
##############################################################################
# Ideally, solution should look something like the following code
function count_distinct(table::TabularData)
values = Set{eltype(table.column_1)}()
for value in table.column_1
push!(values, value)
@johnmyleswhite
johnmyleswhite / array.jl
Created May 17, 2015 20:02
Iteration invalidation for arrays
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.4.0-dev+4878 (2015-05-17 18:08 UTC)
_/ |\__'_|_|_|\__'_| | Commit b3116d4 (0 days old master)
|__/ | x86_64-apple-darwin14.3.0
julia> xs = [1, 2, 3]
@johnmyleswhite
johnmyleswhite / life_nulls.jl
Last active August 29, 2015 14:22
lift_nulls.jl
# Implement the unary operators: +, -, !, and ~
for f in (
:(Base.(:+)),
:(Base.(:-)),
:(Base.(:!)),
:(Base.(:~)),
)
@eval begin
function $(f){S}(x::Nullable{S})
resval = $(f)(x.value)
# Implement the unary operators: +, -, !, and ~
using NullableArrays
@noinline throw_error() = error()
for f in (
:(Base.(:+)),
:(Base.(:-)),
:(Base.(:!)),