Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / expressive.jl
Last active October 26, 2017 01:42
expressive C++17 in Julia
(length(ARGS) < 4) && (println("error, insufficient arguments"); exit(1))
infile, column, replace, outfile = ARGS
function replace_column(idx)
(idx == 0) && (println("column name doesn’t exist in the input file"); exit(1))
mtx2 = copy(mtx)
mtx2[2:end,idx] = collect(Iterators.repeated(replace,size(mtx,1) - 1))
mtx2
@ityonemo
ityonemo / find first free
Created October 18, 2017 03:08
find_first_free.ex
defmodule T do
def find_first_free(arr), do: find_first_free(arr, 0, [])
def find_first_free([], lowest_free, _leftovers), do: lowest_free
def find_first_free([head | tail], lowest_free, leftovers) do
if (lowest_free == head) do
find_first_free(tail, lowest_free + 1, leftovers)
else
find_first_free(tail, lowest_free, [head | leftovers])
end
end
@ityonemo
ityonemo / algebra.jl
Last active October 9, 2017 16:29
AST-fun with julia
function simplify(e::Expr)
if e.head == :call
if e.args[1] == :+
simplify_add(e)
end
end
end
function simplify_add(e::Expr)
terms = Dict{Symbol, Int}()
@ityonemo
ityonemo / drivingtaxes.jl
Last active September 5, 2017 09:41
everitt taxes '17
#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 / erlang.def
Created June 2, 2017 00:42
erlang def
BootStrap: debootstrap
OSVersion: xenial
MirrorURL: http://us.archive.ubuntu.com/ubuntu
Include: bash python
%post
##############################################################################
## general system stuff
# respect license requirements
@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.
@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 / 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 / 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
function magicsum(arg){
var sumsofar = 0;
var f;
f = function(inner_arg){
if (inner_arg){
sumsofar += inner_arg;
return f;
} else {
return sumsofar;