Skip to content

Instantly share code, notes, and snippets.

View ChrisPenner's full-sized avatar
:bowtie:
Happily Hacking

Chris Penner ChrisPenner

:bowtie:
Happily Hacking
View GitHub Profile
@ChrisPenner
ChrisPenner / shell-reminders.md
Last active August 29, 2015 14:19
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"
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 August 29, 2015 14:20
Testing Gist [post]

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 August 15, 2019 20:00
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
ChrisPenner / README.md
Last active December 8, 2021 22:15
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
ChrisPenner / .env
Last active September 4, 2015 18:58
Autoenv + tmux workflow
#!/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 February 15, 2016 18:53
"Don't argue" blog post
@supply_args
def main(first, second, keyword=42, *extras):
print first, second, keyword, extras
@ChrisPenner
ChrisPenner / factorial.py
Last active September 19, 2020 08:13
Tail Recursion in Python without Introspection
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)
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 March 17, 2017 05:44
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

@ChrisPenner
ChrisPenner / kleisli-endo.md
Last active October 22, 2019 03:44
Kleisli Endo

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