Skip to content

Instantly share code, notes, and snippets.

View mxswd's full-sized avatar

Maxwell mxswd

View GitHub Profile
{-# LANGUAGE OverloadedStrings, TypeOperators #-}
import Control.Monad (mapM)
import Data.String
import Language.C.Syntax
import Control.Category
import Prelude hiding ((.), id)
import Language.C.Parser
import qualified Language.C.Syntax as C
{-# LANGUAGE DataKinds, KindSignatures, GADTs, RankNTypes #-}
data K = X | Y
data Box (a :: K) where
Box :: Box a
class Foo (a :: K) where
name :: Box a -> String
@mxswd
mxswd / Monad.cc
Last active December 28, 2015 07:49
#include <tr1/type_traits>
#include <iostream>
#include <vector>
#include <algorithm>
// (* -> *) -> Constraint
template<template <typename> class T>
class Functor {
public:
template <typename A, typename B>
class (Show a, Read a) => PlainTextDB a where
get :: IO a
get = fmap read $ readFile "db.txt"
set :: a -> IO ()
set x = return (show x) >>= writeFile "db.txt"
instance PlainTextDB Int
main = do
set (4 :: Int)
module Foo where
data Foo = Foo { name :: NSString, age :: NSNumber }
dothing :: Foo -> NSString
dothing x = do
n <- name x
a <- age x
return n
@mxswd
mxswd / Log Song.scpt
Created December 24, 2013 09:39
Log song titles from iTunes http audio streaming to a file.
-- http://www.macosxautomation.com/applescript/sbrt/sbrt-09.html
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as string
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
@mxswd
mxswd / FolderRave.hs
Created December 29, 2013 09:07
Cycle colours of a File label on OS X every half second.
{-# LANGUAGE RankNTypes #-}
import Control.Concurrent
import Control.Monad.Fix
import Control.Monad.IO.Class
import Control.Wire.Core
import Control.Wire.Session
import Data.Functor.Identity
import System.IO
import Control.Wire
import Prelude hiding ((.), id)
{-# LANGUAGE TemplateHaskell #-}
module Rect (Rect, x, y, rect) where
import Control.Lens
import Data.Functor
data Rect = Rect { _x :: Int, _y :: Int }
makeLenses ''Rect
{-# LANGUAGE CPP #-}
import Distribution.Simple
import Distribution.Simple.Configure
import System.Directory
import System.Cmd
import Distribution.Simple
import Control.Monad (when)
@mxswd
mxswd / MaxC2Hs.hs
Created January 3, 2014 12:20
A small c2hs alternative?
{-# LANGUAGE TemplateHaskell #-}
import System.Environment (getArgs)
import Control.Monad (mapM)
import Text.PrettyPrint.Mainland
import qualified Data.ByteString.Char8 as B
import qualified Language.C.Syntax as C
import qualified Language.C.Parser as P
import Data.Loc
import Language.Haskell.TH
import Foreign.Ptr