Skip to content

Instantly share code, notes, and snippets.

@wobh
wobh / cl-game-random.lisp
Last active March 14, 2021 03:59
cl-game-random: Provides randomness utilities useful in many games.
(defpackage #:cl-game-random
(:use #:cl)
(:export #:random-whole #:random-range
#:random-digit #:random-alpha
#:random-array-subscripts
#:random-char #:random-svref
#:random-nth #:random-elt
#:random-aref
#:sample
#:bias
@wobh
wobh / ace.lisp
Created March 17, 2017 06:56
Acing the technical interview (in Common Lisp)
;; Inspired by https://aphyr.com/posts/340-acing-the-technical-interview
(defun conz (head tail)
(lambda (_) (if _ head tail)))
(let ((subject (conz 1 (conz 2 nil))))
(assert (= 1 (funcall subject t)))
(assert (= 2 (funcall (funcall subject nil) t))))
(defun mth (lizt mth)
@wobh
wobh / arrayn.rb
Last active January 28, 2017 23:51
Exercise implementing multidimensional arrays in Ruby
# Exercise for implementing multi-dimesional arrays in Ruby
# TODO:
# Level 0: Implement `row_major_index` and `to_a`.
# Level 1: How could tests be improved?
# Level 2: How could the interface of ArrayN be extended? Made more idiomatic?
# Multi-dimensional array
class ArrayN
CL-USER>
(defun 🔪🍳 (ingredients)
(case ingredients
(🌾 '🍚)
(🌽 '🍿)
(🐔 '🍗)
(🐄 '🍔)
(t '🍲)))
(defun 🗢🌱 (thing)
@wobh
wobh / pipe.lisp
Last active May 2, 2016 13:49
pipes via reduction
;; Per https://twitter.com/wobher/status/726442806353399808 what I'm
;; trying to say, all too succinctly, is that structurally an
;; expression like "foo |> bar |> baz |> qux" or even
;; "foo.bar.baz.qux" is commonly considered syntax for a bunch of
;; nested calls: "qux(baz(bar(foo)))". However, in Lisp or any other
;; non-infix language, we can see that this need not be the case.
;; Lets define a `pipe' function; we'd like the following assertions
;; about it to be true:
@wobh
wobh / decomposition_test.exs
Created March 19, 2016 21:25
Elixir unicode decomposition bug
Code.require_file "test_helper.exs", __DIR__
defmodule DecompositionTest do
use ExUnit.Case, async: true
# "015D;0074;0302;;;" in Decomposition.txt
# "0073;0302;015D;" in Composition.txt
test "String.equivalent? (LATIN SMALL LETTER S WITH CIRCUMFLEX)" do
assert String.equivalent?("\u015D", "\u0073\u0302") # fails, but correct
assert String.equivalent?("\u015D", "\u0074\u0302") # passes, but incorrect
@wobh
wobh / stream_printer.rb
Last active March 10, 2016 19:08
StreamPrinter
# Stream of consciousness development. Copy/Paste into pry or irb.
require 'stringio'
def stream_print(stream, object)
stream << object.to_str if object.respond_to?(:to_str)
stream
end
io = StringIO.new
@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 / 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 &amp; yield syntax
@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)