The Discussion Delegate

Answers to the Ultimate Questions about the Web, Mobile and Vercingetorix

 

When you get some time off make some wallpapers!

This post was created on March 10th, 2010 by abhinit and has 0 comments. It has been filed under , , , ,

Between frantic coding sessions, making sense of emails, staring at the screen and chasing tyrannosauruses around the Office I get sometime off. When that happens, I launch Pixelmator, make sure no one around is paying any attention, and make wallpapers.

Here are some of them. Most of them took a few minutes to make. No, really!!

PS: Pixelmator is an awesome image editor.

Popularity: 15%

Open up your Mac Mini!

This post was created on February 5th, 2010 by Sudhanshu and has 0 comments. It has been filed under , ,

Among the many joys of running your own company, a certainly interesting one is the ability to open up stuff once the hardware stops working.

A weird accident yesterday left our Mac Mini a little zonked out and it just refused to power up. When there was no hope left that we would see it working anytime soon (The Apple Store takes 4 days to update an OS, this would have certainly taken up a month to fix), we decided to open this thing up. I realize that a hundred thousand people have done this before, but this was certainly the first time we opened up the little monster.

Here is what it look like, once you open it up.

Not that any good came of it though (we’re looking for somebody who can fix it now!), but we were able to appreciate the inner beauty of tiny piece of hardware evolved by Apple. Maybe it will provide the inspiration for us to do something that has never been done before.

Popularity: 33%

Push Notifications in your iPhone App using PHP and Ubuntu

This post was created on February 3rd, 2010 by Sudhanshu and has 1 comment. It has been filed under , , , , ,

Push Notifications have been around for quite some time now, but when we started on it, we found out that we were unable to find all the information about creating a demo in one place. After a few hours, we were able to get it to work. Here is what we did.

Basically, the code on your server needs to talk to the Apple Push Notification Service (APNS) to send the messages, and the APNS then delivers them to your phone. We will only provide the code level details here to help you carry out the same on your server.

Basic Idea

You need to do the following to get your application to send push notifications

1. Make your application accept Push Notifications
2. Create a SSL certificate for your server which will allow it to talk to the APNS
3. Create the payload for each message to be send to the APNS
4. Send all the payloads one by one to the APNS

Even if you have already been into iPhone development for sometime, you might not be aware of the ‘DevToken’. This is a uniquely generated token for your iPhone application on a particular phone. It can keep changing over time for a particular phone as well, but it is the unique id that will help you send a message to a particular application on a particular phone.

This is what it looks like on our phone

4d3d32e4 c1beebd2 f3a6bc85 3f7d12b9 abc156b4 26818ecf 9673a712 85e01adc

This is what you need to do to get your device token.

// Delegation methods
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
 
  //RegisteringforRemoteNotifications
  NSLog(@"%@ \n %@", deviceToken, [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding]);
 
}

Getting the certificates in place

Reach for your mac and start doing the following

1. Login to the iPhone Developer Connection Portal and click on App Ids.

2. Create an AppId for your application witouth a wildcard. It should be something like this :

com.vxtindia.PushSample

3. Click configure and then go ahead and create a certificate for Push Notifications.[1]. Download it once it has been created.

4. Import the newly created certificate into your keychain by double clicking it.

5. Launch ‘Keychain Assistant’ and filter it by the Certificate’s category. There you should see a ‘Apple Development Push Services’ option. Expand it, right click on it and click on ‘Export …’ and save this as apns-dev-cert.p12 . Also download the private key as apns-dev-key.p12

6. Copy the file apns-dev-cert.p12 to your server in the folder where you will put the rest of your PHP code.

7. Now run the following code on the server
openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12

We are running everything from a server running Ubuntu-9.04. Here we had to remove the passphrase, which can be done as follows
openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem

Finally, combine the two to get your apns-dev.pem file
cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem

8. You need to create a payload and send it to the APNS server. You can use the following code to do so
// Create a stream to the server
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'apns-dev.pem');
 
$apns = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);
 
