Skip to content

Instantly share code, notes, and snippets.

View afternoon's full-sized avatar

Ben Godfrey afternoon

View GitHub Profile
@afternoon
afternoon / .zshrc
Created September 19, 2023 19:44
Lean and mean .zshrc
autoload -Uz compinit
compinit
alias ls="ls -F --color"
alias vi="/usr/local/bin/nvim"
PS1="
▶ %F{81}%U%~%u%f %F{8}$%f "
#![no_std]
#![no_main]
use panic_probe as _;
mod microgroove {
mod sequencer {
use heapless::Vec;
use midi_types::{Channel, Note, Value14, Value7};
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define DISPLAY_WIDTH_PX 128
#define DISPLAY_HEIGHT_PX 64
#define DISPLAY_ADDRESS 0x3D
Adafruit_SSD1306 display(DISPLAY_WIDTH_PX, DISPLAY_HEIGHT_PX, &Wire);
#include <Arduino.h>
#include <RotaryEncoder.h>
#define PIN_IN1 2
#define PIN_IN2 3
RotaryEncoder encoder(PIN_IN1, PIN_IN2);
int lastPos = 0;
void setup() {
@afternoon
afternoon / helloworld.c
Created December 6, 2016 18:15
Hello world C -> LLVM IR -> GNU assembly
#include <stdio.h>
int main() {
printf("Hello World!\n");
}
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 12
.globl _main
.p2align 4, 0x90
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp0:
.cfi_def_cfa_offset 16
@afternoon
afternoon / StreamEditor.hs
Created November 23, 2016 13:31
A DSL for editing streams defined in Haskell using a simple Monad
--
-- Documents are objects to which a set of edits can be performed.
--
-- A simple example is a text document which is subjected to a number of find
-- and replace operations.
--
-- This module implements a simple state monad which allows operations to be
-- written using do notation. Example
--
-- badfiction = "11pm. Night time in the city."

A functional programming language for low-latency microservices

  • Easy to get started for mainstream programmers (JavaScript, Java, Python, Ruby), don't need to know monads to print a string, no enforcement of pure/impure in the type system, no Lisp-syntax (use Clojure if you want that), strict evaluation
  • Readable programs: one true way to layout code, significant whitespace, minimal noise in code, no custom operators like .&&.
  • Rich set of base data types: int, float, decimal, unicode strings,
@afternoon
afternoon / pairpeers.clj
Last active July 6, 2016 17:06
Map a function over a CSV file in Clojure
(ns pairpeers.core
(:require [clojure.data.csv :as csv]))
(defn pair-with-first [[s & more]]
(map list (repeat s) more))
(defn rows->peers [rows]
(->> rows
(map pair-with-first)
(reduce concat)))
@afternoon
afternoon / separate_zeroes.py
Created September 1, 2015 20:24
Given an array of numbers (1,2,3,8,0,2,2,0,10), move all 0s to the right end and all other numbers to the left while keeping relative order of non-zero numbers. Has to be linear in time and in-place.
def separate_zeroes(nums):
'''
Given an array of numbers (1,2,3,8,0,2,2,0,10), move all 0s to the right end and all other numbers to the left while keeping relative order of non-zero numbers. Has to be linear in time and in-place.
>>> separate_zeroes([1, 2, 3, 8, 0, 2, 2, 0, 10])
[1, 2, 3, 8, 2, 2, 10, 0, 0]
>>> separate_zeroes([1, 1, 1, 0, 1, 0, 0, 1])
[1, 1, 1, 1, 1, 0, 0, 0]