Skip to content

Instantly share code, notes, and snippets.

View GoNZooo's full-sized avatar

Rickard Andersson GoNZooo

View GitHub Profile
Nothing :: struct {}
Just :: struct($T: typeid) {
value: T,
}
Maybe :: union($T: typeid) {
Nothing,
Just(T),
}
@GoNZooo
GoNZooo / language_integration.lua
Last active April 23, 2023 09:14
A basic setup for being able to interact with your `iex` sessions live via RPC calls
local M = {}
local erl_call = "erl -noshell -sname neovim -eval"
M.beam_dev_helper_rpc = function(node, module, function_name)
return "rpc:call(" .. node .. ", " .. module .. ", " .. function_name .. ", []), halt(0)."
end
M.execute_erlang_rpc_call = function(node, module, function_name)
local command = erl_call .. " \"" .. M.beam_dev_helper_rpc(node, module, function_name) .. "\""
startLink :: Arguments -> Effect (StartLinkResult (Process Message))
startLink arguments = do
SimpleServer.startLink arguments { init, handleInfo, name: Nothing }
init :: Arguments -> ProcessM Message (InitValue State)
init { socket } = do
self' <- Process.self
liftEffect $ Process.send self' ReadRequest
pure $ SimpleServer.initOk { socket, prices: MapSet.empty }
@GoNZooo
GoNZooo / Dockerfile
Created April 5, 2021 08:07
Basic development container for Yesod projects & VSCode
FROM fpco/stack-build:lts-16.31
RUN apt update && apt install -y inotify-tools
RUN stack --resolver lts-16.31 install yesod-bin
RUN stack --resolver lts-16.31 install ormolu
RUN stack --resolver lts-16.31 install hlint
@GoNZooo
GoNZooo / init.vim
Created September 20, 2020 11:11
`zig build` on save with `ALE`
" zig ALE linter by fubd @ FreeNode
" Author: Kevin Watters <kevinwatters@gmail.com>
" Description: This file adds support for checking zig code.
"
let g:ale_lint_on_text_changed = 'never'
let g:ale_zig_compiler = "zig"
function! ZigGetExecutable(buffer) abort
return g:ale_zig_compiler
// c version:
// #include <erl_nif.h>
// static ERL_NIF_TERM hello(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
// {
// return enif_make_string(env, "Hello World!", ERL_NIF_LATIN1);
// }
// static ErlNifFunc nif_funcs[] = {"hello", 0, hello};
@GoNZooo
GoNZooo / hello_world_with_link_error.zig
Created December 5, 2019 19:13
Link error hello world NIF
@GoNZooo
GoNZooo / hello_world_nif.zig
Last active December 5, 2019 20:14
Hello world NIF in zig
// c version:
// #include <erl_nif.h>
// static ERL_NIF_TERM hello(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
// {
// return enif_make_string(env, "Hello World!", ERL_NIF_LATIN1);
// }
// static ErlNifFunc nif_funcs[] = {"hello", 0, hello};
@GoNZooo
GoNZooo / text.ts
Created December 24, 2018 21:48
Phantom type variant in TypeScript
interface PlainText extends String {
__plaintext__: never
}
interface Base64Encoded extends String {
__base64Encoded__: never
}
interface Encrypted extends String {
__encrypted__: never
}
defmodule Consumer.Subscriptions do
def start_link do
Agent.start_link(fn -> %{} end, name: __MODULE__)
end
def get_subscribers(topic) do
Agent.get(__MODULE__, fn map -> Map.get(map, topic, []) end)
end
def add_subscription(sub, topic) do