// You can access the errors using the variables $error and $errorString
$message = 'You have just pushed data via APNS';
 
// Now we need to create JSON which can be sent to APNS
$load = array( 'aps' => array( 'alert' => $message, 'badge' => 1, 'sound' => 'default'));
$payload = json_encode($load);
 
// The payload needs to be packed before it can be sent
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $token)) . chr(0) . chr(strlen($payload)) . $payload;
 
// Write the payload to the APNS
fwrite($apns, $apnsMessage);
echo "just wrote " . $payload;
 
// Close the connection
fclose($apns);

9. Great work! You have just pushed a message to the APNS which will now be delivered to a phone running your application.

10. (Optional) Apple also provides a Feedback service (which doesn’t do anything that you would expect). This service tells you when was the last time that APNS failed to find your application on a specific phone. When this happens, you need to stop sending updates to that Device Token.

To assist you in your endeavors, here is the code to help you read this data
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'apns-dev.pem');
 
$apns = stream_socket_client('ssl://feedback.sandbox.push.apple.com:2196', $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);
 
if($apns) {
  while ($data = fread($apns, 38)) {
    $feedback = unpack("N1timestamp/n1length/H*devtoken", $data);
    echo "Sent message at " . date("r", $feedback['timestamp']) . " with length " . $feedback['length'] . " to token " . $feedback['devtoken'];
  }
  fclose($fp);
}

That’s it. You are now officially a pro at push notifications!

References :
1. Apple’s Documentation
2. BoxedIce

Popularity: 100%

ConnectingIndia has a new address

This post was created on June 18th, 2009 by Sudhanshu and has 0 comments. It has been filed under , , , , , , ,

Connecting India

Connecting India is a Pune based NGO dedicated to suicide prevention in youth. Its team of dedicated volunteers and concerned citizens are dedicated to serve the community through its various programs, seminars and especially through its Suicide Prevention Helpline to support individuals dealing with emotional stress.

Connecting India was starting a number of new initiatives and wanted a new website which would reflect the dynamism in the organization. We working in collaboration with Stradicate to help create the new design and interface. Stradicate worked on the design and we developed and hosted the website.

If you would like to make a difference, and you are above 21 years of age, please get in touch with Connecting India on +91-20-26333044. Their helpline operates from 2pm to 8pm and they also provide training to volunteers who qualify for the program.

If you are an NGO and are looking for a similar solution, do get in touch with us.

Popularity: 29%

Another iPhone application reaches the App Store

This post was created on June 11th, 2009 by Sudhanshu and has 0 comments. It has been filed under , ,

fruition-on-app-store

Our second iPhone application is now live at the App Store. We worked with Iterating on this one, and after a few months of hard work, it has finally reached the AppStore.

More details are available on the Iterating Blog and it can also be seen on the App Store.

Even though the app is free, the only catch is that you need to own a few vineyards to actually use this application!

Popularity: 29%

Get emails from SVN on commit

This post was created on June 3rd, 2009 by admin and has 1 comment. It has been filed under , , , , , ,

We have been using SVN for a couple of years for all of our projects. Initially we were hosting them at Springloops.com for almost a year, when we decided to start hosting them on our own server.

It all sounded really good, till we realized that code reviews became a real problem. Springloops had a stunning interface to compare the diffs and get all the related information, which we really missed.

So we decided to use the post-commit hooks in SVN to email us as soon as a commit was made.

If you would like to implement the same for your server, here is a quick and dirty guide on how to do that.

First, the details about our server

# svn --version
svn, version 1.5.1 (r32289)
compiled Jul 31 2008, 09:45:20

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 8.10
Release: 8.10
Codename: intrepid

Okay, so let us get started. The first thing that you should know is that inside your repository, SVN creates a folder called hooks. This folder initially contains template files for all the hooks that can be called via SVN. The hook that we are after today, is called post-commit.tmpl

Since our language of preference is PHP, we decided to call a php script as soon as a commit was done on that repository. Here is how we did it

