<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>Maxwell Swadling</title>
  <link href="http://maxpow4h.com/atom.xml" rel="self"/>
  <link href="http://maxpow4h.com/"/>
  <updated>2013-04-30T04:31:16-07:00</updated>
  <id>http://maxpow4h.com</id>
  <author>
    <name>Maxwell Swadling</name>
  </author>

  
  <entry>
    <title>How to Write Documents</title>
    <link href="http://maxpow4h.com/posts/how-to-write-doc"/>
    <updated>2013-03-26T00:00:00-07:00</updated>
    <id>http://maxpow4h.com/posts/how-to-write-doc</id>
    <content type="html">&lt;p&gt;This is my &quot;getting started&quot; with writing documents guide.&lt;/p&gt;

&lt;h2&gt;Write Document&lt;/h2&gt;

&lt;p&gt;First step: write the document in plain text (I use markdown). Plain text
is easy to diff, put into source control, collaborate on, plus there are
some great editors out there with tons of tools.&lt;/p&gt;

&lt;h2&gt;Makefile&lt;/h2&gt;

&lt;p&gt;Make a Makefile. Makefiles define a process to convert forms of data, such
as a plain text document into a type setted document, plus are platform
agnostic. A simple example would be:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;%.pdf : %.tex
  pdflatex $&amp;lt;
  pdflatex $&amp;lt;
  pdflatex $&amp;lt;

%.tex.in : %.md
  multimarkdown -t latex -o $@ $&amp;lt;

%.tex : %.tex.in
  m4 template.m4 &amp;gt; $@

default: report.pdf
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;template.md&lt;/h2&gt;

