Skip to content

Instantly share code, notes, and snippets.

View beastaugh's full-sized avatar

Benedict Eastaugh beastaugh

View GitHub Profile
@beastaugh
beastaugh / DropConsec.hs
Created September 1, 2011 10:26
Drop consecutive elements of a list if they're the same, e.g. "AAABBACDDD" => "ABACD"
module Data.List.DropConsec
( dropConsec
) where
import Data.List (dropWhile)
dropConsec :: Eq a => [a] -> [a]
dropConsec [] = []
dropConsec (x:xs) = x : dropConsec (dropWhile (== x) xs)
@beastaugh
beastaugh / installing-ghc7.2-osx10.7.md
Created August 24, 2011 21:41
Installing GHC 7.2 on Mac OS X 10.7 Lion

Installing GHC 7.2 on Mac OS X

This is a brief and bare-bones guide to getting GHC 7.2 and the cabal-install tool (the two basic things you'll need to do Haskell development) up and running on a new Mac OS X 10.7 install.

The instructions given here worked for me, but YMMV.

@beastaugh
beastaugh / case_sensitive.c
Created August 22, 2011 11:11
Figure out if your Mac is running a case sensitive filesystem.
#include <stdio.h>
#include <unistd.h>
int main(void) {
if (pathconf("/", _PC_CASE_SENSITIVE)) {
printf("The file system is case sensitive\n");
} else {
printf("The file system is case insensitive\n");
}
@beastaugh
beastaugh / iso-8859-15_to_utf-8.rb
Created July 11, 2011 08:58
Convert a file from ISO-8859-15 to UTF-8
#!/usr/bin/env ruby
file = ARGV.shift
contents = File.read(file, {:encoding => "ISO-8859-15", :mode => "rb"})
contents.encode!("UTF-8")
File.open(file, 'w') do |f|
f.write(contents)
@beastaugh
beastaugh / CountLicenses.hs
Created April 26, 2011 20:31
Script to count how many different packages use particular licenses on Hackage.
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
{-
To use this script you need to extract your local Hackage index file. If
your setup is anything like mine, you should be able to find a .tar file
containing the listing somewhere like this:
~/.cabal/packages/hackage.haskell.org/00-index.tar.gz
@beastaugh
beastaugh / HDBC-mysql_GHC7.diff
Created April 15, 2011 23:08
Patch to get HDBC-mysql running on GHC 7.0
diff -rN old-HDBC-mysql/Database/HDBC/MySQL/Connection.hsc new-HDBC-mysql/Database/HDBC/MySQL/Connection.hsc
2c2
< {-# OPTIONS -fglasgow-exts #-}
---
> {-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables, EmptyDataDecls #-}
125c125
< mysql_autocommit mysql_ 0
---
> _ <- mysql_autocommit mysql_ 0
674c674
routeArticle :: Routes
routeArticle = customRoute (flip replaceExtension ".html" . dropDate)
dropDate :: Identifier -> FilePath
dropDate ident = let file = toFilePath ident
in replaceFileName file (drop 11 $ takeFileName file)
@beastaugh
beastaugh / functions.php
Created April 3, 2011 13:14
A full-width version of the Tarski theme.
<?php
function my_theme_init() {
if (!is_admin()) {
wp_enqueue_style('tarski_stylesheet', get_template_directory_uri() . '/style.css');
}
}
add_action('init', 'my_theme_init');
-- Render RSS feed
route "rss.xml" $ idRoute
create "rss.xml" $
requireAll_ "posts/*"
>>> mapCompiler (arr $ copyField "body" "description")
>>> renderRss feedConfiguration
@beastaugh
beastaugh / gist:888519
Created March 26, 2011 18:35
Stupid case-insensitive file system :/
~/projects/hakyll/examples/brochure (examples) $ ll
total 32
-rw-r--r-- 1 ionfish staff 724B 27 Sep 18:57 about.rst
-rw-r--r-- 1 ionfish staff 794B 27 Sep 18:57 code.lhs
drwxr-xr-x 4 ionfish staff 136B 15 Nov 15:25 css
-rw-r--r--@ 1 ionfish staff 504B 26 Mar 18:32 hakyll.hs
-rw-r--r--@ 1 ionfish staff 1.1K 27 Sep 18:57 index.markdown
drwxr-xr-x 3 ionfish staff 102B 19 Mar 12:13 templates
~/projects/hakyll/examples/brochure (examples) $ ghc --make hakyll.hs