# cd /path/to/repo/hooks
# mv post-commit.tmpl post-commit
# chmod 755 post-commit
# vi post-commit

The post-commit file contains the following

#!/bin/sh

REPOS="$1"
REV="$2"

php /svn/scripts/postCommitHook.php $REPOS $REV

The above steps can also be automated by writing another php script which would copy all our hooks from a base directory into the respective directories in the repositories. Here is what our script looks like

$hooks_dir = '/svn/hooks/';
$repos_dir = '/svn/svn.localhost/';
$repo_hook_dir = $repos_dir . '__REPO__/hooks/';

if($hooks = opendir($hooks_dir)) {
  while(($hook = readdir($hooks)) !== false) {
   $unwanted = array('.', '..');
   if(!in_array($hook, $unwanted)) {
    if($repos = opendir($repos_dir)) {
     while(($repo = readdir($repos)) !== false) {
      if(!in_array($repo, $unwanted) && is_dir(repoPath($repo))) {
       if(!copy($hooks_dir . $hook, repoPath($repo) . $hook)) {
        echo "Could not copy " . $hooks_dir . $hook . " to " . repoPath($repo) . "\n";
       }
       if(!chmod(repoPath($repo) . $hook, 0755)) {
        echo "Could not chmod " . repoPath($repo) . $repo . "\n";
       }
      }
     }
     closedir($hooks);
    }
   }
  }
  closedir($hooks);
}

function repoPath($repo) {
  global $repo_hook_dir;
  return str_replace('__REPO__', $repo, $repo_hook_dir);
}

Finally, we need to create the file postCommitHook.php which will find out all the relevant information and mail you the details. We have used svnlook and phpmailer to get all the information. Here is what our postCommitHook.php looks like

function getRepoName($repo) {
  return strtoupper(str_replace('/', '', str_replace('/svn/svn.localhost/', '', $repo)));
}

require_once('phpmail/class.phpmailer.php');

$repository = isset($argv[1]) ? $argv[1] : '';
$revision = isset($argv[2]) ? $argv[2] : '';

$author = strtoupper(exec('svnlook author ' . $repository));
$changed = exec('svnlook changed ' . $repository);
$comments = exec('svnlook log ' . $repository);

$diff = '';
$fp = popen('svnlook diff ' . $repository, "r");
while(!feof($fp)) {
  $diff .= fread($fp, 1024);
  flush();
}
pclose($fp);

$body = "Hi,\n\n$author has just committed revision $revision in " . getRepoName($repository) . " and said \n\n$comments.\n\n\n\nThe following files have changed :\n\n$changed \n\n\n\nThe changelog is given below $diff";

$mail = new PHPMailer();
$mail->From = 'svn@localhost';
$mail->FromName = 'SVN Server';
$mail->AddAddress('repo.admin@localhost', 'Repo Admin');

$mail->Subject = 'SVN Commit - ' . getRepoName($repository) . ' - Revision ' . $revision;
$mail->Body = $body;

if(!$mail->Send()) {
  echo "Error sending: " . $mail->ErrorInfo;;
}

And that is it!

Once the scripts are in place, just run copyHooks.php once and then whenever anybody commits on any of your repositories, you will get an elaborate email with the diff.

Popularity: 36%

Fixing the performance issues

This post was created on May 30th, 2009 by Sudhanshu and has 0 comments. It has been filed under ,

While iterating through the archives of Daring Fireball, I came across an interesting policy from the WebKit team.

The way to make a program faster is to never let it get slower.

We have a zero-tolerance policy for performance regressions. If a patch lands that regresses performance according to our benchmarks, then the person responsible must either back the patch out of the tree or drop everything immediately and fix the regression.

Common excuses people give when they regress performance are, “But the new way is cleaner!” or “The new way is more correct.” We don’t care. No performance regressions are allowed, regardless of the reason. There is no justification for regressing performance. None.

I hope someday the Firefox dev-team working on Linux also gets to fixing their performance issues. There is not one decent web browser for Linux and I don’t see any company coming out with anything interesting with it.

Popularity: 31%