Tue
Jun 2nd

Review: Figure Out When

Figureoutwhen.com is a tiny service for organising dates.  It works like this:

  • Enter a title for an event
  • Click the dates you’re not available
  • Send the link to friends you want to invite
  • They click the dates when they aren’t available

Everyone can see when they’re not free, thus allowing you to figure out when to schedule an event.

It’s an incredibly simple tool, but has a clever “just works” interface, there’s no registration, login, saving data… just a simple calendar and title for your event.  Figure Out When works best when organising an event in the near future, because the month defaults to the current month (rather than the last one selected).

The only thing I’d like to see added is shift-clicking to select date ranges.  This might help people when organising events that could happen any time in a month.

Comments (View)
Thu
May 28th

JsChat

JsChat is a simple open source realtime chat protocol based on JSON.  There’s a server and console and web clients.  It’s developed by the Quite Useful authors.  Download it from my GitHub repository: github.com/alexyoung/jschat, and read more at the JsChat Blog.

Web Client

Most people who have tried JsChat think it’s all about the web client, but this is only a proof of concept I built to illustrate how simple implementing the JSON-based protocol can be.  It’s made with Ruby and Sinatra (Sinatra is a tiny Ruby web framework).

It has a few interesting features:

  • YouTube URLs are automatically embedded so people can watch them
  • Image URLs are embedded too
  • Tab completion for names
  • Joining a room gives you the last 100 lines, so you can safely leave and come back
  • Rooms are just denoted by a hash part in the URL: jschat.org/chat/#jschat
  • It’s possible to open multiple tabs in your browser and sit in multiple rooms
  • It polls using simple Ajax calls which means it’ll run in lots of browsers (I’ll experiment with detecting browser-specific push capabilities in the future)

Console Client

The console client is written with Ruby and Ncurses.  You can connect to JsChat.org by downloading it and running:

./client.rb jschat.org

It’ll pick up your name from the system and auto-join #jschat.  You can join multiple rooms and switch between them using /switch (or /s).  Type /help for more commands.

I’m not particularly good at Ncurses, so I’m waiting for someone to help clean it up!

Running Your Own Server

I’m going to blog more about how to run the web app alongside the core server with Apache and mod_proxy, with strategies for keeping them running (I’ll start with monit examples).

If you’d like to try it locally, just run:

./server.rb

./client.rb

Authors

Protocol creation and initial server, client and web app: Alex Young (message me on GitHub or @alex_young for more info about JsChat)

Initial concept, testing, feature suggestions: Kevin Ford

Bug fixes and code contributions: Simon Starr, Ric Roberts, Nick Martini, Jenf

JavaScript sanity checker: gabrielg

Comments (View)
Wed
May 20th

Beautiful Algorithms 3: Gravity

This series of articles explores using basic physics and mathematics to simulate balls bouncing.  The examples are written with Ruby and Shoes.

I’ve been working on the 2D version of the previous example for 3 days now, and I haven’t got it to a point where it’s clear enough yet.  However, I realised I was trying to cram too much into one article.  Instead, this part focuses on explaining vectors, and simulating gravity.  Although simulating gravity is simple for this simulation, I think you’ll be surprised by how naturally the balls bounce.

Vectors and Vectors in Ruby

A vector is just a direction of a force.  They’re usually drawn as a line with a direction.  More generally, vectors are quantities that are made up of components.  In the previous article, arrays were used to represent direction and velocity.  This is adequate, but not as natural as vectors when used with mathematical operators:

[1, 2] + [8, 2]

=> [1, 2, 8, 2]

If you’re used to mathematics, this result might surprise you.  What we want is:

[9, 4]

However, the + operator in Ruby treats arrays like sets and concatenates them.  This is generally the most intuitive thing to do.  What we need is a way of defining vectors.

Vectors are essentially matrices, and Ruby has a matrix library in its standard library.  Vectors are defined like this: Vector.[](1, 2) and can be added, multiplied, and more:

require 'matrix'

v1 = Vector.[](1, 2)

=> Vector[1, 2]

v2 = Vector.[](8, 2)

=> Vector[8, 2]

v1 * -1

=> Vector[-1, -2]

v1 - v2

=> Vector[-7, 0]

v1 + v2

=> Vector[9, 4]

v2 * 0.1

=> Vector[0.8, 0.2]

v2.r

=> 8.24621125123532

v2.inner_product v2

=> 68

Advantages

This makes the code in the previous example clearer, because inverting velocities and updating position becomes much clearer:

@position += @velocity * @mass

@velocity = ((@velocity * -1) * @eta)

These expressions update both the X and Y values for the position and velocity.  The second will be used to simulate bounces off the wall.

Gravity

To model gravity, the Y component of the velocity vector will be updated for each frame of animation:

@velocity += Vector.[](0, @gravity)

