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 / html.tarzan
Created October 23, 2014 06:34
Regexp matching xml-ish markup
# HTML
attribute := /([^\\"']|\\.)*/
name := /([a-zA-Z])+/
dquoted := /"/ attribute /"/
squoted := /'/ attribute /'/
quotes := dquoted | squoted
ws := /[ \t]+/
attrpair := name ws /=/ ws quotes
opentag := /</ name (ws attrpair)* />/
closetag := /<\// name />/
@phadej
phadej / folds.scala
Created October 29, 2014 15:00
Short folds.
/*
There aren't any text book -texts on folds, dunno why. Keywords: structural induction, catamorphisms, recursion schemems.
Not so formally, "fold" is function replacing constructors in the data structure:
*/
Bool = True | False
// Constructor types:
// True: Bool
// False: Bool
boolFold[X](t: X, f: X): X
@phadej
phadej / DataParser.swift
Last active August 29, 2015 14:08
Aeson / scala's play2 json parser inspired json parsing
// Playground - noun: a place where people can play
import Foundation
// We <3 Swift
class Box<T> {
let unbox: T
init(_ value: T) { self.unbox = value }
}
import Prelude hiding (id, (.))
import Control.Category
import Control.Arrow
import Control.Arrow.Transformer.Automaton
import Test.QuickCheck
import Test.QuickCheck.Function
type Auto = Automaton (->)
runAuto :: Auto b c -> b -> (c, Auto b c)
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import Data.Aeson
import Data.ByteString.Lazy as B -- imported so it's easy to work in ghci
import qualified Data.HashMap.Strict as HashMap
type DirectoryName = String
@phadej
phadej / command.js
Created December 30, 2014 09:25
so… what’s the most elegant way of parsing “cmd+shift++” into [“cmd”, “shift”, “+”]? #lazyweb
"use strict";
var parser = require("mixfix").parser;
// Have to add this to mixfix!
function token(x) {
return parser.any.satisfy(function (y) {
return x === y;
})
}

Outputs:

zip

s1     0.3 a
s2     2.1 1
zip    2.1 a
zip    2.1 1
s2     4.2 2
@phadej
phadej / Denotational.agda
Created January 5, 2015 13:13
Event streams as [(Time, a)]
module Denotational where
open import Data.Nat
open import Data.Sum
open import Data.Product
open import Data.List
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl; cong; sym)
bench: queue
version: 0.1.0.0
license-file: LICENSE
author: foo
maintainer: foo@bar.com
build-type: Simple
cabal-version: >=1.10
executable queue
@phadej
phadej / Main.hs
Created January 16, 2015 17:38
Concurrent fibonacci
{-# LANGUAGE BangPatterns #-}
module Main where
import Control.Concurrent
import Control.DeepSeq
import System.Environment (getArgs)
import System.IO.Unsafe (unsafePerformIO)
data Tree a = Tree (Tree a) a (Tree a)
instance Functor Tree where