Showing posts with label free software. Show all posts
Showing posts with label free software. Show all posts

2008-07-02

Self-Documenting ruby t-shirt

For reasons I don't really understand myself, recently I've been messing about with the idea of code on t-shirts. Sure, it's not exactly a new idea, but I couldn't resist it. I started out with this Lisp t-shirt (mainly because I wanted one myself, the order is in and I'm looking forward to getting it) and then went on and did this one (which I'll probably end up buying at some point in the near future).

And then I got to thinking that it might be interesting to have a go at creating a t-shirt that was, in effect, self-documenting. The idea being that the design would contain code that would, as much as possible, be usable in creating the design. After thinking on this for a while I decided that a Mandelbrot set would be a good place to start.

Having already done some Lisp I thought it was time to do something with ruby. So, I sat down and knocked up a quick script that would plot a Mandelbrot set, emitting it as a PBM file, just to make life easier. I then converted that to a PNG. After that I loaded up Photoshop Elements, created an empty image sized correctly for a RedBubble t-shirt design, added in the Mandelbrot and then layered the ruby source code over the top. A tweak or two later and I had a finished design:


I'm rather pleased with the result.

That said, the idea still needs some more work. While the shirt contains the code to produce the background image it's not a fully self-documenting t-shirt in that running the code on the shirt won't produce the whole design. That's to say: you can't run the code and get a PNG that's ready to upload to RedBubble.

I think a bit of reading of the documentation for RMagick is in order.

2008-06-06

Some RedBubble Hacks

No website is perfect, that's probably even more true for the more "social" type sites where you tend to spend a lot of time working with them, and I've found that RedBubble is no exception.

A while back I took a look at Greasemonkey (something I'd been meaning to do for ages) as a method of fixing one little RedBubble niggle and, since then, I've "fixed" a few things that have bothered me.

Given that I've got a few RedBubble hacks kicking about now I thought it might be an idea to list them here:

RedBubble "Edit This" hack
This adds a much-needed "Edit this" link to a public view of a work. I often find that I'll notice a small problem with a work when I'm seeing it how everyone else sees it. Such a view doesn't have a way of taking you directly to the edit page for the work so this hack fixes that.

Better text formatting hints
RedBubble uses Textile as the markup language of the site and most people don't know it (I'd never seen it before I started using RedBubble). This little hack replaces the rather sparse help that is given on various edit pages with a more comprehensive cheat sheet.

Public view tab for mybubble
This little hack simply adds an extra tab to the mybubble pages that takes you to your public view. While such a link does exist in the mybubble pages this makes it more obvious.

Watch a forum thread in Google Reader
RedBubble's forums provide RSS feeds so you can keep track of what's going on. This hack adds a "Add to Google Reader" button to each thread so you can quickly and easily add them to Google Reader.

Watch comments for a work in Google Reader
Similar to the above but for the comments made on any work on RedBubble.

Move user actions further up a user's profile
Each user profile page on RedBubble has a couple of user actions: one to add/remove them from your watchlist and one to send them a BubbleMail. The problem is that, at the moment, these actions come below the written profile for the user. Lots of users have very long profiles, often with large image previews in them. Because of this you've got to scroll down quite a way to find those actions. This hack fixes that by moving the actions to before the user-written profile.

Simple BubbleMail preview
Another Textile thing. RedBubble's BubbleMail system (the internal messaging system for the site) has no preview facility. It's also pretty easy to mess up when working with Textile formatting. This hack provides a simple preview system that helps catch any silly errors before you hit the send button.

Extra paging for mybubble work lists
The lists of works in mybubble (your private view of your works) only have the page navigation links at the bottom of the lists. This means that you've generally got to scroll down the page to get to the next page. This hack fixes that problem by placing a clone of those links at the top of the list.

Average views per public work
Possibly the least useful of all the hacks. This one adds an extra bit of information to the view count stats you get in the work lists in mybubble: the average number of views per work.
Hopefully, as RedBubble develops, most of these hacks will become less useful. The ideal situation would be that such things are built into the RedBubble site itself. Until such a time...

2008-05-29

Rails, Simile Timeline and Pocket IE

Following on from earlier, I ran into another problem with my little test application but, thankfully, it ended up being easy to fix.

In the application I make use of Timeline. Including it in the application is simple enough. I just include this:

javascript_include_tag(
"http://simile.mit.edu/timeline/api/timeline-api.js" )
in the html.erb file and the Timeline is available for use (I'll probably go with a local version at some point soon, I've just not got around to sorting that out yet).

The problem I ran into is that Pocket IE on my Pocket PC (a Dell Axim X50) doesn't seem to like this and throws an "Object Error". This was easy enough to solve in the end. I simply added this:
# Test if the request came from Pocket IE.
def pocket_ie?( request )
request.env[ "HTTP_USER_AGENT" ][ /MSIE.*Windows CE/ ]
end
to my ApplicationHelper class and then, in the html.erb file, simply said:
unless pocket_ie?( request )
javascript_include_tag(
"http://simile.mit.edu/timeline/api/timeline-api.js" )
end
Combined with a handheld specific stylesheet to hide the div that contains the timeline I end up with a version of the page that works in Pocket IE with no problems.

Okay, I guess it's a little kludgy, but it works and solves the problem at hand.

Ruby on Rails (and some WAP)

I'm quite a fan of ruby and have been for many years. In the last year or so I've been meaning to get to grips with rails but, every time I've tried, we've ended up having a falling out.

