Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / not_colored.zig
Created August 9, 2021 03:19
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
ityonemo / my_ets.ex
Last active April 23, 2021 19:34
Dumbest possible singleton ets table that is also responsibly written.
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
:ets.new(__MODULE__, [:set, :public, :named_table])
{:ok, nil, :hibernate}
catch
@ityonemo
ityonemo / chiaroscuro.js
Created April 23, 2021 05:36
Chiaroscuro - beam modules into wasm runtime
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
ityonemo / res_net_block.py
Last active January 20, 2021 03:17
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
ityonemo / test.md
Last active May 15, 2026 05:58
Zig in 30 minutes

A half-hour to learn Zig

This is inspired by https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/

Basics

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
ityonemo / algebra.zig
Last active January 4, 2021 13:54
Strategy for composable Algebra in 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
ityonemo / awaiting_resumed.zig
Created December 6, 2020 00:41
awaiting resumed ??? example
const std = @import("std");
const print = std.debug.print;
var yielded = false;
fn yield() void {
yielded = true;
suspend;
}
@ityonemo
ityonemo / lisp.ex
Created September 20, 2020 06:41
Lisp in Elixir
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 """
@ityonemo
ityonemo / gromacs.md
Last active July 30, 2020 19:40
gromacs installation on lambda v100

Gromacs on Lambda V100 nodes

Installation

  1. Install singularity
sudo apt-get update && sudo apt-get install -y build-essential libssl-dev uuid-dev \
  libgpgme11-dev squashfs-tools libseccomp-dev wget pkg-config git cryptsetup
@ityonemo
ityonemo / itinerary.jl
Created June 30, 2020 16:10
itinerary code
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
Base.next(r::rows, idx) = (r.tgt[idx, :], idx + 1)
Base.done(r::rows, idx) = idx > size(r.tgt, 1)