# Someone Needs to Fork BBPress

I really love bbpress, but I have to say how unfortunate it is that the standalone version no longer seems to be supported. I can’t blame the authors though.. I know how it is. You spend all this time writing a bunch of software and it doesn’t get you anywhere except a bunch of people saying things need to be fixed when you already don’t have enough time.

I don’t want to delve into the philosophy behind open source software, but I guess I’m saying if someone is looking to support an open-source project, I’d vote for bbpress standalone. Fantastic forum software. I wish I had the time to maintain it myself, but life is only so long, and there’s only so much time to work on so many things. Who knows. Maybe one day in the future.

# Is Getting to Work Early Better Than Staying Late?

I believe there’s a general impression in the work force that arriving at work earlier is somehow meritorious. I believe this stereotype works against people who arrive at work later in the day, even though both work the same amount of hours. Let me explain what I mean with an example:

Let’s say your office core hours are from 10-2. The extreme early-arriver would be in the office from 6 a.m.-2 p.m. (a standard 8 hour shift). A later-arriver would be in from 10 a.m.-6 p.m. (again a standard 8 hour shift). Based on my work experience I believe that the person who arrives at 6 a.m. will often be looked at as arriving at a more favorable time than the person who arrives at 10 a.m., regardless that they both work an 8 hour shift.

As a person who regularly arrives in the office after 10 a.m. I can attest to the fact that being unable to get to work before then has resulted in more than one negative experience.

What has been your experience? Do early-arrivers run into problems as well? Is it just me, or have you also noticed that later-arrivers seem to somehow have a less-meritorious arrival time?

# Cosine Similarity Calculator

The cosine similarity is a calculation used in data mining.  As far as I’m aware, this is the first and only online cosine similarity calculator.  Sweet.  Enjoy!  :)

Explanation

This Cosine Similarity Calculator will teach you how to calculate the Cosine Similarity (a.k.a. how to calculate the Cosine Measure) of two vectors. Useful for both math homework and data mining.

The Cosine Similarity of two vectors is an arbitrary mathematical measure of how similar two vectors are on a scale of [0, 1]. 1 being that the vectors are either identical, or that their values differ by a constant factor.

The Cosine Similarity of two vectors (d1 and d2) is defined as:
cos( d1, d2 ) = dot(d1,d2) / ||d1|| ||d2||

Where dot(d1,d2) = d1[0]*d2[0] + d1[1]*d2[1] …
And Where ||d1|| = sqrt(d1[0]^2 + d1[1]^2 …)

(Additional Info For Data Miners: The Centroid Similarity Measure is simply the Cosine Measure of your clustering output.  e.g. After clustering some data, if you only have two centroids, to get the Centroid Similarity Measure, you just take the Cosine Measure of the resultant vectors. If you have k centroids though such that k > 2 (and this formula works for k=2 as well), then it is the Summation From i=1 to K(Summation From j=1 to K (Cosine Similarity(Ci,Cj))).

Directions

This is a Cosine Similarity Calculator. There is currently little data validation so make sure your vectors are of equal length, are numeric in type, and with each value separated by a single space. For example ~> “1 2 3″ (without the quote marks)
would be a valid input:

Calculator

 Enter Vector 1 (Values Separated by Spaces) Enter Vector 2 (Values Separated by Spaces)
Your calculations will appear hear after you push the Calculate button!

I’ve been thinking a lot about Facebook’s purchase of photo-sharing app Instagram for a billion dollars and I haven’t wrapped my head around it yet.

I guess that makes sense though.  If I understood the purchase, I would probably own a company of that size.  It’s probably a testament to the fact that I don’t own Facebook or any company they’re purchasing that I don’t understand the reasons behind the decision.  My hat’s off to Kevin Systrom and the entire Instragram team though on a job well done.

Instragram has (at the time of this writing) about 30 million users from what I can gather from the web.  This is where the value is.

If you just want to make cool photos, in my opinion, Pixlromatic, has far more effects.  It comes with lots of options and allows you to vary not only the effects, but the frame and lighting independently.

Instragram currently has only a few of these features for modifying your photos.  However, unlike Pixlromatic, there’s a social network built into the app which you can share your photos with.  It’s like a mini-facebook for pictures, right inside the app.  I guess it’s a natural decision for Facebook to try to acquire them then, but a billion dollars is a lot of money.

Where Facebook goes with this is anyone’s guess.  They seem to say they’re going to keep it as a separate app, but if that’s the case, how do you monetize it?  Somehow you have to generate revenue.

Linking of Instragram and Facebook accounts would be one way of monetizing it.  Your Instagram “likes”, the people you’re following, and your followers give you insights into targeted advertisements back in Facebook land (even when a Friend relationship on Facebook may not be present).  Then again, you could probably figure this out without even explicitly linking the accounts.  If you were really resourceful, you could probably make educated guesses based on screen names, or face-recognition algorithms in the photos.  Even easier, you could just use the IP addresses of people using Instagram and Facebook and match’em up.  :)