Most of the reasons have tended to be based around the (it seems to me) amazing lack of useful documentation. Sure, there's lots of stuff out there that documents the framework, but the sort of documentation that helps ease you into the learning process seems very thin on the ground.

Not too long back, at the suggestion of Rich Daley, I invested in a copy of Agile Web Development With Rails. This was just the sort of thing I was looking for and it's been a huge help (and also a huge source of frustration in itself seeing as how it's aimed at an earlier version of rails than the one I've got installed, but I've managed to get over that hump — it also seems that there's a third edition on the way).

Even with that book I still had a couple of aborted attempts to get to know rails better. As often happens with me the problem really came down to not having a goal to work to, a problem to solve, an application to build. Finally, last week, I devised a problem to solve and set to work.

And it worked, and it's been enjoyable. So far I'm impressed.

For me a good development system is one where my needs have been anticipated and, up until now, rails seems to deliver. A good example happened very recently. After having "finished" my little test application I thought it might be fun to add some simple WAP support. I imagined it would be easy enough using respond_to. Something like this:

def index
respond_to do |format|
format.html
format.wml
end
end
However, that didn't work. rails didn't know what to do with a "wml". A quick Google search later (see, the online docs are fine once you know what you're doing) and I found that all I needed to do was to edit my config/environment.rb to add the following:
Mime::Type.register "text/vnd.wap.wml", :wml
A restart of the server later and everything was fine. All I then needed to do was to create a index.wml.builder along the lines of this:
xml.instruct! :xml, :version => "1.0"

xml.wml "xml:lang" => "en-gb" do

xml.card :title => "My title here" do

xml.p "Something interesting here"
xml.p "Something else interesting here."

end

end
and I was done (and testing was easy enough thanks to the wmlbrowser add-on for Firefox).

I think I'm going to like rails. Now to find a real problem that needs solving...

2008-04-30

extlogkeywords

On the off chance that it might be useful to someone I've put a copy of extlogkeywords on my website. This is the tool I wrote to generate the data to feed GraphViz and which is central to the production of my clickable search term interconnectedness graph thingy.

It's not terribly good ruby code, it could do with some tidying up. Also, because I hacked up a quick-and-dirty apache log parser, it probably won't even work for your logs (I should probably hunt down a good and flexible ruby library for that, there's got to be one out there). Still, if anyone wants a play/hack, it's there for the taking.

2008-04-29

More ruby, graphviz and weblogs

Things have progressed a little further with my initial play with GraphViz. I noticed that it can produce SVG output and that the input format permits links to be associated with nodes. This meant it would be easy enough to produce a graph, with links, that could relate back to searches made on my site.

I decided to keep things simple and just deal with my photography so, after a little bit of extra scripting later, my site has a clickable search term interconnectedness graph thingy.

No sofas, slimy things with legs, horses, monks (electric or otherwise) or stoned poets were harmed during the writing of this code.

2008-04-02

ruby, geonames and photography

Recently I've been working on some ruby code that serves up the photography content of my website as a ruby object (no, it's not available for download anywhere, it wouldn't be any use to anyone else). The point behind it is that it lets me query my photographs in all sorts of different ways (especially handy when working in irb as it means I've got a kind of REPL for working with my photographs) and also makes it easy to write programs that generate useful data.

Last night I got to thinking that it would be interesting to use this code to try and "reverse geocode" the ICBM address that every album has so that I could display the nearest centre of population to the album.

After a bit of searching on the net I found GeoNames. A handy enough site itself but even more handy because it has an API and a list of client libraries that are available. Handily there's a library for ruby.

A little bit of hacking later and I had this:

#!/usr/bin/env ruby

require 'geonames'
require 'photography'

include Photography
include Geonames

# Get place names for all the icbm locations
Albums.new.load.collect {|album|
[ album.latitude, album.longitude ]
}.uniq.each {|icbm|
near = WebService.find_nearby_place_name( icbm[ 0 ], icbm[ 1 ] )
puts( "#{icbm[ 0 ]}\t" +
"#{icbm[ 1 ]}\t" +
"#{near[ 0 ].name}\t" +
"#{near[ 0 ].country_name}\t" +
"#{near[ 0 ].distance}" )
}
Put simply: it gets a list of the unique locations that I've recorded and runs through them getting the nearest known location. I then use the resulting data on my site to display the name of the nearest location to where the album is from.

It isn't perfect. For example, most of the photographs I've shot in and around Billingborough end up being shown as being near Horbling (the next village north of here, and somewhat smaller than Billingborough). Still, it's a start.

Currently I've got the text linking to a search on nearby.org.uk. Via that there's some fascinating (for varying values of fascinating) links to further searches that can be done based on location.

2007-01-31

Photographs by date

I've extended my photography section of my site a little more to include a couple of ways of getting at the photographs by date. The first is a simple calendar approach — click on a date and you get the thumbnails of all the images taken on that date.

The second addition is timeline of my photographs:



This is done with the Timeline library.

2006-04-13

The Euston Manifesto

The Euston Manifesto seems to be making quite a buzz today. I've had a very quick skim of the document and found much that I agree with and, at first glance, nothing I totally disagreed with. I think I'll be printing this one out and having a good read over the long weekend (it's a holiday weekend in the UK — some sort of pagan festival or other from what I can gather).

If nothing else item 14 caught my attention as it deals with Open Source. Okay, it's bound to annoy the hell out of RMS if he ever reads it but, hey, it's nice to see it get a mention.