Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
@larsmans
larsmans / nonogram.pl
Created August 15, 2011 13:22
Nonogram/paint-by-numbers solver in SWI-Prolog
/*
* Nonogram/paint-by-numbers solver in SWI-Prolog. Uses CLP(FD),
* in particular the automaton/3 (finite-state/RE) constraint.
* Copyright 2011, 2014 Lars Buitinck
* Copyright 2014 Markus Triska
* Do with this code as you like, but don't remove the copyright notice.
*/
:- use_module(library(clpfd)).
@daveray
daveray / match.pojo.clj
Created August 27, 2011 03:02
Generate match lookup for a Java class
(ns match.pojo
(:use [match.core :only [IMatchLookup val-at* match]]))
(set! *warn-on-reflection* true)
(defmacro pojo-match
"Generate an implementation of match.core/IMatchLookup for the given Java class.
Keys are mapped like this:
isVisible -> :visible?
@wycats
wycats / works_today.js
Created September 27, 2011 21:42 — forked from swannodette/gist:1246024
named_subtemplates.hb
<!--
I'm sure there's a better syntax for naming subtemplates
-->
<h3>This is a list</h3>
<ul>
{{#each items}}
{{@cell}}
<li>
{{..}}
@bmmoore
bmmoore / match.agda
Created October 25, 2011 03:29
Horrible pattern matching hack
{-# OPTIONS --universe-polymorphism #-}
module match where
open import Data.List hiding (or)
open import Category.Monad
open import Category.Functor
open import Function
open import Data.Maybe
open import Data.Bool
open import Data.Nat
open import Relation.Binary.PropositionalEquality
@swannodette
swannodette / gist:1326585
Created October 30, 2011 23:23
stones.scm
(usefd)
(define (powerset a)
(if (null? a) (list '())
(let ((p (powerset (cdr a))))
(append (map (lambda (x) (cons (car a) x)) p) p))))
(define (remove-duplicates l)
(do ((a '() (if (member (car l) a) a (cons (car l) a)))
(l l (cdr l)))
-- Solution to http://beust.com/weblog/2011/10/30/a-new-coding-challenge/
import Data.List(isInfixOf)
partitions n 1 = [[n]]
partitions n k | n > 0 = [m:ms | m <- [1..n `div` 2], ms <- partitions (n-m) (k-1)]
partitions n k | otherwise = []
weighings [] = [0]
weighings (w:ws) = [m + n | m <- weighings ws, n <- [-w, 0, w]]
@swannodette
swannodette / gist:1424929
Created December 2, 2011 21:35
test.sml
let
val Id = fn x => x
in
Id
end
(*
Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
@jonifreeman
jonifreeman / scalatoprolog.md
Created January 30, 2012 09:16
Scala type system -> Prolog
@fogus
fogus / delegating-proxy.clj
Created February 1, 2012 16:53 — forked from michalmarczyk/delegating-proxy.clj
A ridiculous proxy macro which delegates calls to methods which have not been explicitly implemented to a specified object.
;;; Written when pondering
;;; http://stackoverflow.com/questions/9086926/create-a-proxy-for-an-specific-instance-of-an-object-in-clojure
(defmacro delegating-proxy [o class-and-ifaces ctor-args & impls]
(let [oname (gensym)]
(letfn [(delegating-impls [^java.lang.reflect.Method ms]
(let [mname (symbol (.getName ^java.lang.reflect.Method (first ms)))
arity-groups (partition-by #(count (.getParameterTypes ^java.lang.reflect.Method %)) ms)
max-arity (max-key #(count (.getParameterTypes ^java.lang.reflect.Method %)) ms)]
`(~mname
@swannodette
swannodette / gist:1893724
Created February 23, 2012 16:52 — forked from fogus/gist:1893062
pretty-lambdas for elisp
(defun pretty-lambdas ()
"Show glyph for lower-case Greek lambda (λ) wherever 'lambda' appears."
(font-lock-add-keywords
nil
`(("(\\(lambda\\>\\)"
(0
(progn
(compose-region
(match-beginning 1)
(match-end 1)