Skip to content

Instantly share code, notes, and snippets.

View ijp's full-sized avatar

Ian Price ijp

  • Aberdeen, Scotland
View GitHub Profile
@ijp
ijp / K2.hs
Last active September 12, 2024 00:14
K2 PCA in Haskell
import Prelude hiding (lookup)
import Data.Maybe
type Nat = Int -- !!
type Baire = Nat -> Maybe Nat
encode :: [Maybe Nat] -> Nat
encode = undefined
@ijp
ijp / commentator.py
Last active May 17, 2020 16:25
Road to Yokozuna - Slohyo prototype
class StdioLogger(object):
def log(self, msg):
print(msg)
class NullLogger(object):
def log(self, msg):
pass
~/src/guile $ make
/usr/bin/make all-recursive
make[1]: Entering directory `/home/ian/src/guile'
Making all in lib
make[2]: Entering directory `/home/ian/src/guile/lib'
/usr/bin/make all-recursive
make[3]: Entering directory `/home/ian/src/guile/lib'
make[4]: Entering directory `/home/ian/src/guile/lib'
make[4]: Nothing to be done for `all-am'.
make[4]: Leaving directory `/home/ian/src/guile/lib'
# a sketch of how Scheme fluids/parameters would work in python
obarray = {}
class Manager(object):
def __init__(self, parameter, value):
self.parameter = parameter
self.value = value
def __enter__(self):
@ijp
ijp / foo.el
Last active August 29, 2015 14:15
(defun my-erc-quit (s)
(or s (concat "brb " (aref my-erc-quit-reasons (random (length my-erc-quit-reasons))))))
(setq erc-part-reason 'my-erc-quit)
(setq erc-quit-reason 'my-erc-quit)
(setq my-erc-quit-reasons
["proving riemann hypothesis"
"cleaning the augean stables"
"inventing something better than sliced bread"
(use-modules (system repl command))
(define-meta-command ((clear module) repl)
"clear
Removes all current bindings."
(let ((mod (current-module)))
(module-for-each (lambda (k v)
(module-remove! mod k))
mod)))
@ijp
ijp / galex.el
Last active August 29, 2015 14:11
;; not tested
(defun galex-assoc-string (regexp alist)
(catch 'done
(while alist
(cond ((consp (car alist))
(if (string-match regexp (caar alist))
(throw 'done (car alist))))
((stringp (car alist))
(if (string-match regexp (car alist))
@ijp
ijp / fib.el
Created December 21, 2014 10:25
(setq fib (lambda ()
(let* ((b (cdddr fib))
(s (apply '+ b)))
(setcdr (cddr fib) (list (cadr b) s))
(throw 'result s))
0 1))
(defun fib () (catch 'result (funcall fib)))
(fib)
def rindex_func(func, l):
for (i,obj) in reversed(list(enumerate(l))): ## Boo! list()
if func(obj):
return i
return None
def only_as_suffix(obj, l):
try:
i = l.index(obj)
except ValueError:
(define (make-palindrome l)
(define (loop l suffix)
(if (null? (cdr l))
(cons (car l) suffix)
(cons (car l)
(loop (cdr l) (cons (car l) suffix)))))
(if (null? l)
#f ; arbitrary choice
(loop l '())))