Skip to content

Instantly share code, notes, and snippets.

View wpcarro's full-sized avatar

William Carroll wpcarro

View GitHub Profile
@wpcarro
wpcarro / updatef.el
Created October 18, 2019 13:01
Updatef - alternative to setf for applying functions to fields in Elisp.
(require 'string) ;; personal library
(require 'dash)
(defmacro updatef (type field f xs)
"Apply F to FIELD in XS, which is a struct of TYPE."
(let ((copier (->> type
symbol-name
(string/prepend "copy-")
intern))
(accessor (->> field
@wpcarro
wpcarro / retry_loop.py
Created October 29, 2019 17:37
Simple retry loop in python with error simulation.
import random
def danger():
if random.choice([True, False]):
raise Exception
def main():
"""Attempt to loop `loop_count` times. Simulate random errors and create a
@wpcarro
wpcarro / bytes.el
Created November 9, 2019 18:06
Represent integer byte values in a human readable format.
;;; bytes.el --- Working with byte values -*- lexical-binding: t -*-
;; Author: William Carroll <[email protected]>
;;; Commentary:
;; Functions to help with human-readable representations of byte values.
;;
;; Usage:
;; See the test cases for example usage. Or better yet, I should use a type of
;; structured documentation that would allow me to expose a view into the test
;; suite here. Is this currently possible in Elisp?
@wpcarro
wpcarro / graphviz-compiler.py
Created November 11, 2019 17:21
Transform a neighbors table into GraphViz source code for visualization purposes.
from graphviz import Digraph
from collections import deque
# There are three ways to model a graph:
# 1. Edge list: [(Vertex, Vertex)]
# 2. Neighbors table: Map(Vertex, [Vertex])
# 3. Adjacency matrix: [[Boolean]]
#
# The following graph is a neighbors table.
g = {
@wpcarro
wpcarro / timestring.el
Created January 30, 2020 22:27
Some Emacs functions to copy
;; I was making some API calls where a URL needed a `since` parameter that of an
;; RFC 3339 encoded string.
;;
;; Because I didn't know what a RFC 3339 encoded
;; string was at the time, and because I didn't know what its format was
;; according to strftime, and because I'm most likely to forget both of these
;; things by the next time that I need something similar, I decided to write
;; this package so that I can accumulate a list of common time encodings.
;;
;; Thank you, Emacs.
@wpcarro
wpcarro / rfcToKindle.go
Created February 2, 2020 18:39
Download RFCs to your Kindle
// Author: [email protected]
//
// Wirelessly transfer RFC documents to your Kindle to device for an alternative
// medium for reading.
//
// Usage:
// ```shell
// > go run rfcToKindle.go -document rfc6479 -recipient [email protected]
// ```
//
@wpcarro
wpcarro / magit-extensions.el
Created February 10, 2020 10:36
Attempting to support --diff-filter
;; TODO(wpcarro): Consider defining a --diff-filter section with the following
;; magit switches:
;; --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
;; Select only files that are Added (A), Copied (C), Deleted (D), Modified
;; (M), Renamed (R), have their type (i.e. regular file, symlink, submodule,
;; ...) changed (T), are Unmerged (U), are Unknown (X), or have had their
;; pairing Broken (B). Any combination of the filter characters (including
;; none) can be used. When * (All-or-none) is added to the combination, all
;; paths are selected if there is any file that matches other criteria in
;; the comparison; if there is no file that matches other criteria, nothing
@wpcarro
wpcarro / example.el
Created February 11, 2020 10:32
Why do I use EXWM?
(defconst display/display-states (cycle/from-list '((t . t) (t . nil) (nil . t)))
"A list of cons cells modelling enabled and disabled states for my displays.
The car models the enabled state of my laptop display; the cdr models the
enabled state of my external monitor.")
(defun display/cycle-display-states ()
"Cycle through `display/display-states' enabling and disabling displays."
(interactive)
(let ((state (cycle/next display/display-states)))
(if (car state) (display/enable-laptop) (display/disable-laptop))
@wpcarro
wpcarro / configuration.nix
Created February 20, 2020 19:46
Posting this here so that I can download it when I'm installing NixOS
{ config, pkgs, ... }:
# TODO(wpcarro): Refactor to prefer nested attribute for configuration values
# instead of using one-liner field accessors.
{
imports = [
./hardware-configuration.nix
];
# TODO(wpcarro): Is this correct? I believe my laptop only supports BIOS and
@wpcarro
wpcarro / Extras.hs
Created June 7, 2020 23:30
Enumerating Haskell data constructors
module Extras where
-- | Create a list of all of the data constructors for a given type.
enumAll :: (Bounded a, Enum a) => [a]
enumAll = [minBound .. ]