Skip to content

Instantly share code, notes, and snippets.

View mxswd's full-sized avatar

Maxwell mxswd

View GitHub Profile
@mxswd
mxswd / Shorthash.hs
Created June 6, 2013 14:11
Hashing!
module Shorthash where
import Data.Digest.Pure.MD5 (md5)
import qualified Data.ByteString.Base64 as B64
import qualified Data.Serialize as B
import qualified Data.Text.Lazy as L
import qualified Data.Text.Lazy.Encoding as T
import qualified Data.ByteString as BS
@mxswd
mxswd / bytestring_uri.txt
Created June 5, 2013 07:42
Escaping a bytestring URI.
Moriya:HSNIP maxs$ ghci Main.hs
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 2] Compiling Backend.Redis ( Backend/Redis.hs, interpreted )
[2 of 2] Compiling Main ( Main.hs, interpreted )
Ok, modules loaded: Main, Backend.Redis.
*Main> :t escape
escape :: BS.ByteString -> BS.ByteString
@mxswd
mxswd / airplay.rb
Last active December 17, 2015 08:49
Stream a video to an Apple TV.
#!/opt/boxen/rbenv/shims/ruby
# You need these gems, set your host on the lan
# plus use the correct ruby path above.
# Also install the puma gem.
# You need to launch this with the FULL path to the video file.
require 'sinatra'
require 'airplay'
require 'socket'
VIDEO = ARGV[0]
@mxswd
mxswd / Magic.hs
Created April 27, 2013 04:21
The goal would be to write stream transformers you can evaluate in Haskell, QuickCheck or produce Objective-C ReactiveCocoa code. Currently, Map *doesn't* go from a -> b, so it is fairly useless. See https://alpha.app.net/maxpow4h/post/5088051/photo/1 for an example. MIT license, Copyright 2013 Maxwell Swadling
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GADTs, IncoherentInstances, MultiParamTypeClasses, NoMonomorphismRestriction #-}
module Magic (objc, run, filter, map, hasPrefix, uppercaseString, length, RACs, Free, show) where
-- todo: quickcheck
import Control.Monad.Free
import Prelude hiding (filter, map, length, show, Show)
import qualified Prelude as P
import Data.Char
import qualified Data.List as L
@mxswd
mxswd / Foo.hs
Last active December 16, 2015 02:39
Example usage (with warnings removed)
module Foo where
foreign export ccall foo :: Int -> IO Int
foo :: Int -> IO Int
foo n = return (length (f n))
f :: Int -> [Int]
f 0 = []
f n = n:(f (n-1))
@mxswd
mxswd / puppet.md
Last active December 15, 2015 05:49
Setting up Puppet

Quick reference to setting up puppet.

First install puppet:

wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb
sudo dpkg -i puppetlabs-release-precise.deb
sudo apt-get update
sudo apt-get install puppet-common

Now git clone your puppet repo into /etc/puppet or use a puppetmaster.

@mxswd
mxswd / YamlAppend.hs
Created March 16, 2013 23:20
Haskell program with TCL gui to append to YAML files.
import System.IO
import System.Environment
import System.Process
import System.Exit
import Data.Maybe
import Control.Applicative
import HTk.Toplevel.HTk
import Data.Yaml
//
// AFHTTPClient+MTLModel.h
// MXProjects
//
// Created by Maxwell Swadling on 2/03/13.
// Copyright (c) 2013 Maxwell Swadling. All rights reserved.
//
#import <AFNetworking/AFNetworking.h>
#import <Mantle.h>
#!/usr/bin/env bash
# Usage: mx configvim
# Summary: Configures / updates vim
# Help: Run it, get a configured vim.
set -e
case "$1" in
# Install .vim
install)
pushd ~
@mxswd
mxswd / ExampleMakefile
Created January 31, 2013 10:33
Example Makefile
# Makefile
# 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