Archives

Tags

Introducing Bolverk: 8-bit Microprocessor Emulator

Over the past few weeks, I have been developing a fun little application in an attempt to broaden my knowledge of the way a processor works at a low level.

What I've come up with is a Web-based, 8-bit Microprocessor Emulator with it's own Machine Language implementation. It contains 2kb of memory and is programmable in Hexadecimal.

I developed the "engine" first and then wrote a simple Web-wrapper for it using the Sinatra framework. Check it out here: http://bolverk.andrewbuntine.com. Or fork me on github!

I tried to keep the process enjoyable and did not worry myself too much with the finicky details that would undoubtedly plague engineers implementing a "real" machine. I questioned myself so many times that, after a while, I began to simply ignore my inner, logical self and simply kept hacking away. So even though writing a program to perform 8-bit floating point arithmatic in a machine language implemented using an interpreted and dynamic language is, quite obviously, far beyond ridiculous, I still reached my goal of... well, I don't know... total schizophrenia?

The true usefulness of such an application lies in it's effectiveness as an educational tool. Recently, I was watching some of the excellent Richard Buckland lectures from the UNSW Comp. Sci. course and I noticed that they were actually using something quite similar. The emulator they were using was only 4-bit and contained just 16 bytes of memory, but the concept was almost identical. What a confidence boost!!

Any feedback, bug reports, comments -- please send me an email!

My first Merb site

Just a quick note to my legions of loyal followers (hey, Mum), I've just finished my first website written using the Merb framework.

S'coolhouse Rock and Swing

Development travelled along relatively well. I ran into a few issues early on with dependency hell and some bugs and/or missing functionality in a few gems. I blogged about a few of my hacks.

Here is my (partial) technology stack:

  • ORM: DataMapper
  • Tests: RSpec
  • Views: HAML/SASS (which I won't be using again, even though it's very well written)
  • Hosting: Dreamhost (using Phusion Passenger, which was easy to use with a config.ru file for Rack)

I still haven't worked out how to properly get Capistrano working with the Dreamhost setup, but shit happens...

Auf wiedersehen!

Bash shells, curly braces, substitutions, attack!

Here is something I do all the time:

$ cp a-file-that-is-badass a-file-that-is-badass.old
...
$ cp a-file-that-is-badass.old a-file-that-is-badass

But, considering I'm a wannabe hacker, I knew there was going to be a much faster way of achieving the same thing. Enter the curly brace of doom!

Let me slip on my hack suit and try that again:

$ cp a-file-that-is-badass{,-old}
$ cp a-file-that-is-badass{-old,}

Here, we are utilising a feature in bash called brace expansion. Basically, it is telling the shell to prepend the contents of the command to the left of the first brace to each string inside the comma-delimited list within the braces. Anything remaining to the right of the braces is appending to each expanded string.

Brace expansion can take place anywhere inside your command. You can even nest them!

Another example (in the case of a collegue with horrible spelling):

$ mv lib/complex/{fisicks,physics}.py

The possibilities are endless...

REST-mapping anchor elements in Merb

One of the things I liked about the REST implementation in Rails was the ability to use an anchor to fire off a HTTP "PUT" or "DELETE" request (or, rather the illusion of such) using the link_to helper method. It basically generates a chunk of inline JavaScript in the anchors onclick event that constructs a POST form, adds a few hidden elements, and finally submits it.

I noticed the functionality was not implemented in Merb. This is not totally surprising to me. I mean, inline JavaScript is never pretty. It also means we are relying on Javascript for the link to work correctly.

Regardless of my initial inhibitions, I decided to implement the functionality into a Merb application I was working on. The main chunk came down to this mixin to Merb::AssetsMixin:

module Merb
  module AssetsMixin

    alias_method :orig_link_to, :link_to

    def link_to(name, url='', opts={})
      if opts.include?(:method)
        method = opts.delete(:method)

        if [ :put, :delete ].include? method
          opts[:onclick] = "var f = document.createElement('form'); f.style.display = 'none'; " +
                           "this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href; " +
                           "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); " +
                           "m.setAttribute('name', '_method'); m.setAttribute('value', '#{method}'); " +
                           "f.appendChild(m);f.submit(); return false;"
        else
          raise ArgumentError, "The :method option only accepts :put or :delete."
        end
      end

      orig_link_to name, url, opts
    end

  end
