Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / uppertriangular.jl
Created September 28, 2016 04:36
Iterates over upper triangular indices.
#upper triangular indices - iterates over upper triangular indices in a list of
#indices.
type uppertriangular; iterable; end
Base.start(x::uppertriangular) = (1, 1)
function Base.next(x::uppertriangular, state)
(idx1, idx2) = state
next1 = idx1
next2 = idx2 + 1
if next2 > length(x.iterable)
@ityonemo
ityonemo / driving.jl
Created October 16, 2016 20:53
queries google maps to tabulate driving distances.
#drivingtaxes.jl
using JSON
#make sure we have what we're looking for.
(length(ARGS) == 0) && throw(ErrorException("needs a file name"))
###################################
#rows iterator
type rows; tgt::Matrix; end
Base.start(r::rows) = 1
@ityonemo
ityonemo / column_sort_inplace.jl
Created November 2, 2016 01:58
sorts a matrix by columns in place
function column_sort_inplace!(matrix::AbstractMatrix, fn::Function)
p = sort_columns_return_permutation(matrix, fn)
#first, find the permutation of the matrix, reduced by rows.
#create an array that signals the completion status of the process.
completion = falses(length(p))
#store important indices
current_root = 1 #root of the current cycle we're operating on.
current_index = 1 #array index we're operating on.
#next, allocate a short array that looks like the vector.
@ityonemo
ityonemo / bloom.jl
Created November 3, 2016 23:00
bloom filter in 65 minutes in julia.
#bloom.jl - takes a file, reads binary data from the file and does whatever a
#bloom filter would do.
doc"""
`BloomFilter{V}`
defines a bloom filter over a value type V
"""
type BloomFilter{V}
filter::BitVector
hashes::Array{Function, 1}
#supson.jl
type ツ; end
_(::Type{ツ}) = ツ
*(::Type{ツ}, ::Function) = ツ
type ⎺; end
Base.:\(::Type{⎺},::Type{ツ}) = ツ
Base.:/(::Type{ツ},::Type{⎺}) = true
⎺\_(ツ)_/⎺ #==> true
function magicsum(arg){
var sumsofar = 0;
var f;
f = function(inner_arg){
if (inner_arg){
sumsofar += inner_arg;
return f;
} else {
return sumsofar;
@ityonemo
ityonemo / tree_printer.jl
Created May 19, 2017 01:42
prints trees, yay
## binary_tree_print.jl
#binary tree defined as the following:
type Tree{T}
node::T
left::Union{Tree{T}, Void}
right::Union{Tree{T}, Void}
end
@ityonemo
ityonemo / elliptic.jl
Last active May 29, 2017 02:18
(unsecure) elliptic numbers is julia
#elliptic.jl
#we'll make an "elliptic curve type" that is empty with no parameters. The advantage to this is that the parameter values
#take no memory in the point representation and are JITted in as assembler immediates.
type EllipticCurve{A, B}; end
#properties of the elliptic curves
discriminant{A,B}(E::Type{EllipticCurve{A,B}}) = -16 * (4*A^3 + 27*B^2)
issmooth(E) = discriminant(E) != 0
haspoint{A,B}(E::Type{EllipticCurve{A,B}}, x, y) = y^2 == x^3 + A*x + B
@ityonemo
ityonemo / primefield.jl
Created May 29, 2017 02:21
trivial and possibly inefficient prime field implementation
#primefield.jl
type PrimeField{P}
intval::UInt64
function PrimeField(n)
new(n % P)
end
end
Base.:+{P}(x::PrimeField{P}, y::PrimeField{P}) = PrimeField{P}(x.intval + y.intval)
@ityonemo
ityonemo / geoserver.ex
Created June 1, 2017 01:39
playing with elixir
defmodule Geoserver do
@moduledoc """
Documentation for Geoserver.
"""
@doc """
latlongdistance({ϕ1, λ1}, {ϕ2, λ2}) gives the distance, in kilometers, between
two points on the globe defined by {ϕ1, λ1}, {ϕ2, λ2}. Negative ϕ values are
in the southern hemisphere and negative λ are in the western hemisphere.