Skip to content

Instantly share code, notes, and snippets.

View spacebat's full-sized avatar

Andy Kirkpatrick spacebat

  • Adelaide, South Australia
View GitHub Profile
@spacebat
spacebat / icicle.lisp
Created April 27, 2016 14:28
Freeze special variable bindings with funcallable instances
;;; Just mucking about with funcallable instances. This class defines
;;; an instance that "freezes" a specified set of special variable
;;; bindings at the time of instantiation, so when the instance is
;;; called these bindings are preserved. This could be achieved with a
;;; closure, but then you couldn't read and alter the bindings so
;;; easily.
(ql:quickload :closer-mop)
(defclass icicle ()
@spacebat
spacebat / critter.lisp
Created April 27, 2016 04:31
CLOS append method combination example
;; An example of append method combination to form a projection of an object's slots
(defclass odour-mixin ()
((odour :initarg :odour :initform nil :reader odour)))
(defclass colour-mixin ()
((colour :initarg :colour :initform nil :reader colour)))
(defclass sound-mixin ()
((sound :initarg :sound :initform nil :reader sound)))
@spacebat
spacebat / string-successor.lisp
Last active January 13, 2016 22:23
String successor like ruby - I guess
(defun char-successor(c)
"values are succesor and carry, same case for letters"
(cond
((char= c #\9) (values #\0 t))
((char= c #\Z) (values #\A t))
((char= c #\z) (values #\a t))
((alphanumericp c) (values (code-char (1+ (char-code c))) nil))
(t (values c t))))
(defun string-successor(s)
@spacebat
spacebat / gist:6613f07b5a3d5c5c9f8b
Created November 20, 2015 11:45
Sketch of a let-alist.el alternative
(defconst my/lookup-extra-handlers nil)
(cl-defun my/lookup (map key &key default test type)
(typecase map
(list
(case type
(plist (getf map key default))
(list (nth key map))
(t (let ((cell (assoc key map)))
(if cell
;; See http://malisper.me/2015/11/10/defmemo/
(defmacro defmemo (name-and-cache args &body body)
"Define a memoized function. NAME-AND-CACHE may be a symbol naming
the function, or a property list in which case the name is specified
in the property :name. When a list is supplied, a set of functions
named by the properties :cache, :reader and :writer may be
supplied. The cache function must return an object that supports a
protocol like hash-table with equality test sufficient to discriminate
the arguments to the memoized function. The reader accepts
#!/usr/bin/env perl
# Adapted from tutorial Copyright (c) 2013 Peter Stuifzand
# at http://marpa-guide.github.io/chapter3.html
# In particular this is an attempt at Exercise 3
use strict;
use warnings;
package Authorization;
#!/usr/bin/env perl6
my $s = IO::Socket::INET.new(:host<abc.net.au>, :port(80));
$s.print("GET / HTTP/1.0\r\nHost: abc.net.au\r\n\r\n");
# Too many positionals passed; expected 1 argument but got 2
# in block <unit> at /home/spacebat/sock.pl6:4
@spacebat
spacebat / sample-wo-replacement.pl
Created February 16, 2015 12:52
sample without replacement
#!/usr/bin/env perl
use Modern::Perl;
use List::Util qw/sum/;
my @elements = (["low", 10], ["mid", 100], ["high", 1000]);
my $accum = 0;
my $total = sum map {
$_->[2] = $accum += $_->[1];
@spacebat
spacebat / sample-w-replacement.pl
Created February 16, 2015 12:50
sample with replacement
#!/usr/bin/env perl
use Modern::Perl;
use List::Util qw/first sum/;
my @elements = (["low", 10], ["mid", 100], ["high", 1000]);
my $accum = 0;
my $total = sum map {
$_->[2] = $accum += $_->[1];
@spacebat
spacebat / keybase.md
Created January 9, 2015 05:27
Keybase proof of GH ident

Keybase proof

I hereby claim:

  • I am spacebat on github.
  • I am spacebat (https://keybase.io/spacebat) on keybase.
  • I have a public key whose fingerprint is 0929 8712 0340 D898 4381 69DD 3067 D9AD 2796 55F6

To claim this, I am signing this object: