Skip to content

Instantly share code, notes, and snippets.

Happily Hacking

Chris Penner ChrisPenner

Happily Hacking
View GitHub Profile
ChrisPenner /
Last active Aug 29, 2015
Reminders in Terminal

Throw this at the bottom of your .profile file (or .bashrc). Quick and easy reminders for yourself that are displayed every time you fire up a terminal prompt.

# Sticky-notes:
alias note="vim ~/dotfiles/messages"
alias notes="cat ~/dotfiles/messages"

I usually use this to remind myself of some new Vim commands I'm trying to integrate into my workflow.

ChrisPenner /
Last active Aug 29, 2015
Testing Gist [post]

Testing Gist Rendering

Here's some markdown

  • and a list
  • again more stuff

Here comes code:

lastly some code stuff
ChrisPenner /
Last active Aug 15, 2019
Use Vim as a man pages viewer.
# Set this in your ~/.bash_profile
export PAGER="/bin/sh -c \"unset PAGER;col -b -x | \
vim -R -c 'set ft=man nomod nolist' -c 'map q :q<CR>' \
-c 'map <SPACE> <C-D>' -c 'map b <C-U>' \
-c 'nmap K :Man <C-R>=expand(\\\"<cword>\\\")<CR><CR>' -\""
# Set this in your ~/.vimrc (This will allow using 'K' to look up man pages inside vim.
let $PAGER=''
ChrisPenner /
Last active Dec 8, 2021
Syntax highlighting for text files, breaks up walls of white text.

Plain-text Syntax Highlighting

Over the years I've gotten used to reading code with syntax highlighting. The colouring of the highlighting provides anchoring points for my eyes as I scroll, helping me to keep my place. However, when I'd be editing plain-text, I have no anchoring points, just a huge wall of text; so I wrote a simple syntax file for it.

All it does is highlights capitalized words, very simple. This typically ends up highlighting things of importance: headings, names, and most importantly the beginning of sentences. I've found this to be a good amount of highlighting without being overwhelming, providing context without being overly flashy.

Here's my current version: Plain-text Syntax Highlighting

ChrisPenner / .env
Last active Sep 4, 2015
Autoenv + tmux workflow
View .env
# Echo the root folder of the current git repo.
echo `git rev-parse --show-toplevel`
# Reconnect tmux session
# Don't attach to tmux if already in tmux
ChrisPenner /
Last active Feb 15, 2016
"Don't argue" blog post
def main(first, second, keyword=42, *extras):
print first, second, keyword, extras
ChrisPenner /
Last active Sep 19, 2020
Tail Recursion in Python without Introspection
from tail_recursion import tail_recursive, recurse
# Normal recursion depth maxes out at 980, this one works indefinitely
def factorial(n, accumulator=1):
if n == 0:
return accumulator
recurse(n-1, accumulator=accumulator*n)
def factorial(n):
if n == 0: return 1
else: return factorial(n-1) * n
def tail_factorial(n, accumulator=1):
if n == 0: return accumulator
else: return tail_factorial(n-1, accumulator * n)
ChrisPenner /
Last active Mar 17, 2017
Exploring Adjunctions

This might all be old-hat for you, but typing it out helps be understand it better anyways :)

Let's consider two examples as we talk about it, the first being curry/uncurry, the second being the case Hardy mentioned in an earlier episode where he had an adjunction between annotated/highlighted text and non-highlighted text.

Considering two Categories A and B; The definition of an adjunction (at least according to wikipedia) is a pair of Functors; F:A -> B and G:B -> A; so basically a pair of functors which map back and forth between categories. We also need


After listening to the latest Magic Read-along episode "You should watch this" (which you should go listen to now) I got caught up thinking about Brian's idea of an Endomorphism version of Kleisli composition for use with Redux, it's actually a very similar model to what I'm using in my event framework for event listeners so I figured I'd try to formalize the pattern and recognize some of the concepts involved. IIRC Brian described the idea of a Redux-reducer, which is usually of type s -> Action -> s, it takes a state and an action and returns a new state. He then re-arranged the arguments to Action -> s -> s. He then recognized this as Action -> Endo s (an Endo-morphism is just any function from one type to itself: a -> a). He would take his list of reducers and partially apply them with the Action, yielding a list of type Endo s where s