Skip to content

Instantly share code, notes, and snippets.

View tshort's full-sized avatar

Tom Short tshort

  • Electric Power Research Institute
View GitHub Profile
@tshort
tshort / withmacro.md
Last active August 29, 2015 13:55
Playing with an @with macro

@with macro

Here is an @with macro to evaluate DataFrame (or even Dict) columns using references.

replace_syms(x, membernames) = x
function replace_syms(e::Expr, membernames)
    if e.head != :quote
        return Expr(e.head, (isempty(e.args) ? e.args : map(x -> replace_syms(x, membernames), e.args))...)
    else
@tshort
tshort / simondf.md
Last active August 29, 2015 14:11
Timing Simon's DataFrame

Simon's DataFrame mock-up using staged functions

module SimonDataFrame

type DataFrame{N,D}
    data::D
end
@tshort
tshort / t.md
Last active September 17, 2015 20:44

hello world

# /: comment
aK
 \ hello world
.asdf#wer 456
@tshort
tshort / str.jl
Created May 27, 2012 15:39
str for Julia
function str(io::IOStream, x, n::Int, indent)
T = typeof(x)
print(io, T, " ")
if isa(T, CompositeKind)
println(io)
if n > 0
for field in T.names
print(io, indent, " ", field, ": ")
str(io, getfield(x, field), n - 1, strcat(indent, " "))
end
@tshort
tshort / withdf.md
Created June 19, 2012 15:44
with/transform for DataFrames

Here are versions of with and transform! for DataFrame's. They each operate on columns.

function with(df::DataFrame, ex::Expr)
    # by-column with operation on df
    
    # helper function to replace symbols in ex with a reference to the
    # appropriate column in df
    replace_symbols(x, syms::Dict) = x
    replace_symbols(e::Expr, syms::Dict) = Expr(e.head, isempty(e.args) ? e.args : map(x -> replace_symbols(x, syms), e.args), e.typ)
@tshort
tshort / benchmarks.md
Created July 25, 2012 14:18
Julia benchmarks and bounds checking

Here are results of Julia's benchmarks with and without bounds checking:

DataFrame  (16,3)
                         type       benchmark     time
[1,]     "no bounds checking"           "fib" 0.210762
[2,]               "standard"           "fib" 0.211954
[3,]     "no bounds checking"        "mandel" 0.572634
[4,]               "standard"        "mandel" 0.587797
[5,]     "no bounds checking"     "parse_int" 0.207615
@tshort
tshort / t.md
Created August 20, 2012 22:34
test

test

# test

* bullet 1
  * bullet 1a

    indented=code();
@tshort
tshort / methodswith.md
Created September 5, 2012 21:50
Show method definitions that include a type

Here is the definition:

function methodswith(io, t::Type, m::Module)
    for nm in names(m)
        try
           mt = eval(nm)
           d = mt.env.defs
           while !is(d,())
               if any(map(x -> x == t, d.sig))
@tshort
tshort / README.md
Last active October 29, 2015 01:53 — forked from espinielli/README.md
Problems with a groupby transform involving sum

Problems with a groupby transform involving sum

In this spec, the groupby transform works just fine using any of median, count, or average. When I use sum, the graph doesn't show.

@tshort
tshort / README.md
Last active October 29, 2015 02:01
Vega working groupby version

Problems with a groupby transform involving sum

In this spec, the groupby transform works just fine using any of median, count, or average. When I use sum, the graph doesn't show. This version should display right.