Skip to content

Instantly share code, notes, and snippets.

View sordina's full-sized avatar

Lyndon Maydwell sordina

View GitHub Profile
@sordina
sordina / data.sh
Created April 9, 2015 04:37
Generate diagrams of your Haskell data-type interrelationships with this robust and elegant program!
#!/bin/bash
echo 'digraph {'
data="$(grep '^data' Prototype.hs | sed 's/data //; s/ .*//')"
for i in $data
do
echo "$i;"
targets="$(grep "data $i .*=" Prototype.hs -A 6 \
| sed '/^$/,$d' \
| grep '::' \
@sordina
sordina / component-clinic.clj
Last active August 29, 2015 14:16
Component-Clinic ~ Keep your components healthy!
(ns component-clinic.core
"
PSA: Your components may be sick!
Make sure they are having regular checkups at the component-clinic!
> A small helper library to allow components to be made healthy.
> Useful for treating components that may become diseased on-the-fly.
> Initialize sickly components to facilitate crash-driven development.
@sordina
sordina / flojure.clj
Created February 20, 2015 03:21
Create a nice flow-chart from your horrible deeply nested decision tree mess!
(ns flojure
"
Functions relating to decision-tree type code. Allowing for debugging, logging, etc.
"
(:require [clojure.core.match :as m]
[pandect.core :as p]))
(defn truncate
[s n]
(subs s 0 (min (count s) n)))
@sordina
sordina / vty_demo.hs
Created January 27, 2015 11:28
Simple demo of VTY-UI
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text as T
import Graphics.Vty.Widgets.All
import Graphics.Vty.Input.Events
import Control.Monad
import Data.IORef
import System.Exit
import Control.Concurrent
@sordina
sordina / RandomMovie.rb
Last active August 29, 2015 14:13
Play a random movie with Peerflix!
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
require 'cgi'
dom = Nokogiri::HTML.parse( open('http://www.imdb.com/chart/top') )
titles = dom.css('.titleColumn a').map &:text
@sordina
sordina / splines.hs
Last active August 29, 2015 14:12
Ghetto Splines
-- Our Domain is always interpreted as (0 <= t <= 1)
import Data.Complex
type Coord = Complex Double
type FunT = Coord -> Coord
interpolate :: FunT -> FunT -> FunT
@sordina
sordina / parse_indented_lines.hs
Created October 28, 2014 22:57
A simple parser from a string to a tree representing the indentation structure of the text.
{-# LANGUAGE QuasiQuotes #-}
import Data.Tree
import Data.Char
import Control.Arrow
import Text.RawString.QQ
import Test.QuickCheck
import Data.List.Split
@sordina
sordina / parse_indented_lines.clj
Created October 28, 2014 22:55
Simple parser to convert a string into a tree representing the structure of indented lines.
(ns instap)
(defn text [l] (clojure.string/replace l #"^\s+" ""))
(assert (= (text " \t\t\t asdf") "asdf"))
(defn value [c]
(condp = c
\space 1
\tab 4
0 ))
import Data.List
import Control.Lens
import Data.Bits.Lens
import Test.QuickCheck
pascal = iterate stepper firstrow
where
firstrow = [1]
stepper r = zipWith (+) ([0] ++ r) (r ++ [0])
{-# LANGUAGE OverloadedStrings #-}
-- http://cryptopals.com/sets/1/challenges/7/
-- Second implementation without using AES library
-- http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
import GHC.Word
import Data.Bits
import Data.Bits.Lens
import Data.List