Skip to content

Instantly share code, notes, and snippets.

View mxswd's full-sized avatar

Maxwell mxswd

View GitHub Profile
@mxswd
mxswd / md2cre.rb
Created July 22, 2012 07:20
Convert Markdown to Creole
#!/usr/bin/env ruby
# Invoke with `ruby md2cre.rb filename.md`
#
# Setup: `gem install redcarpet`
require 'rubygems'
require 'redcarpet'
class Creole < Redcarpet::Render::Base
def normal_text(text)
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
# run `rspec api_spec.rb`
RSpec.configure do |config|
config.color_enabled = true
end
require 'faraday'
require 'json'
describe :api do
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
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
@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]
@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 / 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 / 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 / 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