Skip to content

Instantly share code, notes, and snippets.

View wpcarro's full-sized avatar

William Carroll wpcarro

  • Hadrian
  • internet
View GitHub Profile
@wpcarro
wpcarro / simple_registry.ex
Created April 25, 2017 14:43
An alternative registry implementation in Elixir
defmodule DriverRegistry do
@moduledoc """
Most key-value registries in Elixir can and perhaps should be created with a
`GenServer`. This module illustrates an alternative implementation of a
registry using macros that eliminates the need for a `GenServer`. This removes
OTP dependencies like a supervision tree and also reduces unnecessary
"process noise" in your application.
The use-case for such a registry is a driver registry where consumers opt-in
to drivers by declaring which drivers they would like to use in the
@wpcarro
wpcarro / breadth_first_traversal.ex
Created May 29, 2017 18:56
Simple implementation of a breadth-first tree traversal written in Elixir
defmodule Tree do
@moduledoc """
Simple implementation of a breadth-first tree traversal.
Author: William Carroll
"""
@type value :: any
@type tree :: {value [tree]}
@wpcarro
wpcarro / keybase.md
Created September 18, 2017 21:00
Keybase proof

Keybase proof

I hereby claim:

  • I am wpcarro on github.
  • I am wpcarro (https://keybase.io/wpcarro) on keybase.
  • I have a public key ASCrkXvNTrQIjM9mWqWFJBIhrDe1__hfVe1r-8uo8VsAKQo

To claim this, I am signing this object:

@wpcarro
wpcarro / canvas.cljs
Created October 22, 2017 15:41
Debugging re-frame and reagent
;; versions 1 & 2 -- structure remains the same
(defn render [{:keys [data]}]
(reagent/create-class
{:reagent-render (constantly [:svg.canvas])
:component-did-mount #(-> data clj->js do-render-graph)}))
@wpcarro
wpcarro / private_macros.exs
Created December 5, 2017 16:17
Debugging Elixir private macro usage
defmodule PrivateMacros do
@moduledoc false
defmacrop test() do
quote do
IO.inspect("I compiled")
end
end
test()
@wpcarro
wpcarro / eslint-pre-commit.bash
Created January 5, 2018 20:29
Use this as your `.git/hooks/pre-commit` to enforce ESLint-ing for your JavaScript code. Modify the grep filtering to customize your whitelist. Other examples of ESLint pre-commit hooks exist online, but many seemed too complicated for what I was looking for. Enjoy!
#!/usr/bin/env bash
################################################################################
# This script will run ESLint over all staged files with js or jsx extensions.
# Author: William Carroll
################################################################################
for file in $(git diff --name-only --cached | grep -E '\.jsx?$'); do
npx eslint ${file}
done
@wpcarro
wpcarro / prettier-eslint-pre-commit.bash
Created January 5, 2018 23:00
Run Prettier and ESLint before committing code.
#!/usr/bin/env bash
# short-circuit script for any non-zero exit
set -e
################################################################################
# This script will run ESLint over all staged files with js or jsx extensions.
# Author: William Carroll
################################################################################
@wpcarro
wpcarro / tmux-emacs-windmove.el
Last active February 19, 2018 23:52
Similar to vim-tmux-navigator but for Emacs & Tmux.
(defun wpcarro/tmux-emacs-windmove (dir)
"Move windows in a Tmux-friendly way."
(let* ((dir->opts '((left . ("-L" . windmove-left))
(right . ("-R" . windmove-right))
(above . ("-U" . windmove-up))
(below . ("-D" . windmove-down))))
(opts (alist-get dir dir->opts))
(tmux-opt (car opts))
(emacs-fn (cdr opts)))
(if (window-in-direction dir)
@wpcarro
wpcarro / open-from-iterm.sh
Last active July 13, 2018 14:28
This allows users to Cmd+click on filepaths in iTerm (with Tmux) and open the files in Emacs. Intended for personal use.
#!/bin/bash
# To set this up, open iTerm2 -> Preferences -> Profiles -> Advanced
# In the "Semantic History" section, choose "Always run command..." from the
# dropdown and set the input text to:
# `~/dotfiles/emacs.d/open-from-iterm.sh \1`
# Alias applications since $PATH is unavailable
emacs=/usr/local/bin/emacsclient
grep=/usr/local/bin/ggrep
@wpcarro
wpcarro / merge-sort.hs
Last active October 14, 2018 21:03
Merge Sort (Haskell)
--------------------------------------------------------------------------------
import Data.Function ((&))
--------------------------------------------------------------------------------
main :: IO ()
main =
[2,3,5,1,4,6,8,7,9] & mergeSort & show & putStrLn
mergeSort :: (Ord a) => [a] -> [a]
mergeSort [] = []
mergeSort [x] = [x]