Skip to content

Instantly share code, notes, and snippets.

View phadej's full-sized avatar
🦉
Someone here is possessed by an owl. Who?

Oleg Grenrus phadej

🦉
Someone here is possessed by an owl. Who?
View GitHub Profile
@phadej
phadej / 1_Ref.agda
Created August 6, 2014 10:38
The Scala translation of this particular Agda code snippet is quite close to the C++ version. Exercise: translate to Haskell.
module Ref where
open import Prelude
-- We have three mutually circular types, "entities": Foksi, Fusku and Fuksi
-- (Note: Finnish is an awesome language: Foksi, Fusku and Fuksi are foxtrot, single-time swing and freshman respectively)
-- Each entity value has an identifier.
Identifier : Set
@phadej
phadej / jquery.sh
Created August 17, 2014 12:47
To uglify or not to uglify
#!/bin/sh
set -e
gzip -c -9 jquery-2.1.1.js > jquery-2.1.1.js.gz
bzip2 -c -9 jquery-2.1.1.js > jquery-2.1.1.js.bz2
xz -c -9 jquery-2.1.1.js > jquery-2.1.1.js.xz
uglifyjs jquery-2.1.1.js > jquery-2.1.1.min.js
uglifyjs jquery-2.1.1.js -b > jquery-2.1.1.nocomments.js
module Supercell.LookingForServerEngineers where
import Supercell.Engineer as E
import Supercell.Job as J
import Control.Monad
import Data.Bits
identifier :: Int
identifier = 8192
@phadej
phadej / nub.v
Last active August 29, 2015 14:05
from #haskell: Sensored: i think you can define nub with a fold
Require Import Arith.
Require Import List.
Require Import Recdef.
Definition EqDec (A : Type) := forall (x y : A), {x = y} + {x <> y}.
Fixpoint delete {A : Type} (eq : EqDec A) (x : A) (ls : list A) : list A :=
match ls with
| nil => nil
| cons h t => if eq x h
@phadej
phadej / env-postgres-osx.sh
Created September 21, 2014 06:51
Just source env-postgres-osx.sh to add psql to the PATH
POSTGRES_BIN=/Applications/Postgres.app/Contents/Versions/9.3/bin
if [ -d $POSTGRES_BIN ]; then
export DATABASE_URL=postgres:///`whoami`
export PATH=$PATH:$POSTGRES_BIN
fi
@phadej
phadej / conf.sh
Created October 8, 2014 13:38
Simple clean environment
# Example configuration
export PATH=/usr/bin
export FOO=1
export BAR=2

Suppose we extend the example in Travis' answer:

sealed trait Foo { def name: String }
case class Bar(name: String, i: Int) extends Foo
case class Baz(name: String, c: Char) extends Foo

import play.api.libs.functional.syntax._
import play.api.libs.json._
@phadej
phadej / property.md
Last active August 29, 2015 14:07
Property based testing in JavaScript with jsverify

Property based testing

#jsverify #quickcheck #freaklies @phadej @futurice


Prelude

Who is familiar with Haskell

Calling monadic bind flatMap may cause some confusion. flatMap is very list (or container) specialised name which gives false intuition. Even worse is to call monadic join flatten. Monadic join isn't very good name either, if you drop monadic.

OTOH: flatten does flatten type structure, F[F[A]] => f[A], but I'm not sure how many of us think on the type-level first.

I'm very glad that in scalaz monadic bind is bind. Unfortunately Scala's for comprehension desugars into flatMap's, AFAIK.

One (a bit contrived) example: https://github.com/phadej/playground/blob/master/scala/src/main/scala/homogenicpair.scala

@phadej
phadej / tree.md
Last active August 29, 2015 14:08

This example highlights the eager evaluation problem. Let's give it a bit of though:

Assume we have a tree:

  A
 / \
B   C
   / \
  B   D