Skip to content

Instantly share code, notes, and snippets.

View jaspervdj's full-sized avatar
🧀
eating cheese

Jasper Van der Jeugt jaspervdj

🧀
eating cheese
View GitHub Profile
@jaspervdj
jaspervdj / volume.rb
Created February 7, 2011 16:17
Set pulseaudio volume from the command line
#!/usr/bin/ruby
# Pulseaudio volume control
class Pulse
attr_reader :volumes, :mutes
# Constructor
def initialize
dump = `pacmd dump`.lines
@volumes = {}
@jaspervdj
jaspervdj / stereo.cpp
Created March 22, 2011 12:50
Quick & dirty stereo projection hack
/****************************************************************************
* *
* Nite 1.3 - Players Sample *
* *
* Author: Oz Magal *
* *
****************************************************************************/
/****************************************************************************
* *
@jaspervdj
jaspervdj / dependencies.hs
Created March 27, 2011 08:50
Draft of a new dependency analyzer for Hakyll
import Prelude hiding (reverse)
import Control.Arrow (first)
import Data.Set (Set)
import qualified Data.Set as S
import Data.Monoid (Monoid, mappend, mempty)
import Hakyll.Core.DirectedGraph
-- | This data structure represents the state of the dependency analyzer. It
-- holds a complete graph in 'analyzerGraph', which always contains all items,
@jaspervdj
jaspervdj / invert-hex-colors.lua
Created April 8, 2011 07:36
Invert all hex colors (e.g. #fa74b3) as a unix pipe
#!/usr/bin/lua
-- Pattern matching a hex color, e.g. #fa74b3
local hex_color = '#' .. string.rep('[0-9a-f]', 6)
-- Invert a hex color
function invert_hex_color(color)
-- Drop the initial '#'
color = string.sub(color, 2)
local inverted_color = '#'
-- | This is a Haskell implementation of the benchmark published at:
--
-- <http://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/>
--
-- It is pretty fast as well. It uses WAI and the Warp server. I didn't really
-- bother with using any web framework, since it's such a small benchmark.
--
{-# LANGUAGE OverloadedStrings #-}
module Main where
@jaspervdj
jaspervdj / e-mach.hs
Created May 21, 2011 14:54
Example of a pure function which isn't a pure function
-- | A pure function that isn't. Or is it?
--
eMach :: Double
eMach = eMach' 1.0
where
eMach' i
| i' > 0 = eMach' i'
| otherwise = i
where
i' = i / 2.0
@jaspervdj
jaspervdj / Ndfsm.hs
Created June 11, 2011 09:35
NDFSM toy implementation
module Ndfsm
( State (..)
, Transitions
, Ndfsm
, fromTransition
, fromTransitions
, fromAccepting
, fromStart
, lookupTransitions
@jaspervdj
jaspervdj / jekyll.hs
Created June 14, 2011 22:37
Jekyll-like hakyll config. Haven't actually tested it, I need sleep.
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
import Hakyll
import Control.Arrow ((>>>))
main :: IO ()
main = hakyll $ do
-- Favicon
match "favicon.ico" copy
@jaspervdj
jaspervdj / castles.hs
Created July 1, 2011 09:17
Solution to the ghentfpg castles problem by Javache & me
import Data.Monoid
import Data.Ord (comparing)
import Data.List (sortBy, maximumBy)
import Data.Map (Map)
import qualified Data.Map as M
--------------------------------------------------------------------------------
-- We use a 'Castle' structure to represent the nodes, and a simple 'Graph' type
@jaspervdj
jaspervdj / page.hs
Created July 18, 2011 15:05
Hakyll page parser using Parsec
import Control.Applicative ((<$>), (<*>), (<*))
import Text.Parsec.Prim (many, skipMany)
import Text.Parsec.Combinator (choice, many1, manyTill, option)
import Text.Parsec.Char (alphaNum, anyChar, char, newline, spaces, string)
import Text.Parsec.String (Parser)
openMetadata :: Parser String
openMetadata = many1 (char '-') <* newline
metadataField :: Parser (String, String)