Skip to content

Instantly share code, notes, and snippets.

View ashton314's full-sized avatar
👨‍💻
Expanding ((λ (x) (x x)) (λ (y) (y y)))

Ashton Wiersdorf ashton314

👨‍💻
Expanding ((λ (x) (x x)) (λ (y) (y y)))
View GitHub Profile

Keybase proof

I hereby claim:

  • I am ashton314 on github.
  • I am ashton314 (https://keybase.io/ashton314) on keybase.
  • I have a public key ASAGVAKmpoeIZ8lp6vPnxzyS3oyH-v2vhhrxZODU-hA3ego

To claim this, I am signing this object:

@ashton314
ashton314 / docker.db.exs
Created August 22, 2019 02:51
Custom mix task for development environments to start/stop a Postgres database in a Docker container
defmodule Mix.Tasks.Docker.Db do
use Mix.Task
@project_name "Program Builder"
@project_sname "program_builder"
@shortdoc "Start/stop the docker Postgres container for development"
@moduledoc """
Fire up a postgres database for #{@project_name}, named #{@project_sname} in Docker.
@ashton314
ashton314 / command.rkt
Last active April 9, 2020 20:44
The Command pattern from GoF design patterns is a nice pattern. However, the problem it solves is more deftly handled by Lambda: the Ultimate.
#lang racket
;; First, define the undo stack with a few helper functions
(define *undo-stack* '())
(define (push-undo! command)
(set! *undo-stack* (cons command *undo-stack*)))
(define (pop-undo!)
(let ([head (car *undo-stack*)])
;; Pandoc conversion function
;; Requires f.el, as well as pandoc and pandoc-citeproc installed on the host system.
;; If on macOS, install with `brew install pandoc pandoc-citeproc'
(defcustom pandoc-converter-args "--filter pandoc-citeproc --pdf-engine=xelatex" "Additional arguments to pass to pandoc when running `convert-with-pandoc'")
(defun convert-with-pandoc ()
"Convert a file between formats with Pandoc.
This will place the outputted function in the same directory as
the source folder.
@ashton314
ashton314 / nondet-callcc.rkt
Created February 17, 2021 18:23
Non-determinism implemented with the call/cc operator in Racket
#lang racket
(define *remaining-choices* '())
(define (choose choices)
(call/cc
(λ (k)
(for ([i (cdr choices)])
(set! *remaining-choices* (cons (cons k i) *remaining-choices*)))
(k (car choices)))))
@ashton314
ashton314 / turing.rkt
Last active February 23, 2021 20:25
Showing how you can build a lambda calculus in 7 lines of Racket (that's the first function)
#lang racket
;; Demonstration of a turing-complete language
(define (ev e [ρ '()])
(match e
[(? symbol? x) (cadr (assoc x ρ))]
[`(λ (,xs ...) ,es) `(cls ,ρ ,xs ,es)]
[`(,f ,as ...)
(match (ev f ρ)
[`(cls ,cρ ,xs ,es) (ev es (append (map list xs (map (λ (v) (ev v ρ)) as)) cρ ρ))])]))
@ashton314
ashton314 / minimal.el
Created April 4, 2021 18:32
Minimal package manager set up
(defvar bootstrap-version)
(setq straight-repository-branch "develop")
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
@ashton314
ashton314 / inspect_with_pipe_yasnippet.ex
Created June 22, 2021 19:04
Yasnippets for use with Elixir. Yasnippet repo: https://github.com/joaotavora/yasnippet
# -*- mode: snippet -*-
# name: pipe inspect
# key: pi
# --
|> IO.inspect(label: "$1")
$0
@ashton314
ashton314 / clicky.el
Created April 29, 2022 18:37
Play a sound after every keypress in Emacs on macOS
;; Resource: https://stackoverflow.com/questions/11206140/typewriter-sounds-for-emacs
(defvar tink "/System/Library/Sounds/Tink.aiff")
(defun play (file)
(let ((buf (get-buffer-create "playnoise")))
(start-process-shell-command "play" buf (concat "afplay " file))))
(defun do-tink ()
(play tink))