This looks suspiciously like it will result in infinite speed, but because the overall space the ball can move in is so small we can ignore this for now.

Wall Bounces

I’ve been very explicit about detecting bounces against the “walls” of the scene.  Each wall is checked (because the ball could hit two at the same time), and if a bounce has occurred the ball is moved back to the wall.  This is in case it bounces through the wall in cases where it’s moving very fast.  The bounce_off_wall method just uses the velocity vector multiplication described above.

    if @position[0] >= @app.width - (@radius * 2)
      @position = Vector.[](@app.width - (@radius * 2), @position[1])
      bounce_off_wall
    end

Scene Management and Keyboard Commands

My example adds some methods for creating random balls with different velocities and mass, and it also adds keyboard commands for reset (r) and adding a new ball (a).

Putting it Together

Get ball-gravity.rb from my GitHub repository shoes-ball and run it with Shoes.

Comments (View)
Sun
May 17th

Quite Useful Weekly Roundup

This week we posted the first of a new series of Beautiful Algorithms articles: Collisions.  We also posted about eBooks and a web app called Orchestrate.

Twitter Summary

TeleRead is a great blog about eBooks.  They post regularly, and write about hardware readers, formats, sites that sell/host eBooks.

6 Tips To Get Your App Noticed has some ideas for marketing your iPhone apps.

Wiimote Whiteboard is an open source project for using Wiimotes to turn any surface into an interactive whiteboard.

Windosill is an incredibly imaginative Flash puzzle game.

App Reviews

Please send us links to your web/iPhone/Mac/Windows apps so we can review them!

Comments (View)
Fri
May 15th

Beautiful Algorithms 3: 1D Collisions

“1D Collisions” might sound a little bit strange, but the goal of Beautiful Algorithms 3 is to explore algorithms for collision physics.  Collisions in 2 or 3 dimensions are naturally more complex than a single dimension, so let’s look at this first.  I’ll explain what mathematics and physical laws are required (don’t worry, you understood all of this when you were 13), and then explain how to write a Ruby program to simulate this.

Newton’s Laws

You probably did simple experiments in science classes at school whereby objects were rolled down ramps, and their bounces were measured.  This is a physical exploration of Newton’s second and third laws of motion.

  • Newton’s second law of motion: Momentum = mass * velocity
  • Newton’s third law of motion: For every force there is an equal and opposite force
  • Newton’s law of impact: The difference between velocities before impact is proportional to the difference between their velocities after impact

In the Ruby Shoes example, we’ll draw two balls and make them collide.  Calculating their position for a given frame of animation will require the second law.  Collisions will use the third law and law of impact to calculate the velocities after impact.

Velocity

Velocity is the rate of change of position: speed and direction are combined as a vector.  Vectors aren’t scary — in this example we’ll use an array to model velocity for the speed going left or right and up or down.

The velocity will change after impacts according to the second law of impact and third law: that is, the velocity should be reversed after impact, transferring some of its energy in the process.

Required Variables

According to the brief and possibly inaccurate summary of high school Newtonian physics above, each ball will have the following variables:

  • Mass
  • Velocity (as an array) — negative values will mean left or up
  • X and Y co-ordinates
  • A value for the coefficient of restitution — basically the amount of energy lost in each impact

Required Methods

We’ll need to know when balls bounce off each other or the walls of the scene.  We’ll also want to update the position for each frame of animation.

  • check_collisions(set of balls)
  • hit?(ball) — check if the ball has bounced off another one
  • collide — if a collision has been detected, alter the velocity according to the laws above
  • move — move the ball

Collision Detection

The algorithm works like this:

  1. Calculate the distance between two balls using Pythagoras’ Theorem by subtracting their positions to create a common frame of reference, then calculating the hypotenuse
  2. If this value is less than or equal to the combined radius of each ball, they’ve bounced
  3. If the ball has moved to the end of the window, it has bounced

The first step sounds a little bit complicated.  Basically:

x = absolute value of: ball_a.x - ball_b.x - x_velocity
y = absolute value of: ball_a.y - ball_b.y - y_velocity
hypotenuse = square root of (x squared + y squared)

Main Loop

The main loop will look like this (example requires JavaScript to display):

Putting it Together

The final example is available here: ball-1D.rb.  You can run it with Shoes.  Note that there’s no friction or gravity, bodies simply bounce until their collisions reduce their velocity enough.

Try playing around with the velocity and mass settings to see what happens.  I’ll be back on Monday with a 2D collision example!

Comments (View)
Thu
May 14th

Beautiful Algorithms 3: Balls

Beautiful Algorithms 3 is going to be about simple physics.  These examples will be written with Ruby Shoes, and will demonstrate how to simulate bouncing balls and collisions.

The easiest way to model bouncing is to go back to basics with high school physics.  Start off with 1D collisions, then add the second dimensions, then apply gravity.

