Skip to content

Instantly share code, notes, and snippets.

View mxswd's full-sized avatar

Maxwell mxswd

View GitHub Profile
Copyright (c) 2009, Natacha Porté
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@mxswd
mxswd / Sheet.hs
Created January 20, 2013 02:42
Spreadsheet-like example.
{-# LANGUAGE OverloadedStrings #-}
module Sheet where
import qualified Data.Map as M
import Text.PrettyPrint.Boxes
import Data.List
type Row a = M.Map Key a
type Key = String
@mxswd
mxswd / Domains.hs
Created January 1, 2013 01:17
Domain management at its simplest.
import Data.List
data Domain = Domain { domain :: String, dns :: DNS } deriving (Show)
data Service = Service { name :: String, servtype :: ServType, description :: String } deriving (Show)
data ServType = Heroku | GitHubPages | Redirect deriving (Show, Eq)
data DNS = DNS { dprovider :: String, dname :: String, services :: [Service] } deriving (Show)
-- presentation
@mxswd
mxswd / tools.rb
Created December 22, 2012 01:37
TCL interface to appending to a YAML file.
require 'tk'
class App
def make_row(window, name)
var = TkVariable.new
row = TkFrame.new(window) do
# Frame for a row
pack { fill 'both'; side 'top' }
@mxswd
mxswd / DegreeSolver.hs
Created December 12, 2012 15:07
Check the courses remaining in a university degree.
-- Copyright (C) 2012 by Maxwell Swadling
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
@mxswd
mxswd / .htaccess
Created December 12, 2012 01:04
Apache config to redirect everything except the cgi-bin
RewriteEngine on
RewriteBase /~maxs/
RewriteRule ^cgi-bin - [L,NC]
RewriteRule (.*) http://maxpow4h.com/$1 [R=301,L]
require 'faraday'
require 'json'
require 'couchrest'
@couch = CouchRest.new("http://127.0.0.1:5984")
@db = @couch.create_db('items')
# http://127.0.0.1:5984/_utils/
# TODO: download images as attachments
require 'prawn'
# Page size: 595.28 x 841.89
$WIDTH = 595.28
$HEIGHT = 841.89
Prawn::Document.generate("hello.pdf", :margin => 0, :page_size => [$WIDTH, $HEIGHT]) do
def put(img, x, y)
image "game/#{img}.png", :at => [$WIDTH * (x / 3.0), $HEIGHT * ((y+1) / 4.0)], :height => $HEIGHT / 4
end
# run `rspec api_spec.rb`
RSpec.configure do |config|
config.color_enabled = true
end
require 'faraday'
require 'json'
describe :api do
import Data.Yaml
import qualified Data.Map as M
main = do
Just f <- decodeFile "programs.yml"
let Just x = M.lookup "SENG" f
case x of
Nothing -> fail "InvalidFile"
Just a -> putStrLn a