Skip to content

Instantly share code, notes, and snippets.

@rhwlo
rhwlo / kinesis-arduino.ino
Created November 23, 2020 17:19
Arduino sketch for registering keypresses from the Kinesis and logging them to serial
#include "Arduino.h"
#define KEY_UP 1
#define KEY_DN 0
/* Connect the Arduino to the socket of the keyboard's main microcontroller
(an AT89S8253: http://ww1.microchip.com/downloads/en/DeviceDoc/doc3286.pdf)
with the following pins:
Kinesis U1 Arduino
@rhwlo
rhwlo / kanelbullar-recipe.md
Last active October 4, 2022 18:32
Recipe for Swedish cinnamon buns (kanelbullar)

Swedish Cinnamon Buns (Kanelbullar)

ingredients

  • for the dough:
    • 1¼ cup (300 mL) milk or almond milk
    • ⅓ cup (75 g) butter or margarine
    • 2 teaspoons (1 packet, or 6 g) yeast
    • ½ cup (100 mL) sugar
  • 4 ¼ cups flour
const f = {
m() {
return this.n();
},
n() {
return "hi!";
}
};
f.m(); // "hi!"
f.n(); // "hi!"
import asyncio
import pytest
class Mutable:
def __init__(self) -> None:
self._mutations: int = 0
@property
# look, it's art. okay? it's art about how functional programming in Python is sometimes ugly
#
# it just so happens this art has a terrible worst-case complexity.
#
# usage: echo "1 2 3" | python countdown.py
from itertools import chain, izip_longest, product, permutations
import operator
import sys
@rhwlo
rhwlo / example_client.py
Last active January 13, 2019 18:26
example server and client to reproduce a Reason-Phrase bug in Python’s aiohttp library (https://github.com/aio-libs/aiohttp/issues/3532)
import asyncio
from urllib.parse import urljoin
from aiohttp.client import request
async def main():
for endpoint in ["/success_without_reason", "/failure_without_reason"]:
async with request("get", urljoin("http://0.0.0.0:8080",
endpoint)) as resp:
@rhwlo
rhwlo / duration_parse.vue
Last active August 25, 2018 04:41
parse duration strings in JS and format them
<script>
const formatDuration = ({hours, minutes, seconds}) => {
const finalSeconds = seconds % 60;
const finalMinutes = ((minutes || 0) + Math.floor(seconds / 60)) % 60;
const finalHours = Math.floor((minutes || 0) / 60 + seconds / 3600) + (hours || 0);
const formattedHours = (finalHours && finalHours > 0) ? `${finalHours}h` : '';
const formattedMinutes = (finalMinutes && finalMinutes > 0) ? `${finalMinutes}m` : '';
const formattedSeconds = (finalSeconds && finalSeconds > 0) ? `${finalSeconds}s` : '';
return `${formattedHours}${formattedMinutes}${formattedSeconds}`;
};
set editing-mode vi
set keymap vi
set convert-meta on
# invoke with, ex., 'echo "10010 10110" | sed -rf adder.sed'
:add
p
# If we have two final zeroes:
/^[01]*0\s[01]*0$/ {
# drop the final zeroes
s/^([01]*)0(\s)([01]*)0$/\1\2\3/
# swap the hold buffer in
x
# add a 0 at the front
@rhwlo
rhwlo / full-clock-autogen.svg
Created March 30, 2017 09:46
autogenerating a clock with an optional slice taken out for time. The things I do on vacation ...
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.