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
@ashton314
ashton314 / denote-frontmatter-formatter.el
Created July 23, 2024 17:55
Normalize org frontmatter with Denote
(defun aw/denote-normalize-org-frontmatter ()
"Normalize the front-matter in an org-mode file."
(interactive)
(when-let* ((file (buffer-file-name))
(denote-filename-is-note-p file)
(type (denote-filetype-heuristics file))
(title (denote-retrieve-title-value file type))
(id (denote-retrieve-filename-identifier file)))
(let ((kwds (denote-retrieve-keywords-value file type)))
(delete-matching-lines "^#\\+title:.*$" (point-min) (point-max))
@ashton314
ashton314 / nm-org-roam-to-denote.el
Created July 23, 2024 17:54
Modified version of org-roam-to-denote migration script
;;; nm-org-roam-to-denote.el --- Migrate notes from org-roam to denote
;; Copyright (C) 2022 bitspook <bitspook@proton.me>
;; Author: bitspook
;; Version: 0.1.0
;; URL: https://github.com/bitspook/notes-migrator
;; Package-Requires: ((emacs "28.1") (denote "1.0.0")
;;; Commentary:
@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))
@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 / 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 / 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 / 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)))))
;; 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 / 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*)])