Skip to content

Instantly share code, notes, and snippets.

@dradtke
dradtke / gist:4489205
Created January 8, 2013 23:53
Search Hoogle from Vim.
function! SearchHoogle(q)
call system('firefox "http://www.haskell.org/hoogle/?hoogle='.a:q.'" &')
endfunction
command! -nargs=1 Hoogle call SearchHoogle('<args>')
if has("autocmd")
au filetype haskell nmap K :call SearchHoogle(expand('<cword>'))<cr>
endif
@dradtke
dradtke / gist:3901623
Created October 16, 2012 20:01
Recursively discover all files using Haskell and GIO
-- Given a File object, recursively discover all of its non-directory children
listFiles :: (FileClass f) => f -> IO ([File])
listFiles f
-- this file doesn't exist
| fileQueryExists f Nothing == False = return ([])
-- this file isn't a directory
| fileQueryFileType f [FileQueryInfoNone] Nothing /= FileTypeDirectory = return ([])
-- otherwise, create the enumerator and start looping
@dradtke
dradtke / main.c
Created September 25, 2012 21:47
#include <allegro5/allegro.h>
#include <glib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
uint32_t al_version = al_get_allegro_version();
int al_major_version = al_version >> 24;
int al_minor_version = (al_version >> 16) & 255;
int al_revision = (al_version >> 8) & 255;
@dradtke
dradtke / Makefile
Created September 25, 2012 21:38
Example Makefile for building and running a self-contained game
CC := clang
TARGET := game
AL_CFLAGS := -Ilib/allegro/include
AL_LDFLAGS := -Llib/allegro/lib
GLIB_CFLAGS := -Ilib/glib -Ilib/glib/glib
GLIB_LDFLAGS := -Llib/glib/glib/.libs
CFLAGS := -g -Wall $(AL_CFLAGS) $(GLIB_CFLAGS)
LDFLAGS := $(AL_LDFLAGS) $(GLIB_LDFLAGS)
@dradtke
dradtke / permutations.hs
Created August 24, 2012 21:41
Haskell solution for CodeChef - Ambiguous Permutations (improved)
import Control.Monad
import qualified Data.IntMap as IM
import qualified Data.List as L
import Data.Maybe
import Data.Text
import qualified Data.Text.IO as TIO
import Data.Text.Read
import System.Exit
main = forever $ do
@dradtke
dradtke / permutations.hs
Created August 24, 2012 19:51
Haskell solution for CodeChef - Ambiguous Permutations
import Control.Monad
import Data.List
import Data.Maybe
import System.Exit
main = do
-- get the number for this case, and exit if it's equal to 0
n <- liftM read getLine :: IO (Int)
when (n == 0) exitSuccess
@dradtke
dradtke / gist:3137051
Created July 18, 2012 15:46
Spot Makefile
CC := clang
PKGS := libspotify alsa
CFLAGS := -g -Wall `pkg-config --cflags $(PKGS)`
LIBS := `pkg-config --libs $(PKGS)` -lpthread
TARGET := spot
SOURCES := $(shell find src/ -type f -name *.c)
OBJECTS := $(patsubst src/%,build/%,$(SOURCES:.c=.o))
DEPS := $(OBJECTS:.o=.deps)
// src/main.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libspotify/api.h>
#define DEBUG 1
extern const uint8_t g_appkey[];
extern const size_t g_appkey_size;
@dradtke
dradtke / Makefile
Created April 25, 2012 22:35
Hello World example for Allegro.
CC := gcc
CFLAGS := -g -Wall
LIBS := -lallegro
SOURCES := $(shell find src/ -type f -name "*.c")
OBJECTS := $(SOURCES:.c=.o)
TARGET := game
all: $(SOURCES) $(TARGET)
$(TARGET): $(OBJECTS)
@dradtke
dradtke / store-credit2.hs
Created April 4, 2012 14:34
Alternate solution for store credit
import Data.List
type Input = [String]
data Unsolved = Unsolved { unsolvedNumber :: Int, input :: Input }
data Solved = Solved { solvedNumber :: Int, answer :: String }
data Item = Item { index :: Int, price :: Int }
instance Show Solved where