Skip to content

Instantly share code, notes, and snippets.

@wobh
wobh / dna-min-test-results.txt
Last active August 29, 2015 14:10
Setting up quicklisp in clisp, for exercism
CL-USER> (load "point-mutations-test.lisp")
;; Loading file point-mutations-test.lisp ...
To load "lisp-unit":
Load 1 ASDF system:
lisp-unit
; Loading "lisp-unit"
;; Loading file /Users/wclifford/exercism/lisp/point-mutations/dna.lisp ...
;; Loaded file /Users/wclifford/exercism/lisp/point-mutations/dna.lisp
INVALID-TO-GET-DISTANCE-FOR-DIFFERENT-LENGTH-STRINGS: 3 assertions passed, 0 failed.
@wobh
wobh / quadratic-macrolet.lisp
Last active August 29, 2015 14:12
Common Lisp quadratic formula (a macrolet example)
;;; One use of `macrolet' is to simplify purely structural concerns in
;;; one's functions. As one example, consider this implementation of
;;; the quadratic formula:
(defun quadratic (a b c)
(macrolet ((plus-or-minus-div (x y z)
`(values (/ (+ ,x ,y) ,z) (/ (- ,x ,y) ,z))))
(plus-or-minus-div (- b) (sqrt (- (* b b) (* 4 a c))) (* 2 a))))
;;; Although there's still some redundancy, it's contained to the point
@wobh
wobh / min-conf.rb
Created January 29, 2015 11:26
Minimum configurable Ruby class
# Goals
# 1. Small class configurable with a block
# 2. puts settings in a ruby Struct
require 'Forwardable'
class Settable
extend Forwardable
def_delegator :@config, :foo
def_delegator :@config, :bar
@wobh
wobh / mismatch-count-test.lisp
Last active August 29, 2015 14:22
mismatch-count
(ql:quickload "lisp-unit")
(defpackage #:mismatch-count-test
(:use #:cl #:lisp-unit)
(:export #:run))
(in-package #:mismatch-count-test)
;;; Tests
@wobh
wobh / cl-pretty-print.org
Created June 25, 2015 06:55
Common Lisp Pretty Printing DRAFT

Common Lisp Pretty Printing

Introduction

For some time, I found Common Lisp’s pretty printer to be intimidating, obscure, and complex, and, for as long as I’ve been comfortable with the basics of FORMAT I felt able to ignore it, as

@wobh
wobh / near-chars.cl
Created July 2, 2015 07:53
Near alphabetic standard characters
(defun char-next (char)
"Return the next alphabetic character, per CL standard."
(assert (char-lessp char #\Z)
(char) "No further characters in the standard alphabet.")
(let* ((char-num (digit-char-p (char-upcase char) 36))
(char-next (digit-char (1+ char-num) 36)))
(if (lower-case-p char)
(char-downcase char-next)
char-next)))
@wobh
wobh / http-utils.el
Created August 13, 2015 07:20
http-utils.el
(require 'json)
(require 'url)
(require 'url-http)
;;; http utilities
(defun http-utils-response-json (url)
"Retrieve url and parse json response."
(with-current-buffer (url-retrieve-synchronously url t)
@wobh
wobh / beautiful_code.md
Last active September 11, 2015 06:09 — forked from davy/beautiful_code.md
Ruby as Science, Art and Craft

Beautiful Code

Language Elements

# 49 methods for the price of one
# via @sferik
module Enumerable

# block & yield syntax
@wobh
wobh / handy-math.lisp
Created October 25, 2015 04:04
Handy math package for Common Lisp
(defpackage #:handy-math
(:use #:cl)
(:export #:onep #:twop
#:one-over #:1/ #:halve #:/2 #:integer-factor-p #:factorer
#:two-fold #:2* #:multiplier
#:^ #:2^ #:^2
#:v*)
(:documentation "Handy Math
Simple, often used arithmatic operations."))
@wobh
wobh / rack_test_app.rb
Last active December 13, 2015 23:29
A simple rack app with response builder hack.
require 'pathname'
require 'pp'
class HTTPResponseBuilder
STATUS_CODES = {100 => "Continue",
101 => "Switching Protocols",
200 => "OK",
201 => "Created",
202 => "Accepted",
203 => "Non-Authoritative Information",