Skip to content

Instantly share code, notes, and snippets.

View norswap's full-sized avatar

norswap norswap

View GitHub Profile
@norswap
norswap / README.md
Created February 10, 2017 15:08
Installing SWI-Prolog

macOS / OS X

Install homebrew then run brew install swi-prolog. You can now run the Prolog shell from the command line with swipl.

Important: do not install from the official website, you will get crashes.

Windows

### Keybase proof
I hereby claim:
* I am norswap on github.
* I am norswap (https://keybase.io/norswap) on keybase.
* I have a public key whose fingerprint is CB7E 4E0F F8C0 2860 6A62 55F2 A7E2 9E43 45FB 1D8E
To claim this, I am signing this object:
@norswap
norswap / InlineReceiver.kt
Created November 8, 2016 13:50
Showcasing the usefulness of inline receivers in Kotlin
inline fun <T, U> (() -> T?).map (crossinline f: (T) -> U): (() -> U?)
{
return { this()?.let(f) }
}
inline fun <T> (() -> T?).filter (crossinline pred: (T) -> Boolean): (() -> T?)
{
return {
var out = this()
while (out != null && !pred(out)) out = this()

As VirtualBox Guest

Networking

In the VM properties, make two connections: a "NAT" for regular internet connectivity, and a "host-only" for ssh connectivity between host and guest with a predictable IP. For this to work, both a NAT adapter and a host-only adapter have to be created in the host via the VirtualBox global preferences.

@norswap
norswap / PluginInterface.kt
Created January 18, 2016 16:36
Plugin Interface Proposal Example for Kotlin
// Basic setup
interface Exp
data class Lit(val x: Int): Exp
data class Add(val x: Exp, val y: Exp): Exp
val exp0 = Add(Lit(42), Lit(0x52))
// Adding a print operation
@norswap
norswap / ObjectAlgebra.kt
Created January 18, 2016 16:30
Object Algebras in Kotlin
// Basic setup
interface Exp
data class Lit(val x: Int): Exp
data class Add(val x: Exp, val y: Exp): Exp
interface IntAlg<A>
{
fun lit(x: Int): A
fun add(x: A, y: A): A
@norswap
norswap / Multi.java
Created March 25, 2013 09:54
Multi.java (Multimethods in Java)
package util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* This class implements multiple dispatch (aka multimethods) using reflection.
* The idea is to choose the method based not only on the runtime type of the
* receiver, but also on the runtime type of the arguments. Normally Java
* selects amongst overloaded alternatives using the static type.
@norswap
norswap / jaffar.rb
Created September 8, 2012 14:50
Jaffar, the Evil Advisor Library
# Jaffar, the Evil Advisor Library
#
# This is a simple experiment in Ruby metaprogmming, to see how to implement
# a lisp-style advising construct. Advising is basically augmenting existing
# functions with your own code. See the exemple below.
#
# Advising is very much related to context-oriented programming. I fortunately
# have no use for either an advising or context-oriented programming right now
# and this is why I did not expand upon this simple implementation.
#