Skip to content

Instantly share code, notes, and snippets.

View mtolly's full-sized avatar

Michael Tolly mtolly

View GitHub Profile
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Control.Monad.Trans.Writer
import Data.String (IsString (..))
newtype ListBuilder e a = ListBuilder { runListBuilder :: Writer [e] a }
deriving (Functor, Applicative, Monad)
@mtolly
mtolly / mac-libgdiplus.sh
Last active March 10, 2024 07:35
How to build and install the Mono libgdiplus.dll on a Mac with Homebrew (update: no longer needed, see comments)
#!/bin/bash
# First install XQuartz, then...
brew install freetype fontconfig libpng
ln -s /opt/X11/include/X11 /usr/local/include/X11
git clone git@github.com:mono/libgdiplus
cd libgdiplus
./autogen.sh
make install
@mtolly
mtolly / Adder.hs
Created July 29, 2015 01:22
Small example of compiling a Haskell Mac .dylib to be used from C
{-# LANGUAGE ForeignFunctionInterface #-}
module Adder where
import Foreign.C
adder :: CInt -> CInt -> IO CInt
adder x y = return $ x + y
foreign export ccall adder :: CInt -> CInt -> IO CInt
@mtolly
mtolly / A.hs
Created July 15, 2015 18:06
Sample Haskell project using embedded Ruby as a preprocessor
module A where
@mtolly
mtolly / music.rb
Created April 20, 2015 13:31
My script for copying and compressing music from an archive to a listening device
#!/usr/bin/env ruby
# Run from the destination root (somedevice/music/):
# .../music.rb audiosource/artist1/album1 audiosource/artist2/album2 ...
require 'fileutils'
ARGV.each do |dir|
dir = File.absolute_path(dir)
album = File.basename(dir)
@mtolly
mtolly / async.hs
Last active August 29, 2015 14:19
GHCJS: calling async JS functions in parallel, with time limits
{-# LANGUAGE JavaScriptFFI #-}
module Main where
import Control.Concurrent
import Control.Monad
-- | Very simple, no exception safety. Intended for async JS functions.
parallel :: [IO a] -> IO [a]
parallel fs = do
vars <- forM fs $ \f -> do
{- |
No attempt made to golf, but I did throw some alternate solutions in.
-}
module HW3 where
import Data.List (transpose)
skips :: [a] -> [[a]]
skips xs = zipWith const (map (f xs) [0..]) xs where
-- "zipWith const" clamps the first list to be no longer than the second.
@mtolly
mtolly / vra.hs
Last active August 1, 2018 16:28
Extract game files from Vagante. UPDATE: See https://github.com/mtolly/vagante-extract for new version
{- |
Extracts and injects files from the game Vagante's data.vra.
The format (after a 0x18-byte-long header) is a simple repeating pattern:
- length of filename (4 bytes little-endian)
- filename
- length of file data (4 bytes little-endian)
- file data
The files themselves are all nice standard formats:
OGG, WAV, PNG, JSON, TTF, and OpenGL fragment shader.
-}
@mtolly
mtolly / local_to_global.asm
Created December 19, 2014 02:30
An assembly file for pokemid by dannye
Music_TitleScreen_Ch1::
tempo 130
volume 7, 7
toggleperfectpitch
duty 0
notetype 6, 15, 7
octave 4
E_ 1
F_ 1
notetype 12, 15, 7
@mtolly
mtolly / speed1_ticks1.asm
Created October 16, 2014 02:05
Demonstrates a possible bug in Pokémon Red/Blue's music engine
Music_TitleScreen_Ch1::
tempo 150
octave 2
notetype 1, 10, 0
C_ 1
endchannel
Music_TitleScreen_Ch2::
Music_TitleScreen_Ch3::
Music_TitleScreen_Ch4::