Skip to content

Instantly share code, notes, and snippets.

@fiddlerwoaroof
fiddlerwoaroof / demo.hs
Created February 27, 2018 00:44
Unit-testing IO in Haskell
module Main where
import Data.IORef
import Data.Time.Clock.POSIX
realIoUnderTest :: IORef Int -> IORef [[Char]] -> IORef Int -> IORef String -> IO ()
realIoUnderTest a b c d = do
b' <- readIORef b
putStrLn $ Prelude.unlines b'

Keybase proof

I hereby claim:

  • I am fiddlerwoaroof on github.
  • I am fiddlerwoaroof (https://keybase.io/fiddlerwoaroof) on keybase.
  • I have a public key ASAjpoHMAvokBJ0hUrLDdCiYI9w63MumLlgXyWQvTYLOdwo

To claim this, I am signing this object:

@fiddlerwoaroof
fiddlerwoaroof / nary.idr
Last active September 30, 2017 05:04
Nary map in Idris
import Data.List
import Data.Vect
total
repeatAndRet : (n : Nat) -> Type -> Type -> Type
repeatAndRet Z argType resultType = resultType
repeatAndRet (S n) argType resultType = argType -> repeatAndRet n argType resultType
total
nary : Nat -> Type-> Type
(defpackage :anonymous-generic-function
(:use :cl :alexandria)
(:export :lambda-generic))
(in-package :anonymous-generic-function)
(defmacro defun-ct (name (&rest args) &body body)
`(eval-when (:load-toplevel :compile-toplevel :execute)
(defun ,name ,args
,@body)))
@fiddlerwoaroof
fiddlerwoaroof / isolate-method.lisp
Created May 21, 2017 07:00
Isolate a Method in a Combined Method
(defmacro methodcall ((name &rest qualifiers-and-args) (&rest arg-values) &body next-function-body)
(let* ((qualifiers (butlast qualifiers-and-args))
(specialized-args (mapcar (lambda (arg) (typecase arg (list arg) (t (list arg t))))
(car (last qualifiers-and-args))))
(args (mapcar #'car specialized-args))
(specializers (mapcar #'cadr specialized-args)))
(alexandria:with-gensyms (method-obj method-fun next-args next-funs)
`(let* ((,method-obj (find-method #',name ',qualifiers ',specializers))
(,method-fun (closer-mop:method-function ,method-obj)))
(funcall ,method-fun (list ,@arg-values)
@fiddlerwoaroof
fiddlerwoaroof / maintainable-code-js.js
Created May 20, 2017 23:22
Simple Tested Website in NodeJS
'use strict';
var http = require('http');
var url = require('url');
function OK(contentType, body, otherHeaders = {}) {
return [
200,
Object.assign({},
otherHeaders,
(ql:quickload :ningle)
(ql:quickload :clack)
(defvar *app* (make-instance 'ningle:<app>))
(setf (ningle:route *app* "/some.json" :method :GET)
(lambda (p)
(declare (ignore p))
'(200
(:Content-Type "application/json")
(xhtmlambda::def-element <::request)
(defun post-to-endpoint (xml)
(let ((drakma:*text-content-types* (acons "application" "xml" drakma:*text-content-types*)))
(drakma:http-request *endpoint*
:basic-authorization (list *api-key* "X")
:method :post
:content (with-output-to-string (s)
(format s "~w" xml)))))
#!/usr/bin/zsh
git add $argv || exit 1
git commit || exit 2
git push || exit 3
exit 0
INANGULIS> (defun a  c (a  c) a  c)
INANGULIS> (a  c 2)
2