Killing all instances of Ruby on Rails running on a certain port.

I was having a hard time getting my Rails webserver to restart after it having a bit of a hissy fit. The process to handle most apps when this happens is to locate the PID (Process ID) of the thing that is broken and kill it.

An easy way to do this with Rails is to type the following into your Terminal;

lsof -wni tcp:3000

Which looks for all processes running on port 3000 (the most common port for things like Webrick and Thin to run on) and returns them all as a table.

One of the columns of the table will be the PID for the process, copy it and paste it into the following line which will go into your Terminal;

kill -9 PID

Replacing ‘PID’ with the PID you just copied.

This will kill all processes relating to that PID, once this is done you should be good to go ahead and restart your rails server.

Share this on

Bad example of how to do unsubscribe pages.

Today I received an email from Game. If you don’t know who Game are they are a video game shop here in the UK, not really that important for the blog post but I like my readers to be informed.

I have little interest in what Game have to say anymore so I figured I would unsubscribe from their list, which has actually made me think I should write up a blog post someday on reasons why you should unsubscribe rather than just deleting or putting in filters.

As normal I scrolled to the bottom of the email and scanned for the unsubscribe link, all credit to them I found this with no bother at all. This next screen kind of took away from the experience though;

Game's Unsubscribe Email Page

 

How the heck do I know if I am sure I want to remove t***********@g*********.com?

This stinks of some sort of speculative security measure without any actual use cases being thought out, a horrible user experience and one that left me clicking ‘Remove Me’ because if t***********@g*********.com didn’t pertain to my email address then I was probably doing some other bugger a favour by removing them.

If there is some way for someone to get to that page without clicking on a link that was originally sent to the correct persons email address then Game need to fix that, not obscure the email address in case some non-genuine person is looking at it.

Whilst I am ragging on this page, it also feels a little weird that they didn’t try and subtly sell me something, even a small banner below the form that had the latest releases or something. I don’t want there to be one big advert or for it to take away from my core goal (confirming my subscription status) but having every page as a sales tool seems like e-commerce 101?

Share this on

Using Loops in Jasmine

If you want to test your code against 10 different inputs you don’t want to have to write 10 different tests. You want to write one test you can call 10 times.

The cleanest way to achieve this is to have your inputs and outputs stored in an array or object (In the example below I have chosen an array).

Intuitively (especially if you are familiar with how to write Rspec tests) it might feel like all you need to do is wrap your it block in a for loop and have your arrays feed into it, unfortunately due to the nature of how Jasmine executes this will not work.

What you need to do is wrap your it block inside a function, which you can then call from inside a loop. For example;

describe('this is my looping test!', function() {
  var input = [1,2,3];
  var output = [10, 20, 30];

  function test_my_times_ten(input, output) {
    it('should multiply ' + input + ' by 10 to give ' + output, function() {
      expect(input * 10).toEqual(output)
    });
  }

  for(var x = 0; x < input.size; x++) {
    test_my_times_ten(input[x], output[x]);
  }
});

With this technique you can see how you could quickly build up a very large and comprehensive test suite without writing a large amount of tests, things start to get really interesting if you start having nested loops passing in input. Just be aware of the performance implications of nested loops though!

Share this on

Useful Chrome Extension for Backbone.js Debugging

If you do much work with Backbone.js inevitably you are going to have to end up debugging some silly mistake you have made, I know I have been making about 5000 a second over the past few days.

Luckily I read today that there is a Google Chrome extension out that can help debug Backbone.js issues. The code can be found here along with an easy to follow installation guide.

One thing the guide does not mention is that you will more than likely need to restart Chrome to get this to work, I know I did.

Whilst it is clearly still in early development, I have already been putting it to use and getting good stuff back from it

Share this on