&lt;p&gt;Make a &lt;code&gt;template.m4&lt;/code&gt; to template the outputted latex into a template.
Remember your plain text document only specifies the document, not any
formatting rules. So you can define some macros such as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;divert(-1)
dnl Report name
define(`REPORT_NAME', `Assignment 1')
define(`chapter', `section*')
divert(0)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;REPORT_NAME&lt;/code&gt; macro is just a constant I can use in the markdown. The
&lt;code&gt;chapter&lt;/code&gt; lets me use &lt;code&gt;## Title&lt;/code&gt; in markdown and it will convert it to a
unnumbered section.&lt;/p&gt;

&lt;p&gt;I find it useful to shell out to get the git commit I am on to embed into the
report.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;define(`GIT_COMMIT', `esyscmd(git rev-parse HEAD)')
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can make more interesting macros like for including
figures on the page or forcing page breaks from markdown.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;define(`FIGURE', `\begin{figure}[]
  \centering
  $1
  \caption{$2}
  \label{fig:$3}
  \end{figure}')
define(`PAGEBREAK', `\pagebreak')
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After you have defined the macros you want and &lt;code&gt;divert(0)&lt;/code&gt;, you should then
include a template to wrap your latex. To insert your document, include
&lt;code&gt;sinclude()&lt;/code&gt; in your template (in the body) with the filename you want to
include. You could do this and the figure macro with the latex processor, but I
prefer to use m4.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;\documentclass[12pt]{article}

\usepackage{fancyhdr}
\usepackage[usenames,dvipsnames]{color}
\usepackage{graphicx}
\usepackage{listings}

\usepackage[pdftex,
        pdfauthor={AUTHOR_NAME},
        pdftitle={REPORT_NAME}]{hyperref}

\topmargin=-0.4in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.0in
\textheight=9.0in
\headsep=0.25in
\setlength{\parindent}{1cm}
\linespread{1.1}

% header / footer
\lhead{}
\chead{REPORT_NAME}
\rhead{}
\lfoot{AUTHOR_NAME}
\cfoot{}
\rfoot{Page \thepage}
\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}
\setlength\parindent{0pt}

\pagestyle{fancy}

\begin{document}
\maketitle

sinclude(`report.tex.in')

\end{document}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you have a nice looking pdf!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>File Formats</title>
    <link href="http://maxpow4h.com/posts/file-formats"/>
    <updated>2013-01-19T00:00:00-08:00</updated>
    <id>http://maxpow4h.com/posts/file-formats</id>
    <content type="html">&lt;p&gt;Choosing to use plain text file formats simplifies a lot of problems.
You can use pretty much any text editor.
You can sync via rsync, Dropbox, etc.
If you need revision control, you can use Git on the files.
Since they are just plain text, you can diff, merge, etc.&lt;/p&gt;

&lt;p&gt;Useful file formats:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Documents (.md)&lt;/li&gt;
&lt;li&gt;Typesetting (.latex)&lt;/li&gt;
&lt;li&gt;Spreadsheets / Data (.yaml / .json with Ruby / Haskell)&lt;/li&gt;
&lt;li&gt;Presentations (.md with &lt;a href=&quot;https://github.com/schacon/showoff&quot;&gt;Showoff&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;If you choose to use Markdown, there are plenty of tools to export to
formats such as LaTeX or HTML, however, it is trivial to define your
own format, like my &lt;a href=&quot;https://gist.github.com/3158772&quot;&gt;Creole export&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For Spreadsheets I have a library called &lt;a href=&quot;https://gist.github.com/4576367&quot;&gt;Sheet.hs&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>DegreeSolver.hs</title>
    <link href="http://maxpow4h.com/posts/degree-solver"/>
    <updated>2012-12-13T00:00:00-08:00</updated>
    <id>http://maxpow4h.com/posts/degree-solver</id>
    <content type="html">&lt;p&gt;&lt;a href=&quot;https://gist.github.com/4268490/download&quot;&gt;Download DegreeSolver.hs&lt;/a&gt; &amp;bull; &lt;a href=&quot;https://gist.github.com/4268490/&quot;&gt;GitHub Source&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today I wrote a program to solve which parts of your degree have not yet
been completed. It's a beefed up replacement to an old spreadsheet I have
been using for years.&lt;/p&gt;

&lt;p&gt;Since everyone is special, I recommend you read your
program outline and create an appropriate file for yourself.&lt;/p&gt;

&lt;p&gt;Firstly, get the program off GitHub. It's written in Haskell
so you're going to need to install ghc or ask me for a binary.&lt;/p&gt;

&lt;p&gt;To run it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ runhaskell DegreeSolver.hs program.data completed.data
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;program.data&lt;/h2&gt;

&lt;p&gt;This defines a program. A program is made of requirements. For
example, a program that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;must completed COMP0001&lt;/li&gt;
&lt;li&gt;any 12 units of electives&lt;/li&gt;
&lt;li&gt;either MATH101 or MATH102&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Can be defined as:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[Req 6 &quot;COMP101&quot;, Either 6 &quot;MATH101&quot; &quot;MATH102&quot;, Any 12 &quot;ELECTIVE&quot;]
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;completed.data&lt;/h2&gt;

&lt;p&gt;This defines the courses completed so far.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;C is for Core courses (Req or Either)&lt;/li&gt;
&lt;li&gt;X is for Elective courses (Any)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;To say you have done MATH102 and 6 units of electives use:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[C &quot;MATH102&quot;, X &quot;FUN101&quot; &quot;ELECTIVE&quot;]
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Output&lt;/h2&gt;

&lt;p&gt;The program will tell you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which courses you haven't completed&lt;/li&gt;
&lt;li&gt;How many of each elective you have left&lt;/li&gt;
&lt;li&gt;If you have done a course that doesn't count&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Incomplete Core Courses:
[Req 6 &quot;COMP101&quot;]

Units Remaining in Electives:
ELECTIVE:   6

Completed Courses:
(C &quot;MATH102&quot;,Just (Either 6 &quot;MATH101&quot; &quot;MATH102&quot;))
(X &quot;FUN101&quot; &quot;ELECTIVE&quot;,Just (Any 12 &quot;ELECTIVE&quot;))
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What this doesn't do: Program changes, exceptions, waivers, etc.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>ditch</title>
    <link href="http://maxpow4h.com/posts/ditch"/>
    <updated>2012-09-30T15:04:00-07:00</updated>
    <id>http://maxpow4h.com/posts/ditch</id>
    <content type="html">&lt;p&gt;Evernote updated Skitch a couple of days ago and removed
WebDAV. They were nice enough to provide a download
of the old version from &lt;a href=&quot;http://evernote.com/skitch/&quot;&gt;their site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I made a Ruby web app you can run for free on Heroku. Just
plug in a Dropbox API key, and you can point Skitch's WebDAV at
it and it will store the images into your dropbox!&lt;/p&gt;

&lt;p&gt;It uses the Dropbox App Folders, so when you give it permission to
use your Dropbox, it can only see and use the &lt;code&gt;/Apps/ditch&lt;/code&gt; directory.
More apps should do that!&lt;/p&gt;

&lt;p&gt;There is a problem with Skitch's WebDAV and the clipboard. It verifies the URL exists after
uploading. Unfortunately this means you can't return Dropbox link since
it is just a hash / number. Also if you return a header location redirect,
it will not accept it. So instead it copies to the clipboard a link to a
page that redirects the user to the right Dropbox url.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Event-B Conversion</title>
    <link href="http://maxpow4h.com/posts/eventb"/>
    <updated>2012-08-12T14:18:00-07:00</updated>
    <id>http://maxpow4h.com/posts/eventb</id>
    <content type="html">&lt;p&gt;To show how to do conversion from Event-B to code,
I have made a simple machine to show how
every part of Event-B is converted.
For the example I have made a Microblogging
service.&lt;/p&gt;

&lt;h2&gt;Event-B Component&lt;/h2&gt;

&lt;h3&gt;User Machine&lt;/h3&gt;

&lt;p&gt;For the Event-B model we first make a User machine.&lt;/p&gt;

&lt;p&gt;For the invariants;
We make a variable called &lt;code&gt;users&lt;/code&gt; and give it the invariants:
&lt;code&gt;users ⊆ USERS&lt;/code&gt;. &lt;code&gt;USERS&lt;/code&gt; is defined in a Users context as a SET.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;users&lt;/code&gt; is a subset of &lt;code&gt;USERS&lt;/code&gt;. It contains all the
currently registered users of the system.&lt;/p&gt;

&lt;p&gt;Next we make an event.
&lt;code&gt;create_user&lt;/code&gt; takes any &lt;code&gt;USERS&lt;/code&gt; who is not yet in &lt;code&gt;users&lt;/code&gt; and adds them to &lt;code&gt;users&lt;/code&gt;.
The 2 guards are the user is in &lt;code&gt;USERS&lt;/code&gt; and the user isn't yet in &lt;code&gt;users&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Status&lt;/h3&gt;

&lt;p&gt;Next we refine in the Status machine.
We add a new variable called &lt;code&gt;statuses&lt;/code&gt; to represent all the status
updates made by users.
We make a context called Statuses that defines the set &lt;code&gt;STATUSES&lt;/code&gt;.
&lt;code&gt;statuses&lt;/code&gt; will have an invariant that enforces all statuses
are in &lt;code&gt;STATUSES&lt;/code&gt; such as &lt;code&gt;statuses ⊆ STATUSES&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also we need to map a &lt;code&gt;status&lt;/code&gt; to a &lt;code&gt;user&lt;/code&gt;, so we make a mapping
called &lt;code&gt;owners&lt;/code&gt; with the invariant &lt;code&gt;owners ∈ statuses → users&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now we can make an event called &lt;code&gt;post_status&lt;/code&gt;.
If we make it like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;post_status:
        ANY
            status
        WHERE
            grd1:   status ∈ STATUSES not theorem
            grd2:   status ∉ statuses not theorem
        THEN
            act1:   statuses ≔ {status} ∪ statuses
        END
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We get a failed proof obligation that &lt;code&gt;owners ∈ statuses → users&lt;/code&gt;
doesn't hold! Which is correct.
So we need to add the action for owners.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;post_status:
            ANY
                status
                user
            WHERE
                grd1:   status ∈ STATUSES not theorem
                grd2:   status ∉ statuses not theorem
                grd3:   user ∈ users not theorem
            THEN
                act1:   statuses ≔ {status} ∪ statuses
                act2:   owners(status) ≔ user
            END
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we can be sure that all status updates will have an owner.&lt;/p&gt;

&lt;h2&gt;Conversion&lt;/h2&gt;

&lt;h3&gt;User&lt;/h3&gt;

&lt;p&gt;If we did have an event like delete_user that required a &lt;code&gt;user ∈ users&lt;/code&gt;
then it would be an instance method.&lt;/p&gt;

&lt;p&gt;First we take the invariants and map them to validations. User only has
one, &lt;code&gt;users ⊆ USERS&lt;/code&gt;. This becomes an ID to uniquely identify a user.&lt;/p&gt;

&lt;p&gt;Next we implement &lt;code&gt;create_user&lt;/code&gt;.
Since &lt;code&gt;create_user&lt;/code&gt; doesn't have &lt;code&gt;user ∈ users&lt;/code&gt;, this is a class method.
An instance method requires &lt;code&gt;user ∈ users&lt;/code&gt;, since &lt;code&gt;user&lt;/code&gt; will then be bound
to &lt;code&gt;self&lt;/code&gt; or &lt;code&gt;this&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It does take an id, but we are going to assign ids ourself, so
&lt;code&gt;create_user&lt;/code&gt; just becomes the Active Record Pattern's &lt;code&gt;.create&lt;/code&gt;
class method.&lt;/p&gt;

&lt;p&gt;The id must be present to exist, so we insert a presence validation.
Also the id is used to identify a unique instance,
so it also requires a uniqueness validation.
However, most implementations of the Active Record Pattern do
ids like this automatically, so a correct implementation of user
could be:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class User &amp;lt; ActiveRecord::Base
  # ids are done by the super class
end
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Status&lt;/h3&gt;

&lt;p&gt;Each refinement is a new model, so here we create a new model for Status.
It too has an ID, &lt;code&gt;statuses ⊆ STATUSES&lt;/code&gt;. However, it has one extra invariant.
Since each invariant maps to a validation, we must map this invariant too.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;owners ∈ statuses → users
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This means, given a status, you can determine the owner of it.
This means we have a &lt;code&gt;belongs_to&lt;/code&gt; relation. To match this,
the User model needs a &lt;code&gt;has_many :statuses&lt;/code&gt; relation as well.&lt;/p&gt;

&lt;p&gt;Also since it is a total function, we must validate the user_id is present.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Status &amp;lt; ActiveRecord::Base
  belongs_to :user

  validates :user_id, :presence =&amp;gt; true
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We could change the name from user_id to owner_id if we wanted to match
the Event-B model's name for this function.&lt;/p&gt;

&lt;p&gt;Looking at the guards for &lt;code&gt;post_status&lt;/code&gt; this could be a
class method in Status. This is exactly what it is by default.
However, we should notice the &lt;code&gt;user ∈ users&lt;/code&gt; guard. This means
we could instead make &lt;code&gt;post_status&lt;/code&gt; an instance method
on a &lt;code&gt;User&lt;/code&gt;! Then &lt;code&gt;self&lt;/code&gt; would be bound to the user making
the post and the only argument would be the status to post.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Each refinement becomes a Model&lt;/li&gt;
&lt;li&gt;Each variable in the refinement becomes a member variable&lt;/li&gt;
&lt;li&gt;Each invariant became a Model Validation&lt;/li&gt;
&lt;li&gt;Each event becomes a method&lt;/li&gt;
&lt;li&gt;The machine states become state machines inside the Model&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;You can &lt;a href=&quot;/images/code/microbloggingeventb.zip&quot;&gt;download the Event-B Model&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Note on Authorisation&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;An Event-B model represents an
 &lt;a href=&quot;http://en.wikipedia.org/wiki/Active_record_pattern&quot;&gt;Active Record Pattern&lt;/a&gt;
 system. In MVC this is the Models.&lt;/li&gt;
&lt;li&gt;Authorisation in MVC is part of the controller.&lt;/li&gt;
&lt;li&gt;Therefore you can not model with Event-B authorisation since it is
 outside what Event-B can represent.&lt;/li&gt;
&lt;/ol&gt;

</content>
  </entry>
  
  <entry>
    <title>Raspberry Pi + Ruby</title>
    <link href="http://maxpow4h.com/posts/raspberry-pi"/>
    <updated>2012-08-06T22:41:00-07:00</updated>
    <id>http://maxpow4h.com/posts/raspberry-pi</id>
    <content type="html">&lt;p&gt;Today I got a Raspberry Pi.
I currently run a laptop that has a couple of ruby apps.
I wanted to move these apps to something
less power intensive and hot.&lt;/p&gt;

&lt;p&gt;Before I could use it, I needed 2 things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;SD Card 8GB ($16)&lt;/li&gt;
&lt;li&gt;Micro USB Charger ($20) (1000mA) from a phone shop&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Add the postage of it, and it bumps the price from $35 to $80 computer.&lt;/p&gt;

&lt;p&gt;First &lt;a href=&quot;http://www.raspberrypi.org/downloads&quot;&gt;download the debian image&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For imaging the SD card, &lt;a href=&quot;http://elinux.org/RPi_Easy_SD_Card_Setup&quot;&gt;check out this guide&lt;/a&gt;.
For Mac, &lt;code&gt;df -h&lt;/code&gt; to list drives, &lt;code&gt;sudo diskutil unmount /dev/diskXsN&lt;/code&gt; to unmount
and &lt;code&gt;sudo dd bs=1m if=something.img of=/dev/rdiskX&lt;/code&gt;, eject with &lt;code&gt;sudo diskutil eject /dev/diskX&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once you start it up the first time, run &lt;code&gt;sudo raspi-config&lt;/code&gt; and
resize partition to fill SD card. Then restart it.
Also remember to &lt;code&gt;sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To make SSH-ing in easier I made the following &lt;code&gt;~/.ssh/config&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Host pi
  HostName pi.maxpow4h.com
  User pi
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then I ran &lt;code&gt;ssh-copy-id pi&lt;/code&gt;, so I can just use &lt;code&gt;ssh pi&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now if we want to do anything of interesting we need some stuff:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo apt-get install git curl zlib1g-dev # for RVM
sudo apt-get install openssl libreadline6-dev git-core zlib1g libssl-dev # for ruby's ssl
sudo apt-get install libyaml-dev libsqlite3-dev sqlite3 # for ruby's yaml and sqlite3
sudo apt-get install libxml2-dev libxslt-dev # for nokogiri
sudo dpkg-reconfigure tzdata # set your time zone
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;RVM time! &lt;code&gt;curl -L https://get.rvm.io | bash -s stable --ruby&lt;/code&gt;.
Compiling ruby takes a long time...&lt;/p&gt;

&lt;p&gt;Now we can run our apps!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mkdir app_name
cd app_name
git init
git config receive.denyCurrentBranch ignore

vi .git/hooks/post-receive
# insert the following into the post-receive hook
# cd ..
# GIT_DIR='.git'
# git checkout -f

chmod +x .git/hooks/post-receive
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now on your computer lets add the remote:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git remote add raspberry pi@192.168.0.123:app_name/.git
git push -u raspberry master
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now it will keep the working dir up to date when you push.&lt;/p&gt;

&lt;p&gt;Back on the server. If you are running a service and you want it
to be monitored, the easiest way is to add a Procfile with the commands
to run and use bluepill to monitor it.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;bundle install

# Now for the Procfile
gem install bluepill foreman

foreman export bluepill . -u pi

rvmsudo bluepill load app.pill
rvmsudo bluepill status
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can checkin on how everything is going with &lt;code&gt;rvmsudo bluepill status&lt;/code&gt;.
Check the logs with &lt;code&gt;rvmsudo bluepill log &amp;lt;process_or_group_name&amp;gt;&lt;/code&gt;.
Start / stop with &lt;code&gt;rvmsudo bluepill &amp;lt;start|stop|restart|unmonitor&amp;gt; &amp;lt;process_or_group_name&amp;gt;&lt;/code&gt;.
Also you probably want to add &lt;code&gt;rvmsudo bluepill restart app&lt;/code&gt; to the &lt;code&gt;post-receive&lt;/code&gt; hook
so the app is restarted each push.&lt;/p&gt;

&lt;p&gt;From here, you probably want to install transmission and enable
the web interface. Then install nginx and reverse proxy your web app.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;location / {
  proxy_pass        http://localhost:9292;
  proxy_set_header  X-Real-IP  $remote_addr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;An alternative to this is using the ruby Puma gem for the web server.
I've found it works well with video streaming.&lt;/p&gt;

&lt;p&gt;Also check out &lt;a href=&quot;https://github.com/elcuervo/airplay&quot;&gt;elcuervo/airplay&lt;/a&gt;
for streaming to AppleTV.&lt;/p&gt;

&lt;p&gt;Also you might want to proxy and rewrite transmission something like this.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;location = /transmission {
   rewrite /transmission/(.*) /$1 break;
   proxy_set_header   Host        $http_host;
   proxy_set_header   X-Real-IP   $remote_addr;
   proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
   proxy_pass         http://127.0.0.1:9091/transmission/web/;
   proxy_redirect     off;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Also &lt;a href=&quot;http://www.adafruit.com/products/859&quot;&gt;adafruit make a really neat case&lt;/a&gt;. It is worth checking out.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>md2cre.rb</title>
    <link href="http://maxpow4h.com/posts/md2cre"/>
    <updated>2012-07-22T17:21:00-07:00</updated>
    <id>http://maxpow4h.com/posts/md2cre</id>
    <content type="html">&lt;p&gt;I write everything in Markdown, but a piece of software
I have to use requires Creole. So, I made this script
that converts Markdown to Creole.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Event-B and You</title>
    <link href="http://maxpow4h.com/posts/eventb-and-you"/>
    <updated>2012-07-16T00:01:00-07:00</updated>
    <id>http://maxpow4h.com/posts/eventb-and-you</id>
    <content type="html">&lt;p&gt;Translating Event-B (or any state based modelling language) to an
implementation can be tricky. Here is the process I used to do it.
The first step is to identify what you are implementing in.
This is the &lt;strong&gt;Active Record Pattern&lt;/strong&gt;. It exists in many different
programming paradigms, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Callbacks: Event-Driven Programming&lt;/li&gt;
&lt;li&gt;MVC: Object Orientated Programming&lt;/li&gt;
&lt;li&gt;Monads: Functional Programming&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;The Process&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &quot;Model&quot; refers to the Active Record Pattern idea of a model,
not the Event-B model.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each refinement because a Model.&lt;/li&gt;
&lt;li&gt;Each variable in the refinement because a member variable.&lt;/li&gt;
&lt;li&gt;Each invariant became a Model Validation.&lt;/li&gt;
&lt;li&gt;Each event becomes a method.&lt;/li&gt;
&lt;li&gt;The machine states become state machines inside the Model.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Then, no data could be modified unless all the
invariants you specified in Event-B held true for your Models.&lt;/p&gt;

&lt;p&gt;The next / most important part of the Event-B Model, are state machines.
This requires you to define states (which is an enumeration).
Then each invariant on those states you specify as state transitions
with guards (in your model). Then you can define methods to require certain states.
This then results in events been protected by the state of the machine,
and only certain state transitions been allowed.&lt;/p&gt;

&lt;p&gt;This process will map your complete Event-B model into any
language's Active Record Model. Then on top of that
you can use any design pattern like MVC, Model2, etc.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Guardfile</title>
    <link href="http://maxpow4h.com/posts/guardfile"/>
    <updated>2012-04-28T21:54:00-07:00</updated>
    <id>http://maxpow4h.com/posts/guardfile</id>
    <content type="html">&lt;p&gt;&lt;strong&gt;Guard&lt;/strong&gt; is a gem that lets you setup things to happen
when stuff is changed. I use it for previewing a PDF
while I write LaTeX.&lt;/p&gt;

&lt;p&gt;To set it up, install the gems &lt;code&gt;guard&lt;/code&gt; and &lt;code&gt;guard-shell&lt;/code&gt;.
Then make a &lt;code&gt;Guardfile&lt;/code&gt; with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;guard :shell, :all_on_start =&amp;gt; true do
  watch /cv.tex/ do |m|
    3.times {system &quot;pdflatex cv.tex&quot;}
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or something more fancy&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;guard :shell, :all_on_start =&amp;gt; true do
  watch /^([^\/]*)\.tex/ do |m|
    3.times {system &quot;pdflatex -shell-escape #{m[0]}&quot;}
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now run &lt;code&gt;guard&lt;/code&gt;! Open &lt;code&gt;cv.pdf&lt;/code&gt; in your pdf viewer and
now every time you change cv.tex,
the pdf will be regenerated automagically!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Graphviz Positioning</title>
    <link href="http://maxpow4h.com/posts/graphviz-positioning"/>
    <updated>2012-03-29T17:02:00-07:00</updated>
    <id>http://maxpow4h.com/posts/graphviz-positioning</id>
    <content type="html">&lt;p&gt;Positioning elements in Graphviz is a little bit tricky sometimes.
Here is how I do it.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;digraph finite_state_machine {
  # Settings
  rankdir=LR;
  size=8

  ## Nodes
  node [shape = doublecircle] waiting_for_input finished;
  node [shape = circle] find_path_back check_found;

  # Lines
  waiting_for_input -&amp;gt; find_neighbours [  label=&quot;user input&quot;];
  find_neighbours -&amp;gt; check_found [label=&quot;goal not found&quot;];
  check_found -&amp;gt; find_neighbours [label=&quot;not found&quot;];
  check_found -&amp;gt; find_path_back [label=&quot;goal found&quot;];
  find_path_back -&amp;gt; finished [label=&quot;display result&quot;];

  # Layout
  { rank=same; waiting_for_input waiting_for_input }
  { rank=same; find_path_back check_found}

}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then to generate it use&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;dot -Tpdf diagram.gz &amp;gt; diagram.pdf 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you don't use &lt;code&gt;dot&lt;/code&gt; it &lt;em&gt;may&lt;/em&gt; ignore your positioning. E.g. the Graphviz GUI, neato, etc.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>OS161 on Homebrew</title>
    <link href="http://maxpow4h.com/posts/os161-on-homebrew"/>
    <updated>2012-03-01T16:06:00-08:00</updated>
    <id>http://maxpow4h.com/posts/os161-on-homebrew</id>
    <content type="html">&lt;p&gt;I built OS161 for Homebrew. If you need it too, run:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;brew tap maxpow4h/os161
brew install sys161
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The repo is available on &lt;a href=&quot;https://github.com/maxpow4h/homebrew-os161&quot;&gt;maxpow4h/os161&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>TextMate 2 Properties</title>
    <link href="http://maxpow4h.com/posts/tm-properties"/>
    <updated>2012-02-21T16:28:00-08:00</updated>
    <id>http://maxpow4h.com/posts/tm-properties</id>
    <content type="html">&lt;p&gt;The TextMate 2 &lt;code&gt;.tm_properties&lt;/code&gt; global file I use:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;tabSize = 2
softTabs = true
softWrap = true

[ Makefile ]
softTabs = false
tabSize = 4
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;excludeDirectories&lt;/code&gt; doesn't remove the results from finding. So I use
&lt;code&gt;exclude&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;For Jekyll projects:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;exclude = &quot;{_deploy,public,source/stylesheets}&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For Ruby projects:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;exclude = &quot;{tmp,log}&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For C things:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;excludeFiles   = &quot;*.{so,o}&quot;
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  
  <entry>
    <title>K17 iOS App</title>
    <link href="http://maxpow4h.com/posts/k17-ios-app"/>
    <updated>2012-02-04T21:14:00-08:00</updated>
    <id>http://maxpow4h.com/posts/k17-ios-app</id>
    <content type="html">&lt;p&gt;This app is something I have wanted to make since first year.
The &lt;a href=&quot;https://github.com/maxpow4h/cse_pp&quot;&gt;cse_pp&lt;/a&gt; script provides
an API for the iOS app to search for information with.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>insta-importo.rb</title>
    <link href="http://maxpow4h.com/posts/insta-importo-dot-rb"/>
    <updated>2012-01-26T23:45:00-08:00</updated>
    <id>http://maxpow4h.com/posts/insta-importo-dot-rb</id>
    <content type="html">&lt;p&gt;I wrote a script to import the articles from
&lt;a href=&quot;http://thedailywtf.com/&quot;&gt;The Daily WTF&lt;/a&gt; that I haven't read yet into
&lt;a href=&quot;http://www.instapaper.com/&quot;&gt;Instapaper&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is also handy for other blogs.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Git at University</title>
    <link href="http://maxpow4h.com/posts/git-at-university"/>
    <updated>2011-12-20T00:00:00-08:00</updated>
    <id>http://maxpow4h.com/posts/git-at-university</id>
    <content type="html">&lt;h2&gt;Remote&lt;/h2&gt;

&lt;p&gt;If you want to use a server's plain old filesystem
to host your git repo, like at university, it's pretty
straight forward.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# on the server
mkdir ~/ass1; cd ~/ass1
git init
git config receive.denycurrentbranch ignore

# on your computer in the git repo
git remote add cse USERNAME@cse.unsw.edu.au:ass1/.git
git push -u cse master
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Hooks&lt;/h2&gt;

&lt;p&gt;One useful thing about using Git Hooks is you can submit your assignment
and see the result of the dry run, just by using &lt;code&gt;git push&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To set this up on the server go to the repo and
create a &lt;code&gt;.git/hooks/post-receive&lt;/code&gt; file. This is the script that gets
executed after a push. It should contain:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/bin/bash

# This checks out the push into the working dir
GIT_WORK_TREE=`pwd`/.. git checkout -f
echo &quot;Giving...&quot;
pushd ..

# put your give here...
# give cs1234 ass1 file.c 

popd
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then run &lt;code&gt;chmox +x hooks/post-receive&lt;/code&gt; to make it executable.
Now every time you push it will update the working tree.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This is very sensitive to git versions. git version 1.7.x.x where x differs may not be compatible. For Ubuntu add the ppa for the latest version.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Also Note&lt;/strong&gt;: You can't use #!/bin/sh if you expect pushd to work.&lt;/p&gt;

&lt;h2&gt;SVN&lt;/h2&gt;

&lt;p&gt;Some courses use SVN, to fix that:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git svn clone svn+ssh://maxs@cse.unsw.edu.au/home/maxs/cs3231/repo
# work normally in git
# make commits, etc.
# then when you want to commit to svn, do
git svn fetch # you don't want to do a merge in svn...
git svn dcommit
# Also on the server, you need to go 'up' a few levels of commits
# so use `svn up -r1234`
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  
  <entry>
    <title>Ruby Without Bundler In Production</title>
    <link href="http://maxpow4h.com/posts/ruby-without-bundler"/>
    <updated>2011-12-16T13:15:00-08:00</updated>
    <id>http://maxpow4h.com/posts/ruby-without-bundler</id>
    <content type="html">&lt;p&gt;Sometimes Bundler isn't available in the environment you want to run a
ruby app on. &lt;em&gt;Oh noes&lt;/em&gt;. This is how I get around that problem.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download the .gem files to my local machine&lt;/li&gt;
&lt;li&gt;Deploy to production&lt;/li&gt;
&lt;li&gt;Install gems&lt;/li&gt;
&lt;li&gt;When starting, set the &lt;code&gt;GEM_HOME&lt;/code&gt; and &lt;code&gt;GEM_PATH&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Here are the Rake tasks I use:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1484208.js&quot;&gt;&lt;/script&gt;

</content>
  </entry>
  
  <entry>
    <title>Graphviz Class Diagram</title>
    <link href="http://maxpow4h.com/posts/graphviz-class-diagram"/>
    <updated>2011-09-21T00:00:00-07:00</updated>
    <id>http://maxpow4h.com/posts/graphviz-class-diagram</id>
    <content type="html">&lt;p&gt;An example of a class diagram in Graphviz.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>LaTeX Template Tools for SENG</title>
    <link href="http://maxpow4h.com/posts/latex-template-tools-for-seng"/>
    <updated>2011-08-24T00:00:00-07:00</updated>
    <id>http://maxpow4h.com/posts/latex-template-tools-for-seng</id>
    <content type="html">&lt;p&gt;The tools my group used last year for SENG.
Used for templating requirements into LaTeX tables.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Email Stats</title>
    <link href="http://maxpow4h.com/posts/email-stats"/>
    <updated>2011-07-17T00:00:00-07:00</updated>
    <id>http://maxpow4h.com/posts/email-stats</id>
    <content type="html">&lt;p&gt;A small ruby script that downloads your IMAP email headers into a local database. You can then query it for statistics, such as ranking where most your emails come from.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Task Warrior .taskrc</title>
    <link href="http://maxpow4h.com/posts/task-warrior-taskrc"/>
    <updated>2011-07-11T00:00:00-07:00</updated>
    <id>http://maxpow4h.com/posts/task-warrior-taskrc</id>
    <content type="html">&lt;p&gt;Task Warrior is great. Here are 2 things I added to my .taskrc to make it better.&lt;/p&gt;

&lt;h2&gt;Backup&lt;/h2&gt;

&lt;p&gt;Have task warrior use a folder inside Dropbox. Now its backed up!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Files
data.location=/Users/maxs/Dropbox/Documents/task
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Date Format&lt;/h2&gt;

&lt;p&gt;Set it to use Australian date formats.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;dateformat=d/m/y
dateformat.report=d/m/y
dateformat.annotation=d/m/y
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  
  <entry>
    <title>OS X Failed Backup Alert</title>
    <link href="http://maxpow4h.com/posts/os-x-failed-backup-alert"/>
    <updated>2011-07-10T00:00:00-07:00</updated>
    <id>http://maxpow4h.com/posts/os-x-failed-backup-alert</id>
    <content type="html">&lt;p&gt;A script to email you when a Time Machine backup has failed in the last 48 hours.
You need to fill in the email destination and smtp settings.
Works with system ruby, just install the &lt;code&gt;pony&lt;/code&gt; gem.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>A DVD of Prime Numbers</title>
    <link href="http://maxpow4h.com/posts/a-dvd-of-prime-numbers"/>
    <updated>2011-06-29T00:00:00-07:00</updated>
    <id>http://maxpow4h.com/posts/a-dvd-of-prime-numbers</id>
    <content type="html">&lt;p&gt;My friend once downloaded a DVD of prime numbers. He wanted to match them up to other things. At the time, Internet was slow and a DVD took a while to download. I thought, &quot;It must be quicker to just generate them than download them&quot;. However, I had no idea how to do it at the time. Now I do, and it turns out, yes, it is quicker.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>bookmarks.rb</title>
    <link href="http://maxpow4h.com/posts/bookmarks-dot-rb"/>
    <updated>2011-06-28T00:00:00-07:00</updated>
    <id>http://maxpow4h.com/posts/bookmarks-dot-rb</id>
    <content type="html">&lt;p&gt;A simple script I made that tells you where most of your bookmarks in Chrome are from and if you have duplicates. You need to export your bookmarks from Chrome to use it.&lt;/p&gt;
</content>
  </entry>
  
</feed>
