Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / nbody-zig.zig
Last active June 17, 2020 02:40
benchmarks game: zig
//! The Computer Language Benchmarks Game
//! https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
//!
//! This implementation is written in simple and idiomatic Zig.
//! The only optimization is using SIMD vector intrinsics.
const std = @import("std");
/////////////////////////////////////////////////////////////////////////
// important constants. ALLCAPS constants are not idiomatic Zig, but it's
{
"Inspect": {
"prefix": "ins",
"body": "|> IO.inspect(label: \"$0$TM_LINE_NUMBER\")",
"description": "Adds a pipeline with a labelled `IO.inspect`",
}
}
@ityonemo
ityonemo / gist:4036b50fff8dcf373872440d3eee122b
Created May 22, 2020 22:19
make-podman-like-singularity
#!/bin/sh
IMAGE=<your image id>
CMD=<your cmd>
podman run --net host -v $HOME:$HOME -e HOME="$HOME" -w$(PWD) -it $IMAGE "$CMD $@"
@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)