Skip to content

Instantly share code, notes, and snippets.

View mdwhatcott's full-sized avatar

Michael Whatcott mdwhatcott

View GitHub Profile
@mdwhatcott
mdwhatcott / framed-bowling.clj
Last active August 12, 2021 22:34
framed-bowling.clj
(ns bowling.core-spec
(:require [speclj.core :refer :all]))
(defn is-strike? [[first & _]] (= 10 first))
(defn is-spare? [[first second & _]] (= 10 (+ first second)))
(defn split-frame [rolls]
(cond (is-strike? rolls) [(take 3 rolls) (rest rolls)]
(is-spare? rolls) [(take 3 rolls) (drop 2 rolls)]
:else [(take 2 rolls) (drop 2 rolls)]))
@mdwhatcott
mdwhatcott / minimal-bowling.clj
Last active August 7, 2021 19:39
minimal-bowling.clj
(ns bowling.core-spec
(:require [speclj.core :refer :all]))
(defn is-strike? [rolls] (= 10 (first rolls)))
(defn is-spare? [rolls] (= 10 (apply + (take 2 rolls))))
(defn ->frames [rolls]
(cond
(empty? rolls) []
@mdwhatcott
mdwhatcott / bowling.clj
Created August 2, 2021 19:22
bowling.clj
(ns bowling.core-spec
(:require [speclj.core :refer :all]))
(def all-pins 10)
(def frames-per-game 10)
(defn game-over [frame] (= frame frames-per-game))
(defn strike-score [rolls] (+ all-pins (nth rolls 1) (nth rolls 2)))
(defn spare-score [rolls] (+ all-pins (nth rolls 2)))
(defn frame-score [rolls] (+ (first rolls) (second rolls)))
(defn is-strike [rolls] (= all-pins (first rolls)))
@mdwhatcott
mdwhatcott / template.go
Created April 2, 2021 16:56
fmt.Sprintf -> template.Execute
package templates
import (
"bytes"
"fmt"
"io"
"text/template"
)
func ParseAndExecute(format string, args ...interface{}) string {
@mdwhatcott
mdwhatcott / bowling.rkt
Created January 16, 2021 20:06
The 'Bowling Game' Kata in Racket
#lang racket
(define LAST-FRAME 10)
(define ALL-PINS 10)
(define (is-spare? rolls) (= ALL-PINS (+ (first rolls) (second rolls))))
(define (is-strike? rolls) (= ALL-PINS (first rolls)))
(define (score-frame frame score rolls)
(score-frames (add1 frame)
@mdwhatcott
mdwhatcott / stack_trace_error.go
Created February 6, 2020 02:08
Go Stack Trace Error
type StackTraceError struct {
inner error
stack []byte
}
func NewStackTraceError(inner error) *StackTraceError {
return &StackTraceError{
inner: inner,
stack: debug.Stack(),
}
@mdwhatcott
mdwhatcott / tcr.sh
Last active October 5, 2019 15:25
test && commit || revert (a la Kent Beck)
#!/usr/bin/env bash
# TCR: test && commit || revert
# codified by Kent Beck
# https://medium.com/@kentbeck_7670/test-commit-revert-870bbd756864
function test() {
echo
cd `git rev-parse --show-toplevel`
go test ./...
@mdwhatcott
mdwhatcott / path.py
Created March 31, 2018 17:35
Dynamic attribute resolution to mimic a directory tree on a file system (either real or contrived).
class Path(object):
"""
This nifty class uses dynamic attribute resolution to mimic a directory
tree on a file system (either real or contrived).
"""
def __init__(self, root, enforce_real_paths=False):
self.root___ = str(root)
self.navigation___ = []
self.enforce___ = enforce_real_paths
if self.enforce___ and not os.path.exists(self.root___):
@mdwhatcott
mdwhatcott / Preferences.sublime-settings
Created November 29, 2016 16:36
sublime preferences
{
"close_windows_when_empty": true,
"color_scheme": "Packages/Dayle Rees Color Schemes/sublime/darkside.tmTheme",
"draw_white_space": "all",
"font_face": "Source Code Pro",
"font_size": 19,
"ignored_packages":
[
"Vintage"
],
@mdwhatcott
mdwhatcott / Default (OSX).sublime-keymap
Created November 29, 2016 16:35
sublime keyboard shortcuts
[
{ "keys": ["super+k", "super+w"], "command": "toggle_setting", "args": {"setting": "word_wrap"}},
{ "keys": ["super+k", "super+m"], "command": "toggle_minimap" },
{ "keys": ["super+k", "super+t"], "command": "delete_trailing_spaces" }
]