Skip to content

Instantly share code, notes, and snippets.

View KirinDave's full-sized avatar

Dave Fayram KirinDave

View GitHub Profile
@KirinDave
KirinDave / DictTrick.hs
Created May 25, 2018 17:35 — forked from jship/DictTrick.hs
Small example showing the Dict trick to discover available instances from a GADT
#!/usr/bin/env stack
-- stack --resolver lts-10.8 --install-ghc exec ghci
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
-- A key type for pretend use in looking up a doggo in a database.
newtype Key a = Key { unKey :: String }
package stupid
import (
"fmt"
"reflect"
"unsafe"
)
type iptr struct {
@KirinDave
KirinDave / gist:6117117
Last active December 20, 2015 10:39 — forked from danryan/gist:6116878
HTTP/1.1 200 OK
Server: Turtle
Content-Type: application/turtles; charset=turtles
{
"turtles": {
"turtles": {
"turtles": {
"turtles": {
"turtles": {
"turtles": {
@KirinDave
KirinDave / gist:1162732
Created August 22, 2011 15:53 — forked from Ragmaanir/gist:1162677
cyclic definitions
object A1 { lazy val X = B1.Y }
object B1 { lazy val Y: Int = A1.X }
println("Executes safely unless you try and evaluate A1.X or B1.Y because they have no definition.")
object ABase { val X = 1 }
object A2 { lazy val X = B2.Y+1 }
object B2 { lazy val Y :Int = ABase.X*2 }
println("Even this could cause problems, but lazy helps. A2.X = " + A2.X.toString)
(defn get-route [route-map req]
(loop [routes (keys route-map)]
(let [route (first routes)]
(if (route-matches route req)
(get route-map route)
(recur (rest routes))))))
; This is one way
(defn get-route [route-map req]
(when-let [[route fun] (first (filter #(route-matches (first %) req) route-map))]
<html>
<head>
<title>Welcome to Oatmeal Homeland!</title>
<meta name="description" content="">
<meta name="keywords" content="Private server, WoW, World of Warcraft">
<STYLE>
:link {color: #666633; font-weight: normal;}