Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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:
CL-USER>
(defun ๐Ÿ”ช๐Ÿณ (ingredients)
(case ingredients
(๐ŸŒพ '๐Ÿš)
(๐ŸŒฝ '๐Ÿฟ)
(๐Ÿ” '๐Ÿ—)
(๐Ÿ„ '๐Ÿ”)
(t '๐Ÿฒ)))
(defun ๐Ÿ—ข๐ŸŒฑ (thing)
@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