end

It mimicks Rails behaviour. Therefore, I call it like this:

link_to "Delete", url(:post, 1), :method => :delete
# OR
link_to "Save changes", url(:post, 1), :method => :put

I also wrote a bunch of specs and threw it up on GitHub. Eventually, I plan to set it (and the rest of my hacks) up as proper Merb plugins. If anyone wants to give me a hand, feel free to fork the project(s) and do your thing...

Multiple before/after model filters with Merb

This evening I found myself in a position in which I wanted to execute several "before" methods hooks/filters on a DataMapper model in a Merb application. I had a look around in the source and API docs, but couldn't really find a nice way of doing it (even though having every hook on a seperate line is not such a bad thing in terms of readability, I suppose).

Anyway, I came up with the following mixin for Extlib (which houses DataMapper's before/after hook functionality):

module Extlib
  module Hook
    module ClassMethods

      alias_method :singular_before, :before
      alias_method :singular_after, :after

      def before(target_methods, filter_methods = nil, &block)
        insert_multiple_hooks "before", target_methods, filter_methods, &block
      end

      def after(target_methods, filter_methods = nil, &block)
        insert_multiple_hooks "after", target_methods, filter_methods, &block
      end

      private

      def insert_multiple_hooks(context, target_methods, filter_methods, &block)
        targets = [target_methods].flatten
        filters = [filter_methods].flatten

        targets.each do |target|
          filters.each do |filter|
            send("singular_#{context}", target.to_sym, filter.to_sym, &block)
          end
        end
      end

    end
  end
end

Hopefully it is fairly straight-forward. Basically, it will allow you to pass an array to the before and after methods. For example, you can do this:

before [ :create, :update ], [ :set_filename, :set_filesize, :generate_thumbnail ]

Which is equivalent to:

before :create, :set_filename
before :create, :set_filesize
before :create, :generate_thumbnail
before :update, :set_filename
before :update, :set_filesize
before :update, :generate_thumbnail

I got it loaded into my Merb app by creating an app/lib directory and requireing the contents of it from the config/init.rb file.

Witchhammer 1.3, available now!

After I released Witchhammer 1.0, my bandwidth usage went up 3,000%. My logs are telling me that over 500 people have already downloaded the extension!

In any case, I decided that I could make an enhancement or two. Namely:

  • Full support for both band and album/release searching
  • Better handling of AJAX requests (as metal-archives is often down or slow)

It still works in the same way as before, although there is now a submenu available that allows you to choose to search for either bands or albums. The results are aggregated and displayed efficiently (instead of simply redirecting you to a webpage).

You can download the extension at Firefox Addons and Softpedia (thanks to whoever submitted it there!).

Note, you will need Firefox 3.0 or above -- so make sure you upgrade if you need to.

Please let me know if you find any bugs or areas for improvement. Thanks!

An improved shell script for Svn resetting

A few weeks ago I posted a simple script for resetting an Svn repository to an earlier revision (and recording it as a new revision, so the reset is resettable!).

I decided it was totally shit, and so, I have simplified it a little bit:

  • You no longer have to pass in the URL for the central repository. The script will figure it out for you.
  • The working copy (second) argument is optional. It defaults to the current directory.

Anyway, here it is:

if [ $# = 0 ]
then
  echo "Resets an Svn working copy to an earlier revision."
  echo "svnreset <revision> [PATH...]"
else
  dir=$2
  : ${dir:="."}

  # Find repository URL using AWK.
  repo_url=`svn info $dir | awk '/^URL: (.+)$/ { print $2 }'`

  # Update working copy, merge into older revision, commit with message.
  svn update $dir
  svn merge -rHEAD:$1 $repo_url
  svn commit -m "Reverted back to r$1"
fi

exit 0

Call it like this (with an appropriate revision number): $ svnreset 1242

Witchhammer, a Firefox extension for metal warriors

NOTE: My latest version is available here: http://andrewbuntine.com/articles/2008/11/27/witchhammer-13-available-now

Record Collecting is a hobby of mine. Well, perhaps an obsession. Infact, I feel somewhat comfortable in claiming that I have the best collection of obscure Czechoslovakian Heavy Metal LPs in Australia!

One of the best general resources for confirming information about bands (or discovering new ones) is undoubtedly The Encyclopaedia Metallum (or simply "Metal Archives" to most of us). When browsing a tradelist, distro listing, EBay, etc I find myself continuously jumping to said website. So I thought:

Wouldn't it be cool if there was a Firefox Extension that allowed you to simply highlight a bands name (or keyword) on a webpage, right-click, select "Find at Metal Archives", and be presented with a nice listing of the results?! You could then select the results you wanted to see, and click "Ok". A new tab, linking to the bands profile, would be opened for each.

So this is exactly what I did. I decided to name the extension Witchhammer; a reference to the cult Czech band, Törr.

Witchhammer is currently in sandbox at the official Mozilla Add-Ons website, and should be available for download there soon. In the meantime, you can download it here: http://www.andrewbuntine.com/firefox/witchhammer.xpi

You will need Firefox 3.0 or above. I developed it on Linux, but have tested on Windows XP and found no problems. It also works fine on Mac OSX.

If you find any issues or areas for improvement, please feel free to email me!

Enjoy, thrashers!!

Freyja, available now!

My first Firefox extension, Freyja, is now available for download! See my first post for an introduction to the functionality and inspiration of this work.

Freyja is currently in an experimental state, and being my first attempt, may not be 100% stable on all operating systems (tested on Ubuntu 8.04, Fedora 8, Windows XP).

To use it properly, you will need Firefox 2.0 or above (FF3 is recommended), access to an SMTP server (Gmail is supported!) and the Python interpreter (comes bundled on most Linux distro's and Mac OS X).

MS Windows users -- the extension will work for you if you have Python installed on your machine.

Direct download: http://www.andrewbuntine.com/firefox/freyja.xpi

I would really appreciate it if someone could download it, test it out with their own email address(es), and let me know if you run into any problems. Any feedback at all is appreciated!

General usage is as follows:

  • Go to Tools > Freyja
  • Add a few URLs to the Websites list
  • Add one or more email addresses to the Email list
  • Go to Preferences and set your email information (example: Gmail password, email address, full name)
  • Browse to a disallowed URL (that you just set)
  • Look in the status bar for the "Sending email..." message!

Freyja: A firefox extension for porn addicts

A while ago I stumbled upon one of the weirdest/coolest/most original reasons for abandoning Linux I have seen in a long time. Check it out here: http://ubuntuforums.org/showthread.php?t=878991

Basically, the guy is heading back to Windows due to a massive addiction to pornography. He says there is not enough pornography-filtering software available for *nix systems.

Perhaps he is right? I'm not sure. But it sure is very original!

At one point in the post, he makes mention of an O/S tool that scans your browsing habits and threatens to email a person of your choosing. I thought to myself that such an idea is great for a Firefox Extension!

So I sat down and started hacking on an extension that works in the following way: The user (adictee) preconfigures the extension with a list of the websites he/she visits in order to "fill their need" and provides one or more appropriate email addresses (their mother, girlfriend/boyfriend, etc). From here, the extension silently pays attention to the users browsing and, in the occurence of the user browsing to a "disallowed" page, the supplied individuals are instantly emailed informing them of what their son/partner/whatever is up to!

I don't believe in censorship or content filtering, and so the pages will be completely available to the user, but the consequences could be dire (provided they use it with integrity!).

I have basically finished the extension and should have it packaged up and ready for download within the next day or so. I will give out more specific details (including full source code) at that time.

Also, I have decided to name it "Freyja"; a not-so-accidental reference to the Norse Goddess of Fertility.

Now there is no excuse, porn addicts all over the world can feel comfortable using free software!

Pages: 1 2 3 4