You could also keep it as a separate “social network” of sorts and just put ads or ways to purchase items directly into Instagram.  This parallel social network to Facebook wouldn’t share any data with Facebook and would retain the nature of the two entities as separate businesses.

Either way, a company doesn’t make a purchase without reason, especially a billion dollar purchase.  It’s going to be very interesting to see what happens with Facebook and Instagram in the future.

# Early Morning Meetings

I’m not a fan of meetings, and I’m not a fan of getting up early. So if there’s one thing that I can’t stand, it’s an early morning meeting.

It’s 1:13 a.m. and I’ve got a 9 a.m. meeting tomorrow. That means I need to be up in less than 7 hours. Instead of sleeping (which may or may not happen in the next 2 hours), I’m going to write this article.

If you manage a team of software developers, don’t make your developers come in early. It’s a bad idea when you cause your workforce to be sleep-deprived. For example:

1.) Most developers are night owls.
Sure, I’ve known some really great developers that were early-birds, but most of your developers are going to enjoy programming late into the night. When you’re working on a problem, it’s often hard to put down, and this tends to beget a later and later schedule. The glow of the computer screen on your face doesn’t help put you to sleep either (I remember reading a study somewhere that said the light from the computer screen keeps people up). When you set an early morning meeting, you cause your developers to lose sleep.

2.) Tired developers are not as productive.
If you set your meetings later, your night-owl developers would come in well-rested and be more productive. I once had a manager tell me that “studies have shown people are more productive in the morning”. I’m not sure who they were interviewing, but as a developer I’m most productive between 7-9 p.m. If you consistently wake someone up, cutting off their REM time, you’re going to see a degradation in their performance eventually (usually about 4 hours after getting to work too early).

Some common objections:

OBJECTION 1: “Developers need to be in when everyone else is in to work with the team”

That’s true, so set some core hours. Make them reasonable though. Anything before 9 a.m. is unreasonable. Remember that.  My recommended core hours are 11 a.m. – 2 p.m.

OBJECTION 2: “such and such a time is not early”
To you. Circadian rhythms are subjective. You may have been getting up at 5:00 a.m. since you were in the military, but your developers have been staying up till 5:00 a.m. since they were in high school (not something I recommend doing).

OBJECTION 3: “Developers should re-adjust their schedule. Most of the world works at such and such hours”.

Even if your developers were coming in at noon, they would have no problem interfacing with whomever you needed them to interface with between the hours of 12-3, so I don’t really see how this applies.

# Compromise

In the end, it takes compromise on both sides.  The developers should be willing to come in a little earlier, and those who manage them should be willing to have them come in a little later.  If either side has complete control, then someone is going to get upset.  The number one thing is to make your work place enjoyable.  This can be accomplished if everyone is flexible.  Don’t think for a second though that any developer is going to hang around long if you act like a dictator and order them around.  They’ll be out of there faster than you can say dice.com.

# Using XAJAX with CodeIgniter

