Skip to content

Instantly share code, notes, and snippets.

View wpcarro's full-sized avatar

William Carroll wpcarro

View GitHub Profile
@wpcarro
wpcarro / cycle.el
Created August 12, 2019 15:09
Basic implementation of a cycle data structure in Elisp.
;;; cycle.el --- Simple module for working with cycles. -*- lexical-binding: t -*-
;; Author: William Carroll <[email protected]>
;;; Commentary:
;; Something like this may already exist, but I'm having trouble finding it, and
;; I think writing my own is a nice exercise for learning more Elisp.
;;; Code:
;; `current-index' tracks the current index
@wpcarro
wpcarro / encrypt.zsh
Last active August 15, 2019 14:02
Personal helper functions for encrypting and decrypting.
# Note: there are almost assuredly faster and potentially more secure ways to encrypt files.
# My focus with these function was security and ergonomics. I find GPG functions difficult to
# remember and unwieldy to type. The easier encrypting and decrypting is, the more likely I am
# to do it. All other things being equal, some encryption is probably better than no encryption.
#
# Usage:
# $ encrypt *.txt dir_{a,b}
# $ decrypt *.txt.gpg dir_{a,b}.tar.gz.gpg
[email protected]
@wpcarro
wpcarro / main.sh
Created August 20, 2019 14:42
Easily configure default applications in Linux
# Adding this as a reference for myself.
# At the terminal, call:
mimeopen -d <filetype>
# For example to configure `lf` to open for directories:
mimeopen -d $(pwd)
# To configure Emacs for .js files
mimeopen -d file.js
@wpcarro
wpcarro / .vimrc
Last active August 21, 2019 11:25
Dependency-free vimrc
" My barebones vimrc without any Vundle dependencies.
"
" I'm attempting to optimize the following:
" - Minimize dependencies
" - Maximize ergonomics
" - Maximize Tmux compatibility
" - Minimize shadowing of existing Vim KBDs
"
" Warning: This is currently unstable as it is a work-in-progress.
"
@wpcarro
wpcarro / radix_compliment.py
Last active August 27, 2019 12:03
Radix compliment
################################################################################
# Simple program for computing the "radix compliment" of a given number.
# Written primarily to help me better understand the "two's compliment" concept.
#
# Author: William Carroll <[email protected]>
################################################################################
def radix_compliment(x, radix=None, num_digits=None):
"""Computes the radix compliment for `x`.
@wpcarro
wpcarro / zle.el
Created September 11, 2019 10:46
Porting my Z-shell Line Editor KBDs to Emacs.
;;; zle.el --- Functions to mimmick my ZLE KBDs -*- lexical-binding: t -*-
;; Author: William Carroll <[email protected]>
;;; Commentary:
;; This is primarily for personal use. The keybindings that I choose are those
;; that feel slightly mnemonic while also not shadowing important bindings.
;; It's quite possible that our tastes will differ here.
;;
;; All of these keybindings are intended to shave off milliseconds off your
;; typing. I don't expect these numbers to sum up to a meaningful amount. The
@wpcarro
wpcarro / deref.sh
Created September 23, 2019 15:41
Expand symlinks into their source; delete the symlink.
deref() {
# Dereferences a symlink.
# Usage: deref [symlink]
if ! [ -L $1 ]; then
echo_error "File is not a symlink: $1. Exiting..."
else
local src=$(readlink -f $1)
echo "Moving $src -> $1" && \
mv $1 $1.bak && \
mv $src $1 && \
@wpcarro
wpcarro / kaomoji.el
Created September 26, 2019 16:58
Quickly copy kaomojis onto your system clipboard.
;;; kaomoji.el --- Supporting kaomoji usage -*- lexical-binding: t -*-
;; Author: William Carroll <[email protected]>
;;; Commentary:
;; Simple keyboards like this make life a bit better.
;;; Code:
(defconst symbols '(("Joy" . "(⌒‿⌒)")
("Love" . "(ღ˘⌣˘ღ)")
@wpcarro
wpcarro / alist.el
Created September 30, 2019 13:47
A rough draft of a module to improve the ergonomics of working with associative lists in Emacs Lisp.
;;; alist.el --- Interface for working with associative lists -*- lexical-binding: t -*-
;; Author: William Carroll <[email protected]>
;;; Commentary:
;; Firstly, a rant:
;; In most cases, I find Elisp's APIs to be confusing. There's a mixture of
;; overloaded functions that leak the implementation details (TODO: provide an
;; example of this.) of the abstract data type, which I find privileges those
;; "insiders" who spend disproportionately large amounts of time in Elisp land,
;; and other functions with little-to-no pattern about the order in which
@wpcarro
wpcarro / point-free.el
Last active October 18, 2019 13:15
Point-free threading in Elisp
(require 'dash)
(defmacro - (&rest forms)
"Compose a new, point-free function by composing FORMS together."
(let ((sym (gensym)))
`(lambda (,sym)
(->> ,sym ,@forms))))