Skip to content

Instantly share code, notes, and snippets.

Avatar
:bowtie:
Happily Hacking

Chris Penner ChrisPenner

:bowtie:
Happily Hacking
View GitHub Profile
@ChrisPenner
ChrisPenner / shell-reminders.md
Last active Aug 29, 2015
Reminders in Terminal
View shell-reminders.md

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"
notes

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

@ChrisPenner
ChrisPenner / other.md
Last active Aug 29, 2015
Testing Gist [post]
View other.md

Testing Gist Rendering

Here's some markdown

  • and a list
  • again more stuff

Here comes code:

lastly some code stuff
@ChrisPenner
ChrisPenner / vim-manpage-viewer.sh
Last active Aug 15, 2019
Use Vim as a man pages viewer.
View vim-manpage-viewer.sh
# 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
ChrisPenner / README.md
Last active Nov 21, 2017
Syntax highlighting for text files, breaks up walls of white text.
View README.md

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

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

View kleisli-endo.md

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