about:benjie

Random learnings and other thoughts from an unashamed geek

JavaScript: Defining a Window Level Function With Eval()

| Comments

You know the old mantra: eval is evil! Well, maybe, but I hate writing lots of code, and I like my debugging to be simple. I wanted to write a shorter way to extend a parent class into a child class. Long way (too much repeated code/risk of copy & paste errors):

Long winded: manually creating each class from scratch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Root class
function MyClass() {
  return this;
}

// Create first subclass
function MyChildClass1() {
  return this;
}
MyChildClass1.prototype = new MyClass();
MyChildClass1.prototype.parent = MyClass.prototype;
MyChildClass1.prototype.constructor = MyChildClass1;

// Create second subclass
function MyChildClass2() {
  return this;
}
MyChildClass2.prototype = new MyClass();
MyChildClass2.prototype.parent = MyClass.prototype;
MyChildClass2.prototype.constructor = MyChildClass2;

// Create an instance
var instance = new MyChildClass2();

Shorter way (gives wrong output on console.log()):

Backup Your Logs to S3

| Comments

We’ve got an auto-scaling EC2 setup, so servers can appear and disappear at will, each with random IP addresses. We want to store the apache error/access logs (or system logs) from these servers for later debugging and analysis, but nothing else on them matters (they’re basically read only, except the logging). How should we store these?

Seems like a simple problem, there must be a simple solution? Here are the existing options:

Dear Virgin Media…

| Comments

I think I do have fibre optic at my house already, even though it does not show up on your system. The previous resident had V+HD, and they left their equipment, so I’ve plugged it in to show the system working:

iPhone Music and Sound Effects in Parallel

| Comments

I was trying to find out how to use [MPMusicPlayerController iPodMusicPlayer] and AVAudioPlayer in parallel. I’d read before that I’d need Audio Sessions, but the documentation for that was huge and confusing. Fortunately Andrew pointed me at this post from Mark at Sputnik Games which solved my issue immediately just by copying and pasting 14 lines of code into the applicationDidFinishLaunching method of my application delegate (see below). Sputnik Games’ blog doesn’t seem to support comments, so I thought I’d buy his latest game, Aerolite, and write this post to show my appreciation. Thanks Mark!

Add to applicationDidFinishLaunching to enable music & sound effects at the same time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
OSStatus result = AudioSessionInitialize(NULL, NULL, NULL, self);
if (result) {
  // Init error, handle error here
} else {
  UInt32 category = kAudioSessionCategory_AmbientSound;
  result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
                                    sizeof(category), &category);
  if (result) {
      // set audio session error, handle error here
  } else {
      result = AudioSessionSetActive(true);
      if (result) {
          // Set audio session active error, handle error here
      }
  }
}

N900: First Impressions

| Comments

This post is part 2 of a three part series. You may also be interested in: Part 1: N900: the tale of the indestructible box Part 3: N900: a phone for hackers? (coming soon…)

After conquering the indestructible box and charging the N900 I decided to have a quick play. I watched the getting started video which I found to be both beautifully smooth, showing off the high definition of the N900 screen immediately, and somewhat slow content-wise.

G1 (top), N900 (left), iPhone 3GS (right)

The N900 is similar in width and height to the iPhone but

N900: The Tale of the Indestructible Box

| Comments

This post is part 1 of a 3 part series. You may also be interested in: Part 2: N900: first impressions Part 3: N900: a phone for hackers? (coming soon…)

A week ago I was contacted by Lydia of WOMWorld.com/nokia who asked me if I would be interested in receiving an indestructible box. I was told that she found me via my twitter profile and felt it would appeal to my passions. After confirming the email was not spam I replied, intrigued, “yes please” and sent her my address.

4iP Funding for GymFu

| Comments

image GymFu (that’s Jof Arnold, Jem Gillam and myself) has received just shy of £100,000 funding from 4iP (an angel/investment arm of Channel 4) to work on a new project improving the health of the nation in bitesize chunks. This is obviously very exciting for us all, but I’m afraid we can’t tell you any more until details are firmed up, though I can tell you that you should see output from this project by the middle of next year. Wish us luck! Why not read 4iP’s press release and TechCrunch’s take on the funding?

MythPyWii Power Update (V17)

| Comments

Myth tv logo from Wikipedia

Thanks to Matthew Zimmerman for sending me his modified version of MythPyWii, it now has power-saving - after 35 minutes of inactivity the Wiimote turns off. You can download the latest version, as always, here; or you can get this specific version (v17) here. I love open source!

Arduino Pin Speed (Multiplexing)

| Comments

image

I’m working on a new project, I’ve got a 8x8 dual colour dot matrix display (£2.50 delivered from Earthshine Design) and I want to power it from the Arduino. One way of making a chip like that (which has 2x8x8 = 128 LEDs) would be to have a common ground and an additional 128 pins - one for each LED. This, I think you’d agree, would be a nightmare, so instead they’ve basically gone for an 8x16 grid for a total of 24 pins. This raises two main problems:

  1. You can’t turn 2 arbitrary LEDs on at the same time unless they are on the same row/column. (Doing so would actually draw a square of LEDs.)
  2. My Arduino doesn’t have enough digital input/output pins

Point 1 is easily solved - we simply update just one row at a time, letting Persistance Of Vision (POV) do the hard work for us. Point 2 is the subject of this post - multiplexing, combining multiple individual signals into just one signal. I will not be using this dot matrix display in this post, instead I will simply be powering normal LEDs. I wanted to find out if the Arduino is fast enough to multiplex the data through just a few pins in order to power this display. The answer (one of my favourite answers!) is: “Yes, but not without some hacking.”