Skip to content

Instantly share code, notes, and snippets.

@cscheid
cscheid / main.jl
Created Sep 10, 2014
bare-bones stress majorization in julia
View main.jl
# You should totally ignore this because it's the first piece of Julia I've ever written.
# 2-clause BSD, blah.
function make_cycle(n)
result = Dict{Int32, Array{Int32}}()
for i = 1:n
ii = i - 1
push!(result, i, [1 + ((i+n-2) % n), 1 + i % n])
end
result
@quinnj
quinnj / juliacon2015.jl
Last active Aug 29, 2015
Managing Data in Julia: Old Tricks, New Tricks Code
View juliacon2015.jl
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")
View DataFrameX.jl
type DataFrame{N,D}
data::D
end
immutable Field{s}
end
Field(s::Symbol) = Field{s}()
function DataFrame(;kwds...)
@simonbyrne
simonbyrne / jbug.jl
Created Oct 15, 2012
A bugs-type sampler in julia
View jbug.jl
require("extras/distributions.jl")
require("slicesampler.jl")
import Distributions.*
macro buildslicesampler(model)
# pull apart the model into variables and distributions
variables = Dict{Symbol,Expr}()
unboundvars = Set{Symbol}()
for line in model.args
@kjhealy
kjhealy / st2binding
Created Nov 5, 2012
R and ST2's REPL. Keybinding Example
View st2binding
[
// Modified Sublime-REPL keybindings for an "R-friendly" set of shortcuts.
// Copy and paste this text into the Key Bindings - User (under Preferences menu).
// For more information, see http://tomschenkjr.net/2012/05/17/using-sublime-text-2-for-r/
// Executes a selection of text in REPL, latter only displays code and does not execute
{ "keys": ["super+shift+enter"], "command": "repl_transfer_current", "args": {"scope": "selection"}},
// I disabled this one
//{ "keys": ["super+shift+enter", "r"], "command": "repl_transfer_current", "args": {"scope": "selection", "action":"view_write"}},
anonymous
anonymous / Chutes.jl
Created Dec 24, 2012
Graphs in Julia... some preliminary thoughts
View Chutes.jl
module Chutes
abstract Graph
abstract DGraph <: Graph
abstract UGraph <: Graph
typealias LabelType Dict{Int,Any}
type DenseGraph <: Graph
mat :: Matrix{Uint8}
@dmbates
dmbates / gist:5303570
Last active Dec 15, 2015
Formula, ModelFrame and ModelMatrix types
View gist:5303570

Formula, ModelFrame and ModelMatrix types

In R, the functions for fitting statistical models based on a linear predictor usually allow for a formula/data specification of the model. The data part is a data.frame object in R. In Julia the corresponding type is a DataFrame as implemented in the DataFrames package.

A formula object in R is an expression whose top-level operator is a unary or binary tilde, ~. The interpretation of many operators, including +, *, ^, \ and : are overridden in the formula language. See the result of

?formula

in R for the details.

@cykl
cykl / HLLMergeBenchmark.java
Created Jun 2, 2013
Benchmarks for stream-lib/faster_hll
View HLLMergeBenchmark.java
package bench;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.BenchmarkType;
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.State;
@carlobaldassi
carlobaldassi / nzipperf.jl
Last active Dec 18, 2015
Alternative Zip iterator, with better performance than the one in base, but whose performance degrades if calls to start,next,done are inlined.
View nzipperf.jl
module NZipTest
import Base.start, Base.next, Base.done, Base.length
using Benchmark
immutable NZip0
end
immutable NZip1{I1}
i1::I1
@romainfrancois
romainfrancois / gist:6981372
Last active Dec 25, 2015
Reading the internal function table
View gist:6981372
#include <Rcpp.h>
using namespace Rcpp;
typedef SEXP (*CCODE)(SEXP, SEXP, SEXP, SEXP);
/* Information for Deparsing Expressions */
typedef enum {
PP_INVALID = 0,
PP_ASSIGN = 1,
PP_ASSIGN2 = 2,