Skip to content

Instantly share code, notes, and snippets.

@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
@fiddlerwoaroof
fiddlerwoaroof / composer.json
Last active January 30, 2016 01:06
Markdown Test Case
{
"name": "fiddlerwoaroof/markdown_case",
"require": {
"league/commonmark": "^0.13.0"
},
"authors": [
{
"name": "fiddlerwoaroof",
"email": "fiddlerwoaroof@gmail.com"
}
@fiddlerwoaroof
fiddlerwoaroof / gist:72d1149501369eb20a06
Created September 26, 2015 15:09
Installed packages
/home/edwlan/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/package.conf.d:
Cabal-1.22.4.0
array-0.5.1.0
base-4.8.1.0
bin-package-db-0.0.0.0
binary-0.7.5.0
rts-1.0
bytestring-0.10.6.0
containers-0.5.6.2
deepseq-1.4.1.1