If you’re like me, you probably tried just including the php files per the learn xajax in 10 minutes docs and ended up getting some arcane error message in Firebug that reads “[Exception... "'[object Object]‘ when calling method: [nsIDOMEventListener::handleEvent]” nsresult: “0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)” location: “<unknown>” data: no] Line 0″

huh?  what am I supposed to do with that?  google turns up nothing… (which is why i’m adding it here)

hmm.. ok over to the CI docs on xajax and there’s an article ( http://codeigniter.com/wiki/XAJAX/ ) .  Perfect!

wait… what is that??  right there on the third line, that little “Note: This doc is obsolete”.  noooo!!

alright, maybe i can still pull this apart.. it kind of looks good, but it’s got a lot of what appears to be unecessary steps (like creating a library loader) and munging the view code into the controller.  i’d like to keep the view code in the view and i don’t need to be messing with library loaders.  let’s try something else:  XAJAX + CodeIgniter in 3… 2… 1…

Install XAJAX
into the funny CodeIgniter directory structure!

1. Download XAJAX Standard here: http://xajaxproject.org/en/download/ At the time of this writing, the most recent release is 0.5, but it shouldn’t matter much.
2. Unzip the zip file
3. Upload the xajax_0.5_standard/xajax_core folder to /www/system/application/xajax_0.5_standard/xajax_core
4. Upload the xajax_0.5_standard/xajax_js folder to /www/xajax_0.5_standard/xajax_js

I like to leave the version number in the folder names, otherwise, how will I remember a year from now if I need to upgrade?  Or what version to upgrade from?

Notice we had to put the xajax php code with the CI php code, and xajax looks for web stuff based on your url so we have to put it someplace web-accessible which is why we put it in our web root folder.  That’s the first tricky bit.  xajax is nice enough to pop up an error message letting you know if it can’t find the js files it needs (go xajax!  much appreciate that).  I had no need for the other xajax folders as I was just doing simple ajax requests, but i imagine that once you get this working, you can probably deduce where they might belong should a project require them.

You don’t have to do this, but I did because I think it makes upgrading to a later version of xajax that much easier. I defined the path in a constant by creating a util directory and constants.php file at /www/system/application/util/constants.php with the following code:

<?php
define ("XAJAX_FOLDER", "xajax_0.5_standard");
define ("XAJAX_PHP", APPPATH . XAJAX_FOLDER . '/xajax_core/xajax.inc.php');

I didn’t close my php tag on purpose. You < href="http://codeigniter.com/user_guide/general/styleguide.html#php_closing_tag" target="_blank">shouldn’t close your php tags. Remember that for your next job interview.

When I upgrade xajax later, all I’ll have to do is upload the new version, and change the XAJAX_FOLDER define and not touch any code.

Pick a controller.. any controller. You can have a special ajax controller, or I would recommend picking the controller for your view (makes sense right? a view requires ajax and its ajax requests are sent to its controller).

Add a constructor to the controller which will initialize xajax. For poipedia I have a controller class View defined in CI at controllers/view.php. The beginning of that controller looks like this:

<?php

require_once(APPPATH . 'util/constants.php');

require_once(XAJAX_PHP);

class View extends Controller {

private \$xajax = '';

function View() {
parent::Controller();
\$this->xajax = new xajax();
\$this->xajax->processRequest();
}

{
// Instantiate the xajaxResponse object
\$objResponse = new xajaxResponse();
// add a command to the response to assign the innerHTML attribute of
// the element with id="SomeElementId" to whatever the new content is
\$objResponse->assign("lnkFav","innerHTML", 'xajax response!');

//return the xajaxResponse object
return \$objResponse;
}

function poi(\$id)
{

\$data = array('xajax' => \$this->xajax,
'poi' => \$this->poi->getPoi(\$id),
'pictures' => \$this->picture->getPicturesForPoi(\$id),

}

Let’s break that down. The important steps are:

We initialize xajax in the constructor of the controller, and assign the xajax object to a class variable which we’ll pass to our view later
The php function we want to call via ajax is located in our controller (in this case “addFavorite”
The \$xajax class variable which was initialized by our constructor is passed to our view to be used by the view. (the first array assignment in \$data in the poi function–those other things like comments and pictures you probably won’t be using on your site. )

In my case the view I’m loading in the poi function is poiDetails.php at /system/application/views/poiDetails.php. Here’s the pertinent code from the view:

<?php
require_once(APPPATH . "util/constants.php");
// the sneaky bit.. tell xajax where to look for it's javascript files (web-accessible of course)
\$xajax->configure('javascript URI', base_url() . XAJAX_FOLDER );
// this is the name of your controller. my controller was class View in view.php
// so i have 'view' here.  what is your controller named?
// this is another very sneaky bit.  we don't let it decide its own URI because
// that only works if you are coming from the index() function in your
// controller!!
\$xajax->setRequestURI(site_url('view'));
// now print what we just configured
\$xajax->printJavascript();
?>
<!-- and finally a link to click on -->

Don’t forget the return false; after your xajax call and the # sign for the href value or your browser will take you to another page or jump to the top of the current page.

That’s it! There were a couple of sneaky things in there that took me forever to figure out, but hopefully I’ve saved you some measure of the pain I know.

Posted in PHP

# iPhone SDK – How to determine if an NSString is numeric

I was working with the iPhone SDK and needed to determine if an NSString was numeric. After a lot of searching I came up with this function that doesn’t rely on any third party libraries. It uses the numberFromString function from the built-in NSNumberFormatter. Feel free to use it in your applications.

/*
Returns whether or not an NSString represents a numeric value.
*/
-(bool) isNumeric:(NSString*) checkText
{

NSNumberFormatter* numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];

NSNumber* number = [numberFormatter numberFromString:checkText];

if (number != nil) {
NSLog(@"%@ is numeric", checkText);
return true;
}

NSLog(@"%@ is not numeric", checkText);
return false;
}

You can invoke it like:

[self isNumeric:@"2"];
[self isNumeric:@"2.0"];
[self isNumeric:@"4"];
[self isNumeric:@"-1"];
[self isNumeric:@"asdf"];

and it will return output like:

2009-10-09 10:27:03.656 App[16351:207] 2 is numeric
2009-10-09 10:27:03.658 App[16351:207] 2.0 is numeric
2009-10-09 10:27:03.659 App[16351:207] 4 is numeric
2009-10-09 10:27:03.659 App[16351:207] -1 is numeric
2009-10-09 10:27:03.660 App[16351:207] asdf is not numeric

Don’t forget to declare the prototype in your .h file:

-(bool) isNumeric:(NSString*) checkText;

Enjoy!

# Rounding a number

This is an oldie but goodie. One of the first programming problems students run into is “How do I round a number?”  I had this question once too, and here’s the answer:

1.)  Add 0.5 to the number

2.)  Typecast to an integer.

In code this looks like:

double x = 12345.6789
int y = (int) (x + 0.5);

Hope this helps!