Mario's Blog

The journal of a software developer who has a fondness of cheese

Messing Around With Project Euler

So I got a little bit bored today and wanted a change to my daily routine. I realised that I haven’t done any Project Euler problems in quite a while. If you don’t know what Project Euler is and you’re into programming or math then have a read over here.

It’s basically a great way to practise your math and programming skills. You can compete with your friends also which is fun :) I started when my friend Tyson suggested he could solve me than me.

I’ve been solving my euler problems in Ruby because … well why not? Today I managed to solve 3 problems, taking my grand total to 33 out of a possible 300 problems. <=== Sounds more exciting when it’s in bold, right?

So while solving all these problems i’m slowly developing a set of simple libraries that are used across multiple problems. Seems to be saving me a bit of time now. The helper libraries (well only 1 at the moment) are available over at github.

jQuery: Detecting Right Click Paste on Input Fields

Today I was creating a jQuery search for a clients website, I wanted the search to happen once the user types in their search terms without having to press a search button.

Getting the jQuery action to run once the user changes the input is quite easy:

1
2
3
4
$('.search input').keyup(function()
{
  do_search();
});

As you can see from my example I have an input field wrapped inside a div with class search. Also my search method is called do_search(). This method works fine for all user keyboard input, including if the user pastes text into the input using keyboard shortcuts, although it doesn’t work if the users pastes text into the input using a right click mouse menu. To get this behaviour we can bind an action to the paste event like so:

1
2
3
4
$('.search input').bind('paste', function()
{
  do_search();
});

This seems to work well, the do_search method is now being called when the user right click’s and pastes into our box, although it does have a small problem. Our code within our action is executed before the actual paste occurs, this means that our search will be run on whatever is present in the box before the paste, which is not what we want. To rectify this we can add a small delay to our do_search method which ensures it is run after the paste is completed.

1
2
3
4
$('.search input').bind('paste', function()
{
  setTimeout(function() { do_search(); }, 100);
});

Now with the combination of our actions on the keyup and paste events, the search should run no matter how the user is putting their search terms into the input field.

Setup Radiant Projects Easily With Radiant-go

Recently I began work on a project called radiant-go. Radiant-go is a rubygem that allows you to setup radiant projects easily. It saves a huge amount of time when setting up applications and it’s very easy to configure.

Here’s some quick instructions on how to go about using it:

First we install our radiant-go gem. It depends on radiant and bundler so it will install those too if they aren’t installed yet.

1
gem install radiant-go

Now we can generate our configuration files and modify them to our needs. This step is only necessary if you want to modify the initial configuration of your application.

1
radiant-go -c project

Now we can run our generator. If you have followed the step above, you need to run the generator on the same folder.

1
radiant-go project

That’s all, we’re done. Your Radiant install is ready to use.

Chief Detail Officers

If only one day I could be the chief detail officer for a large company in the city :)

Published My First Ruby Gem

Today I published my first rubygem :) It’s an installer for the radiant CMS called radiant-go. I’m really excited about it, as it’s a really great installer. You can get more info over at rubygems.org

My Feelings for You

Great song, great video clip! Look out for the retro gaming references, there’s heaps of them in the clip.