Posts about Blog

Typecasting Strings to Integers in PHP

August 15th, 2008

PHP does some funny things when typecasting strings as integers and may not work the way you would expect (to be fair, it is documented). Here are some examples running under PHP 5.2.5 from the Mac OS X command line:

php -r 'var_dump((int) "agbae");'
int(0)
php -r 'var_dump((int) "zzzzzzzzzzzzzzzzzzzzzzz");'
int(0)
php -r 'var_dump((int) "2agbae");'
int(2)
php -r 'var_dump((float) "42165.6agbae");'
float(42165.6)

This is important to know because PHP allows you refer characters of strings just like you would the elements of an array (and somewhat similar to C’s strings):

php -r '$s = "abcdef"; var_dump($s[2]);'
string(1) "c"

However, giving an invalid key won’t given an error, depending on how your installation of PHP is configured in php.ini. If you give an out-of-bounds string you get an empty string:

php -r '$s = "abcdef"; var_dump($s[45]);'
PHP Notice:  Uninitialized string offset:  45 in Command line code on line 1
string(0) ""

If you give a string key, it is always for the zeroth index, since it is typecasted to an int and typecasting works as described above:

php -r '$s = "abcdef"; var_dump($s['zzzzz']);'
PHP Notice:  Use of undefined constant zzzzz - assumed 'zzzzz' in Command line code on line 1
string(1) "a"

The Two Thirds Rule

August 5th, 2008

The Two Thirds Rule is very simple: for all the people that sign up for a free event, only 2/3 of them will attend. This has been true at all the Lunch 2.0s and BarCamps I organize (BarCamp Amsterdam IV being the exception) and I know it was also true at the TechCrunch/eBuddy Meetup. I also see that this occured at the San Francisco iPhone Dev Camp.

So what? Well, as an organizer it’s frustrating to plan for more people than actually come (food may go wasted, etc), so it’s good to be able to know how many people will really attend. Some people figure it’s worth charging a small but noticable amount (say €10) to make people feel committed. I haven’t done this yet, but my hunch is it would increase your yield to something like 3/4 or 4/5 of signups.

Upcoming Events I’m Organizing

August 4th, 2008

This Friday sees Lunch 2.0 visiting Utrecht for the first time, where will be hosted by iDiDiD. On August 22 we have a Lunch 2.0 at Sogeti in Diemen. Finally at the end of the month, I am hosting an iPhone Dev Camp on August 30 at my office. We’ve had a huge response to the Dev Camp idea, so if anyone has any routers, tables, chairs, projectors or other gear they’d be willing to lend me for the day, it’d be much appreciated!

Finally, keep November 22 open in your calendars. Together with Joris Machielse, I am organizing a BarCamp-style event around creating startups. More information to come in early September, but if you have any people you’d like to meet or things you wished you knew before you started your business, please leave a comment below or email me at peter@bubblefoundry.com.

Loading Javascript Libraries When Needed

June 23rd, 2008

Here is a nice little Javascript function to load some Javascript libraries:

function includeLibs()
{
var libs = [{object: 'Prototype', src: 'http://www.mobypicture.com/slideshow/prototype.js'}, {object: 'Lightbox', src: 'http://www.mobypicture.com/slideshow/lightbox.js'}];
for (var k = 0; k < libs.length; k++)
{
try
{
var obj = eval(libs[k].object);
}
catch (err)
{
var obj = false;
}
if (obj == false)
{
var newjs=document.createElement(’script’);
newjs.type=’text/javascript’;
newjs.src=libs[k].src;
document.getElementsByTagName(’head’)[0].appendChild(newjs);
}
}
}

This is particularly useful if you’re writing a widget that requires external libraries but the user might already have them loaded, such as Prototype.

Multilink

June 21st, 2008

Multilink is a very simple Javascript library that creates tooltips with multiple links per ‘normal’ link, its simplicity due to Prototip2 and Prototype. Why have one link when you can have ten! Check out the Multilink page for an example.

Repairing SVN Working Copies

May 30th, 2008

Unfortunately an all too common problem with Subversion is accidentally deleting the .svn directory used to track changes on a working copy. The accepted solution seems to be to check out to somewhere else the directory to which .svn belongs and then copy the new .svn directory into where the working copy’s should have been.

I wrote the following bash script to automate this repair process:

#!/bin/bash

if [ "$1" == "help" ]; then
  echo "Useage: svnrepair repository_dir local_dir"
  exit 1;
fi

if [ -n $1 ] || [ "$1" == "." ]; then
  repo_dir=`svn info | awk '/URL: (.*?)/ {print $2}'`
else
  repo_dir=$1
fi

if [ -n $2 ] || [ $2 == "." ]; then
  local_dir=`pwd`
else
  local_dir=$2
fi

svn co $repo_dir delme; cp -r delme/.svn $local_dir; rm -rf delme

From the Laboratory: Closed Standards

May 27th, 2008

Closed standards are an oxymoron and any standard that is closed is moronic.

This is going to be a rant, so bear with me….

How can you call anything a standard when you don’t make the standard readily available? What is the point of a standard that no one can implement? Unfortunately, many ’standardized’ audio and video codecs are encumbered by patents, trademarks, and obscenely expensive reference documents. Surprise, surprise, but many of the telco standards bodies are the worst offenders! (As an aside, the movie people, thanks to MPEG, seem to be somewhat more sensible).

Read more »

From the Laboratory: IP2FireEagle

May 23rd, 2008

IP2FireEagle is small PHP script I wrote which will update your location in Yahoo Fire Eagle based upon your current IP address. You can find more information on the IP2FireEagle page.

BarCamps

April 11th, 2008

I apologize for writing this after the fact, but last Saturday I was proud to host BarCamp Amsterdam IV at my office. The event was a fabulous success, with people from six countries (Netherlands, Belgium, UK, Sweden, Finland, and Romania) attending, including several startup founders who had presented at The Next Web Conference. Building on that success, I will be hosting a Health 2.0 BarCamp tomorrow and BarCamp NLGovWeb in June.

And for those who don’t know what a BarCamp is, it is an ‘unconference’ where attendees make the schedule and everyone is encouraged to participate in presentations. I highly recommend attending one, so if you’re free, come by tomorrow or in June!

Startups In The Netherlands?

April 10th, 2008

Yes, there are startups in the Netherlands, as proven by the many in attendance at The Next Web last week. I’ve been gathering a list over the last month, and I now how a list of almost 40 companies. I’ll admit that CrunchBase coming to Europe has also forced my hand. So please, check it out and tell me who I’ve missed!