The first post in this series will be posted tomorrow.  To get Shoes, download it here: shoooes.net.  My previous Shoes example was Let’s Make a Game: Snake.

Comments (View)
Tue
May 12th

eBooks

You’ve probably seen the Kindle, Amazon’s reading device.  I live in the UK, and I have massive Kindle envy because Amazon don’t sell it outside of the US.  That doesn’t mean we all need to wait for Amazon to launch localised Kindles, however.  eBooks have been with us for a long time: Project Gutenberg’s founder Michael Hart has been exploring eBooks since 1971.  I used to read books on my Palm IIIe at university to save money.  The old Palm’s low-glare monochrome screen was good for reading, and I was happy with it.

Since my experience with eBooks on Palm I’ve tried many devices.  I’m currently using an iPhone with the Stanza app.  There’s a few things I like about Stanza: it’s easy to change the brightness by dragging across the screen, there’s a lot of options for fonts and sizes, and page changes are fast.  In terms of comfort, however, reading on the iPhone isn’t optimum.  It’s equivalent to my old Palm but I imagine the Kindle or Sony Reader offer better experiences.

Content and Formats

The main problem with eBooks right now is finding content.  This is a solved problem is you’re using a Kindle in the US, and Sony has their own store too.  Sony’s device can use books from other sources too.  If you’re not using one of these devices, it’s not always clear what books will work for you: some online shops don’t display their formats known.  Others specifically note the format and DRM used.  And even when they display formats, what do they mean and what can your reader support?  If you’re using Stanza and you buy a DRM’d ePub, will it work?  (The answer is: not currently).

Sony’s products support DRM, most notably for ePub.  If you buy a book in the DRM’d ePub format, Adobe’s Digital Editions will open it and manage the DRM.  Interestingly, ePub is basically a load of XHTML, so it’s an easy format for developers to support.

Another popular format is .mobi (or Mobipocket), which is an extension of the PalmDOC format.  It can be DRM’d.  As far as I know, this doesn’t work on the Sony Reader, but it could be converted, and the Kindle does support it.

You’ll probably also come across LIT.  Microsoft Reader will open these files, which is on PocketPC and Windows Mobile devices.  Stanza’s desktop app allows me to open LIT files and send them to my iPhone; I think the Sony Reader will need the files converted.

There are many other popular formats.  Books are distributed in RTF, plain text and PDF, and the frightening list here contains more.  Generally, if you’re sent a LIT, ePub or mobi file, it’ll work well on a hardware reader (or with minimal conversion through desktop software).  I’ve had a lot of luck with ePub and LIT with Stanza and iPhone.  PDF has been a problem: yes, I can read them, but they just don’t work very well on hardware readers.  Plain text and RTF can lose some of the elegance of a well presented LIT or ePub book.

Converting Files

You’ll be converting formats a lot.  Calibre works well, and Stanza’s desktop app will try to adapt content for your iPhone.  Calibre will run on Windows, Mac OS and Linux.

Yes, you can strip ePub DRM.  The process is quite technical, and will become more difficult when Adobe fixes a security flaw in Adobe Digital Editions.  It may be illegal in your country to do this.

Finding eBooks

I can only list sites I’ve had luck with, and my list is generally UK-centric.  Stanza has a built-in list of sources as well.

  • Fictionwise - US-based, but has a lot of content.  I haven’t bought anything form here, but they’re clear about formats and DRM.
  • WHSmith eBook Shop - very clear about DRM, but mix in audiobooks with results so keep an eye on the format you’re purchasing.
  • Waterstones - heavily promoted the Sony Reader in the UK.  Not clear enough about DRM and formats, but the books I’ve got from there have been ePub DRM’d and open on my Mac and PC with Digital Editions.  Their advanced search lets you limit results to eBooks, but this sometimes decides to include regular books.
  • Penguin - Similar to Waterstones, selling DRM’d ePub
  • Pragmatic Programmers - the template for all future eBook sites.  Once you buy a book you can download multiple copies in PDF, ePub and mobi with no DRM.  Only really suitable for software and designer folks, but if all eBook sites were done this way life would be simple.
  • O’Reilly - Also sell un-DRM’d eBooks that’ll work on just about any device.
  • Project Gutenberg - Copyright expired books

Blogs

Conclusions

I hope this article has clarified the world of eBooks.  At first all the formats and DRM are hugely frustrating, but the growing dominance of .mobi and ePub should make things simpler, and publishers who support DRM-free books will ultimately create a world where anyone can understand and use eBooks.

Comments (View)
Mon
May 11th

Web App Review: Orchestrate

Orchestrate is a web application made by Elevensoft, who are based in the UK.  It’s designed to manage tasks for projects.  What makes it unique is the focus on scheduling conflicts and qualification management.

