Skip to content

Instantly share code, notes, and snippets.

ityonemo / foo.ex
Created Sep 13, 2021
protocol thingy
View foo.ex
defprotocol Proto do
def generic_getter(value)
defmodule A do
defstruct [:a]
def generic_getter(v), do: v.a
defimpl Proto do
defdelegate generic_getter(value), do: A
ityonemo / dot.zig
Last active Aug 15, 2021
generic dot product zig
View dot.zig
const std = @import("std");
fn childOf(comptime T: type) type {
return switch (@typeInfo(T)) {
.Vector => |vector| vector.child,
.Array => |array| array.child,
.Pointer => |pointer| {
switch (pointer.size) {
.Slice => {},
.One => {
View not_colored.zig
// for testing purposes only, a mock of the c stdlib that provides calloc and malloc backed by the
// testing allocator. Stores last length in a global: Definitely not threadsafe.
var test_allocator_total_length: usize = undefined;
const MockedLibC = struct {
pub fn calloc(count: usize, size: usize) ?[*]u8 {
test_allocator_total_length = count * size;
var slice = std.testing.allocator.alloc(u8, test_allocator_total_length) catch return null;
const result_pointer = @ptrCast([*]u8, slice.ptr);
@memset(result_pointer, 0, test_allocator_total_length);
ityonemo / my_ets.ex
Last active Apr 23, 2021
Dumbest possible singleton ets table that is also responsibly written.
View my_ets.ex
defmodule MyEts do
use GenServer
def start_link(_), do: GenServer.start_link(__MODULE__, nil, name: __MODULE__)
@spec init(any) :: :ignore | {:ok, nil, :hibernate}
def init(_) do, [:set, :public, :named_table])
{:ok, nil, :hibernate}
ityonemo / chiaroscuro.js
Created Apr 23, 2021
Chiaroscuro - beam modules into wasm runtime
View chiaroscuro.js
const get_memory = () => chiaroscuro.memory;
var chiaroscuro = {
imports: {
env: {
// exported functions
abort(msg, file, line, column) {
console.error("abort(" + msg + ")@" + file + " " + line + ":" + column);
jsConsoleLogInt(int) {
ityonemo /
Last active Jan 20, 2021
Testing ResNet Components
import torch
import torch.nn as nn
class ResNetBlock(nn.Module):
def __init__(self, input_channel_count, internal_channel_count, downsampler = None, stride=1, layers = 'all'):
# input_channel_count: An image tensor is a h*w*k tensor where k is represents
# how many channels, naively, groups of features discovered by the ml model.
# the shape of the input tensor is h*w*input_channel.
# internal_channel_count: like above, but the shape of the output tensor is
# h*w*internal_channel_count. In a typical convnet strategy, you will want the
ityonemo /
Last active Sep 9, 2021
Zig in 30 minutes

A half-hour to learn Zig

This is inspired by


the command zig run my_code.zig will compile and immediately run your Zig program. Each of these cells contains a zig program that you can try to run (some of them contain compile-time errors that you can comment out to play with)

ityonemo / algebra.zig
Last active Jan 4, 2021
Strategy for composable Algebra in Zig
View algebra.zig
const std = @import("std");
pub fn Algebra(comptime fields: []const type) type {
return struct{
pub fn @"<+>"(a: anytype, b: anytype) FieldFor(@TypeOf(a), @TypeOf(b)).Type {
const F: type = FieldFor(@TypeOf(a), @TypeOf(b));
return F.@"<+>"(a, b);
pub fn FieldFor(comptime AType: type, comptime BType: type) type {
ityonemo / awaiting_resumed.zig
Created Dec 6, 2020
awaiting resumed ??? example
View awaiting_resumed.zig
const std = @import("std");
const print = std.debug.print;
var yielded = false;
fn yield() void {
yielded = true;
ityonemo / lisp.ex
Created Sep 20, 2020
Lisp in Elixir
View lisp.ex
defmodule Lisp do
@type ast :: [String.t | number | ast]
@type token :: :lp | :rp | number | String.t
@letters Enum.concat(?a..?z, ?A..?Z)
@numbers ?0..?9
@operators [?+]
@doc """