Skip to content

Instantly share code, notes, and snippets.

View relrod's full-sized avatar

Rick Elrod relrod

View GitHub Profile
@tonymorris
tonymorris / Lens.cs
Created August 5, 2012 05:43
Lens library for C# (demonstration)
using System;
using System.Collections;
using System.Collections.Generic;
/*
A basic lens library for the purpose of demonstration.
Implements a lens as the costate comonad coalgebra.
This library is not complete.
A more complete lens library would take from
@jestan
jestan / gist:3692077
Created September 10, 2012 16:51 — forked from mtnygard/gist:2254147
Books I recommended today
@puffnfresh
puffnfresh / covariant.ts
Created October 1, 2012 17:06
Covariant arrays. Blurgh.
// Compiles fine even though the code is broken.
// This is because arrays are covariant and mutable.
//
// TypeScript team: Please fix either of those things. Preferably mutability :)
class Animal {}
class Snake extends Animal {
slither() {
alert("Slithering!")
@ekmett
ekmett / Golf.hs
Created November 2, 2012 23:58
golfing pi and e
-- e
> let z a b c d w@(x:y)=let t=a`div`c in if all(>0)[a,b,c,d]&&t==b`div`d then t:z(10*(a-c*t))(10*(b-d*t))c d w else z(x*a+b)a(x*c+d)c y;f n=1:1:n:f(n+2)in z 1 0 0 1(2:1:2:f 4)>>=show
> let z a b c d w@(x:y)|t<-a`div`c=if all(>0)[a,b,c,d]&&t==b`div`d then t:z(10*(a-c*t))(10*(b-d*t))c d w else z(x*a+b)a(x*c+d)c y;f n=1:1:n:f(n+2)in z 1 0 0 1(2:1:2:f 4)>>=show
> let z a b c d w@(x:y)|all(>0)[a,b,c,d]&&t==b`div`d|True=t:z(10*(a-c*t))(10*(b-d*t))c d w else z(x*a+b)a(x*c+d)c y where t=a`div`c;f n=1:1:n:f(n+2)in z 1 0 0 1(2:1:2:f 4)>>=show
> let z a b c d w@(x:y)|all(>0)[a,b,c,d]&&t==b`div`d=t:z(10*(a-c*t))(10*(b-d*t))c d w|True=z(x*a+b)a(x*c+d)c y where{t=a`div`c};f n=1:1:n:f(n+2)in z 1 0 0 1(2:1:2:f 4)>>=show
> let f n=1:1:n:f(n+2);z a b c d w@(x:y)|t<-a`div`c,all(>0)[a,b,c,d]&&t==b`div`d=t:z(10*(a-c*t))(10*(b-d*t))c d w|True=z(x*a+b)a(x*c+d)c y in z 1 0 0 1(2:1:2:f 4)>>=show
> let f n=1:1:n:f(n+2);z a b c d w@(x:y)|any(<=0)[a,b,c,d]||t/=b`div`d=z(x*a+b)a(x*c+d)c y|t<-a`div`c=t:z(10*(a-c*t))(10*(b-d*t))c d w
@ymasory
ymasory / scala-irc
Last active August 30, 2017 21:16
List of all Scala-related IRC channels.
Please help compile a list of all Scala-related IRC rooms.
All of these channels are on Freenode.
#akka | concurrency & distribution framework
#argonaut | json library
#fp-in-scala | the book Functional Programming in Scala
#geotrellis | geoprocessing library
#indyscala | regional scala group
#json4s | json library
@t0yv0
t0yv0 / subtyping.v
Last active February 28, 2021 01:47
Demonstrating TypeScript 0.8 type system to be unsound. The subtyping relationship is defined in a way that admits the following code that results in TypeError exception being thrown.
Require Import Utf8.
Inductive subtype (a b : Set) : Set :=
| ST : (a -> b) -> subtype a b.
Infix ":>" := subtype (at level 50).
Definition st {x y} f := ST x y f.
Definition unpack {a b : Set} (st : a :> b) :=
@dkhenry
dkhenry / play2.service
Created January 6, 2013 21:28
Systemd script for the Play Framework
[Unit]
Description=Play2 Server for <site>
After=network.target
 
[Service]
Type=simple
PIDFile=<path>/RUNNING_PID
 
ExecStartPre=/bin/sh -c 'cd <path> ;/bin/rm RUNNING_PID ; sbt clean compile stage'
ExecStart=<path>/target/start
@rodneyrehm
rodneyrehm / anti-keygrabber.user.js
Last active May 26, 2024 17:50
GreaseMonkey: Prevent Web Applications From Grabbing Certain HotKeys
// ==UserScript==
// @name anti key-grabber
// @description Prevent web apps from capturing and muting vital keyboard shortcuts
// @grant none
// @version 1.1
// ==/UserScript==
(function(){
var isMac = unsafeWindow.navigator.oscpu.toLowerCase().contains("mac os x");
unsafeWindow.document.addEventListener('keydown', function(e) {
if (e.keyCode === 116) {
@twanvl
twanvl / Sorting.agda
Last active December 2, 2022 16:44
Correctness and runtime of mergesort, insertion sort and selection sort.
module Sorting where
-- See https://www.twanvl.nl/blog/agda/sorting
open import Level using () renaming (zero to ℓ₀;_⊔_ to lmax)
open import Data.List hiding (merge)
open import Data.List.Properties
open import Data.Nat hiding (_≟_;_≤?_)
open import Data.Nat.Properties hiding (_≟_;_≤?_;≤-refl;≤-trans)
open import Data.Nat.Logarithm
open import Data.Nat.Induction
@tonymorris
tonymorris / IO.scala
Created November 5, 2013 23:57
Pure-functional IO in Scala
sealed trait IOOperation[A] {
def map[B](f: A => B): IOOperation[B] =
this match {
case PutChar(c, a) =>
PutChar(c, f(a))
case GetChar(g) =>
GetChar(f compose g)
}
}
case class PutChar[A](c: Char, a: A) extends IOOperation[A]