Skip to content

Instantly share code, notes, and snippets.

View keelerm84's full-sized avatar

Matthew M. Keeler keelerm84

View GitHub Profile
/**
* Coding challenge : Armstrong Numbers
*
* Write a program using any language or technique that can accept two positive
* integers defining a range (such as 0 and 100 for the range 0 <= x <= 100) and
* will print all Armstrong Numbers in that range.
*
* An Armstrong Number is fully defined at
* http://en.wikipedia.org/wiki/Narcissistic_number
*
@keelerm84
keelerm84 / recursive-cache.rb
Created May 18, 2013 00:58
3n + 1 Recursive Solution in Ruby
#!/usr/bin/env ruby
# Consider the following algorithm to generate a sequence of numbers. Start
# with an integer n. If n is even, divide by 2. If n is odd, multiply by 3 and
# add 1. Repeat this process with the new value of n, terminating when n = 1.
# For example, the following sequence of numbers will be generated for n = 22:
#
# 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
#
# It is conjectured (but not yet proven) that this algorithm will terminate at
@keelerm84
keelerm84 / core.clj
Created February 16, 2014 17:30
Clojure implementation of the bowling kata
(ns bowling.core)
(defn spare? [rolls]
(= 10 (reduce + (take 2 rolls))))
(defn strike? [rolls]
(= 10 (first rolls)))
(defn take-how-many [rolls]
(if (or (spare? rolls) (strike? rolls)) 3 2))
(defadvice delete-file (before purge-from-projectile-cache (filename &optional trash))
(if (and (projectile-project-p) projectile-enable-caching)
(let* ((project-root (projectile-project-root))
(true-filename (file-truename filename))
(relative-filename (file-relative-name true-filename project-root)))
(if (projectile-file-cached-p relative-filename project-root)
(projectile-purge-file-from-cache relative-filename)))))
@keelerm84
keelerm84 / vote.zsh
Last active November 6, 2020 14:35
Short function to monitor voting results in battleground states
function vote {
curl --silent https://alex.github.io/nyt-2020-election-scraper/battleground-state-changes.csv | \
awk -v red="$(tput setaf 1)" \
-v blue="$(tput setaf 4)" \
-v reset="$(tput sgr0)" \
-F "," '
NR==1 { next }
matches[$1] == 1 { next }
{
matches[$1]=1