Skip to content

Instantly share code, notes, and snippets.

View johnmyleswhite's full-sized avatar

John Myles White johnmyleswhite

View GitHub Profile
@johnmyleswhite
johnmyleswhite / note.md
Created August 27, 2014 17:35
Modifying Julia

If you make a change to Julia Base by adding a new file, you'll probably want to do the following:

  • Add the file as an include in base/sysimg.jl
  • Add the few exported names to base/exports.jl
  • Add a test file in test and then activate the test by modifying test/runtests.jl

If you only modify an existing file, you should just update base/exports.jl.

@johnmyleswhite
johnmyleswhite / type_unstable.R
Created September 6, 2014 00:25
Type instability when using "generic" NA value
> type.unstable <- function(x) {
+ if (x > 0) {
+ return("foo")
+ } else {
+ return(NA)
+ }
+ }
>
> class(type.unstable(0))
[1] "logical"
@johnmyleswhite
johnmyleswhite / values_etc.md
Last active August 29, 2015 14:06
[WIP DRAFT] Values vs. Bindings: The Map is Not the Territory

Values vs. Bindings: The Map is Not the Territory

Many newcomers to Julia are confused by the seemingly dissimilar behaviors of the following two functions:

julia> a = [1, 2, 3]
3-element Array{Int64,1}:
 1
 2
@johnmyleswhite
johnmyleswhite / roadmap.md
Last active August 29, 2015 14:06
0.4 Roadmap for the Tabular Data Ecosystem
  • Replace NAtype with Nullable{T}
    • This will substantially change the semantics of missing data
      • You will have to fully specify how missing values are handled
      • You cannot leave off thinking about missing values to the first time you hit one
      • Your code will become type-stable and will run much faster (~100x)
      • The name NA will be replaced by NULL
        • This implies isna will become isnull
      • There will be no more attempts to define functions over NA
        • This includes Booleans: there will be no more three-valued logic
  • Replace DataArray with NullableArray
@johnmyleswhite
johnmyleswhite / gist:e5992d598f80f1cdd66b
Created September 13, 2014 17:22
Programming and Developmental Psychology
Missingness as boxes with unknown content. Cf. the Smarties task: http://www.jstor.org/discover/10.2307/1130386?uid=3739920&uid=2&uid=4&uid=3739256&sid=21104622658277
Understanding pointers and mutable containers. Confer the development of object permanence and object identity: http://en.wikipedia.org/wiki/Object_permanence
@johnmyleswhite
johnmyleswhite / indexing.R
Created September 18, 2014 05:32
R indexing showcases all possible design theories
> v <- c(1, 2, 3, 4)
> v[1]
[1] 1
> v[4]
[1] 4
> v[0]
numeric(0)
> v[5]
[1] NA
> v[-1]
@johnmyleswhite
johnmyleswhite / na_woes.R
Created September 20, 2014 17:27
The dangers of rendering many distinct NA's as if they were all the same
> v <- c(1, 2, 3, 4)
> ind <- NA
> ind
[1] NA
> v[ind]
[1] NA NA NA NA
> ind <- -ind
> ind
[1] NA
> v[ind]
@johnmyleswhite
johnmyleswhite / gist:14dbd928019669faef82
Last active August 29, 2015 14:06
Benchmarking Resources
@johnmyleswhite
johnmyleswhite / pausable.jl
Created October 22, 2014 15:46
Pausable Loops
# TODO: Need different behavior for the REPL
function set_stdin_mode!(raw::Bool)
res = ccall(
:jl_tty_set_mode,
Int32,
(Ptr{Void}, Int32),
STDIN.handle,
int32(raw)
)
return res != -1
@johnmyleswhite
johnmyleswhite / factor_woes.R
Last active August 29, 2015 14:08
Factors expose way too much of their implementation
> x <- c(4, 1, 3, 5, 2)
> # Sorts levels automatically
> f1 <- factor(x)
> f1
[1] 4 1 3 5 2
Levels: 1 2 3 4 5
> # Does not sort levels automatically
> f2 <- factor(x, levels = c(3, 4, 5, 2, 1))