Orchestrate has a clean interface, similar to Lighthouse or Basecamp: the main page body is used to display information and forms, whilst the sidebar is used to issue commands or change the view.  It also has a prominent breadcrumb navigation, so it’s easy to jump back to earlier stages of a process.

The only tweak I’d like to see here is automatic field focus: I’m used to web apps putting careful thought into what field I’ll need to type in on a freshly loaded page.

Scheduling

Tasks can be assigned to locations and people.  It’s also easy to set up recurring tasks, then assign them to people based on a weekly schedule overview.  You can then see all of the events for a particular day in a summary by clicking on the day:

Qualifications can be created and assigned to people.  This makes it easier to decide who can perform a particular task.  This makes sense: in our company I’m the only person who can deploy apps to our servers, so I’d set that up as a qualification.  Other tasks like writing blog posts are accessible to more than one of us.

Once a task is ready to be signed off, there’s a set of standard outcomes that can be selected:

Pricing and Conclusions

There’s a free plan, and other plans start at $19 per month.  All paid plans give unlimited users so they’re pretty good value, and the top plan at $199 per month gives branding features.  Judging by customer feedback I expect branding will be dropped to other plans, but this will probably be determined by how many companies pick up the $199 plan.

The Help page is powered by Get Satisfication.  I’d much rather see a comprehensive help page with usage examples; despite Orchestrate consistently claiming to be easy to use and simple, it took me too long to figure out its terminology and features.  The interface is always clear and also provides inline help tips, but more detailed inline help would really get people going with less initial confusion.

I use project management software: I’ve used Basecamp since it was launched, and I still use it to manage client projects today.  The core feature that makes me stick with Basecamp is messaging, and Orchestrate doesn’t do this.  However, many business people I’ve worked with have wanted more sophisticated scheduling like Orchestrate offers, and it does provide client updates, so it may work better than Basecamp for  companies who want this type of scheduling.

Comments (View)
Sun
May 10th

Quite Useful Weekly Roundup

This week we posted a selection of command line time savers, the source code for a Ruby Twitter scheduler, and a review of online collaboration service Woobius.

Twitter

I was having a bit of fun with mashups this week, so I posted a link to DJ Lobsterdust who makes some incredibly witty and skilled tracks.  If you like that, it’s worth checking out Girl Talk too.

A lot of Twitter/Digg style sites were announced this week: Daily RT and Twittl were heavily linked to.  Although these types of sites don’t seem wildly popular right now, their obviousness is leading some people to believe Twitter’s future will be based on reputation: a combination of Google’s PageRank with social networks.

On the Mac apps side, I found Warranty Hero which is an interesting app: it aims to help you track when you purchased items along with their receipts.  Page Capture also seemed to strike a chord, I’ve been using Paparazzi! for a few years to do the same thing — great apps for designers building images for a portfolio or for clients.

I posted a few developer links, but one that stood out was an OCUnit tutorial.  I’ve been a Ruby programmer for several years, where unit testing is part of a day’s work.  In the Objective-C (iPhone/Mac) camp, however, unit testing isn’t part of the scenery.  It’s worth getting to grips with OCUnit though, if only to save your sanity in the long run!

Comments (View)
Fri
May 8th

Mind Blowing Command Line Time Savers

Whether you’re an old skool unix hacker or a Mac user who uses Terminal regularly, there’s lots of ways to save time on the command line.  I’ve mentioned a few of the following tips on twitter.com/quiteuseful, but I thought it’d be handy to collect them all here.

Bash

!! - repeats the last command

history n - shows the last n things you’ve typed

My favourite shortcut is ctrl-r: this lets you search through history interactively.  I probably use ctrl-r every day, I really don’t like repeating myself!

xargs is a useful command: it’ll construct argument lists.  It works really well with pipes:

find *.rb | xargs grep -i "ActiveRecord"

Aliases

My aliases end up getting ridiculously short.  I don’t ssh into my screen session with IRC, etc, I just type “irc”.  I don’t even type ls either:

alias l='ls -Gla'

If you’re on a Mac you should have a ~/.profile file, so you can add aliases there.

Apps: ack and cdargs

My two favourite command line time savers are ack and cdargs.  I found myself searching code a lot, and ack works better than grep for this.  It’s also useful for finding documentation: why view the Rails HTML docs when you can ack the Rails source?  Give it a go with one of your regularly used libraries!

You can get ack from betterthangrep.com.

cdargs lets you bookmark directories, then cd to them with a shorter name.  I have a lot of code in ~/Documents/Code/project_name, and I move between projects every day.  I bookmarked these with ca, then I cd to them with cv project-short-name.

You can get cdargs here: cdargs.

These apps don’t sound like a big deal, but they really help me switch between projects.  Ack is great for navigating code too: you can get plugins for TextMate or Vim.

Comments (View)
Related Posts Widget for Blogs by LinkWithin