Skip to content

Instantly share code, notes, and snippets.

View chiroptical's full-sized avatar

Barry Moore chiroptical

View GitHub Profile
W def random_code() do ■ Function random_code/0 has no local return
┆ :crypto.strong_rand_bytes(5)
┆ |> Base.encode32(padding: false, lower: true)
┆ end
@chiroptical
chiroptical / check_order.erl
Created June 24, 2023 21:01
Checking order of operations for async call within sync call
-module(check_order).
-behaviour(gen_server).
-export([
start_link/0,
thing/1,
init/1,
handle_call/3,
handle_cast/2
]).
@chiroptical
chiroptical / Maybe.kt
Created December 18, 2022 19:17
The maybe function in Kotlin
// The same behavior as the Haskell version
fun <T, U> T?.maybe(default: U, f: (T) -> U) =
when (this) {
null -> default
else -> f(this)
}
// When `f` returns null you get the default
fun <T, U> T?.maybeBad(default: U, f: (T) -> U) =
this?.let { f(it) } ?: default
@chiroptical
chiroptical / layout.json
Last active September 29, 2022 15:27
Keyboardio Model 100 Layout
{
"keymaps": [
[
{"code": 46, "label": {"base": "=", "shifted": "+"}},
{"code": 30, "label": {"base": "1", "shifted": "!"}},
{"code": 31, "label": {"base": "2", "shifted": "@"}},
{"code": 32, "label": {"base": "3", "shifted": "#"}},
{"code": 33, "label": {"base": "4", "shifted": "$"}},
{"code": 34, "label": {"base": "5", "shifted": "%"}},
{
@chiroptical
chiroptical / babyShark.hs
Last active February 3, 2023 15:23
Baby shark as a Haskell program
{-# LANGUAGE BlockArguments #-}
module Main where
main :: IO ()
main = do
babyShark
do do do do do do babyShark
do do do do do do babyShark
do do do do do do babyShark
@chiroptical
chiroptical / Meeting-05-08-21.md
Last active May 8, 2021 14:48
Streaming Tools and Functional Programming Hackathon

Participants: chiroptical, jappiejappie

Putting together some initial ideas for the Hackathon

Notes:

  • Primary goal should be learning something new
  • With the new "Stage" channels we can probably just use Discord. This is on-brand because I imagine some of us will work on Discord bots
  • Keep the scope small for the first incarnation, no reason to bite off more than we can chew
    • Choose the cross section of "Streaming Tools" AND "Functional Programming" will keep the scope small
  • That being said, I think it is fine if projects don't fall in this category
@chiroptical
chiroptical / status.css
Last active November 16, 2020 16:34
CRC Status CSS
table {
width: 100%;
text-align: center;
color: rgb(230 230 230 / 1);
}
table,
th,
td {
border: 1px solid black;
@chiroptical
chiroptical / commands.sh
Created November 3, 2020 18:13
Installing mpi4py and hdf5 [parallel] on H2P
# The installation below expects that HDF5 is compiled with shared and parallel capabilities
# 1. Load python and mpi libraries
module purge
module load python/3.7.0 venv/wrap openmpi/3.1.4 hdf5/1.10.7
# 2. Make a new virtual environment (or load an existing one)
mkvirtualenv test
workon test
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
module Free where
import Control.Monad.Free (Free (..), iterM, liftF)
import qualified Control.Monad.Trans.State as S
safeHead :: [a] -> Maybe a
@chiroptical
chiroptical / abilities.md
Last active October 30, 2020 02:34
A proposal for improving the Unison abilities documentation
title description
Abilities in Unison
Unison's type system tracks which functions can do I/O, and the same language feature, called _abilities_ can be used for many other things, too. This is a tutorial on abilities.

Abilities in Unison

Here are two functions in Unison. One performs I/O (it writes to the console) and so it has an interesting type we'll be explaining much more in this tutorial: