To Top

Our Blog

Guru Technologies

Return JSONP with CakePHP

Here’s a nice way to turn on JSONP for CakePHP. JSONP, or JSON with padding, is necessary when you want to include JSON from a site different than the one you’re on.

A good explanation for what JSONP is can be found here:

Just include this code on any CakePHP controller that you will be using with JSONP (or you could put it in the AppController to make it work everywhere in your app but that may add a slight performance hit). It checks to make sure that JSON is being returned before trying to apply the padding. This code overrides the afterFilter() which is the last controller action CakePHP does after doing rendering.

    // This funciton makes so JSONP works
    public function afterFilter() {

      if (empty($this->request->query['callback']) || $this->response->type() != 'application/json') {

      // jsonp response
      App::uses('Sanitize', 'Utility');
      $callbackFuncName = Sanitize::clean($this->request->query['callback']);
      $out = $this->response->body();
      $out = sprintf("%s(%s)", $callbackFuncName, $out);

Web browser text search

So I am working on a project where I have to search some HTML documents for a possible text string. This lead me to an interesting find in how browsers do searching on text.


Let’s look at the following HTML.

<div style="background-color: #00ff00;">Hello ther</div>
<div style="background-color: #ff0000;">e,
<span style="background-color: #f0ff00;">bob</span> how are</div>
<div style="background-color: #00ff00;">you?</div>

The text displays as the following: Text displayed in a browser

The yellow represents the inner span. The divs are different colors to show their distinction.

If you search for the text “Hello there” no results will be found as the browser does not search across div elements.

If you search for the text “e, bob how are” the text will be found as the browser will search across span elements.

It’s interesting to note that the browser’s search works only across defaulted inline elements but not elements set inline by the html.

Find out what Subversion commits haven’t been merged to stable

We frequently use Subversion for version control, and use /trunk to commit all code in active development and merge code to a stable branch that represents what is currently on a production server.

Sometimes commits need to be done right away, so you merge them right away; others can wait until you do a push.  After developing a while with regular commits to trunk, you can have a state where several commits in trunk may already be in the stable branch while others aren’t.  When you’re ready to push a group of commits to stable or do a full release of everything from trunk to stable, it’s helpful to know which commits haven’t been merged to your stable branch yet.

Here’s a bash script that will show you the details of everything in trunk that hasn’t been merged to stable:

for i in `svn mergeinfo --show-revs eligible svn://server/project/trunk svn://server/project/branches/stable | cut -c 2-`
svn log -c $i svn://server/project/trunk
done | less

The magic here is the “svn merginfo –show-revs eligible”.  Very useful.

Using nullmailer as a simple MTA

nullmailer is a very simple MTA I like to use on Linux servers when I don’t want to have a lot of hassle with mail server configuration.

It will automatically send all local mail to one of my email addresses by simply installing it and configuring two files.  The /etc/nullmailer/remotes I put in my smtp server.  Here is an example: smtp --pass=examplepassword

For /etc/nullmailer/adminaddr I put the following:

All mail delivered to, say, the local root account automatically gets sent to the email address put in the adminaddr file.  Simple and convenient.

Troubleshooting is also simple.  When the email is still in queue, you can see it with command mailq.  It will also show where it’s going to be delivered.  Logs can be found in /var/log/mail.log and /var/log/mail.err

One thing I’ve noticed is you’ve got to get your hostnames right.  Make sure /etc/mailname has the fully qualified domain name in it.  I had an issue when the hostname on the machine (/etc/hostname) was the same as the /etc/mailname.

Does Your Business Need a Mobile App?

As a business owner you may be asking yourself this question when it seems like the whole world is going mobile. There are some key points to consider in order to answer this question for your company.

The first thing to consider is your audience. What does your typical consumer look like? Nielson released a study in January 2012 with a sample of 20,000 consumers on reported smartphone ownership. The percent in each category is as follows:

  • 66% of 25-34 year olds
  • 54% of 18-24 year olds
  • 53% of 35-44 year olds

If your target audience is not in these age groups, you may not want to proceed with an app. However, if your audience is in a saturated bracket, consider if you have a following or would be able to create one with a little work. One thing to try before investing in a mobile app would be to create an online presence through a website and Facebook. Would your company be able to use an app to “push” products and services to your followers? Would a mobile app give you a competitive advantage?

Google released some other interesting data to consider:

  • Mobile searches have increased 4X since 2010, to over 100 billion mobile searches in 2011. Consumers are looking for information directly from their smartphones, often about local businesses, where to go and what to do.
  • 36% of all restaurant searches are done on the mobile phone.
  • 70% of smartphone users use their device while shopping in-store
  • 53% of searchers purchase as a result of a smartphone search
  • 95% of smartphone users have searched for local information
  • As a result of looking for local information, 77% contact a business and 44% purchased
  • By 2013, more people will use their mobile phones than PCs to get online

Does your business have the capability to benefit from this type of use to enhance shopping experiences, promote products or fill time-slots?

The last point to consider would be budget. Development costs can vary greatly depending on the complexity of the app. Meet with a development team to determine what functionality would be necessary and to craft the most useful tool for your business so your company’s costs will be returned exponentially.

Gaming to Grow Your Business

The Economist says “video games will be the fastest growing and most exciting form of mass media over the coming decade.” But why should that excitement end there? Businesses across the board are finding they can use the same idea, and the same audience, to increase business.

Today there are more than 180 million gamers of all ages in the US, and over 40 percent are female. Smartphones are adding to this increased audience. An example of merging business interests with gaming enthusiasm would be a new campaign by the Utah Division of Emergency Management and the Centers for Disease Control and Prevention which plans to capitalize on the recent rise in popularity of all things zombie. They are centering their new campaigns around “everyone’s favorite monster” in hopes of bringing increased attention to their cause and attendance to their events.

This same use of a modern gaming audience can be applied for business use in trainings, advertising, simulation or education. If you are looking for that extra something to bring attention to your business, business mobile app or desktop application, think about the possibilities of a gaming format.

References: Bloomberg Businessweek August 27-September 2 issue,, The Economist

Html5 Audio restart playback in iOS Safari

When using html5 audio and Apple’s safari browser on iOS there is a problem that occurs when you try to set the audio’s time.

Html5 audio DOM object has an attribute called currentTime. This unfortunately isn’t available in iOS safari. This makes it difficult if you want to start the audio from the beginning.

An example code like this:

if($('#audio_' + id)[0].currentTime != undefined)
	$('#audio_' + id)[0].currentTime = 0;

will throw an exception.

There is an easy way around this problem and that is by removing the audio element from the DOM and then re-adding it.

Here is my code:

var audio = $('#audio_' + id).clone();
var parent = $('#audio_' + id).parent();
$('#audio_' + id).remove();

Post in the comments below if this has helped you in developing html5 audio in safari. Any questions are also welcome.

New mobile app – Vinny

We are excited to showcase a fantastic new mobile app we have helped develop. This app is still in beta but will be released soon!

Did you ever wonder what the dealer really paid for that car on the lot?

Check out Vinny, a new app that tells you the exact wholesale cost by simply scanning the VIN barcode. The creators of this idea put together a video highlighting how the new app works:

We created this app using PHP, Mongo DB datasource for Cakephp, and JQuery Mobile.

Automatic and Secure rsync over SSH

Let’s you want to set up an automatic rsync over ssh to a remote server, but you want to do it in a secure way.

Using rsync over ssh is a convenient way to have all of the power of rsync for synchronizing files, comparing differences, doing backups, without having to set up an rsync server.

Here is an example of using rsync in this manner, which will make the destination match the source exactly:

 rsync -a --delete -e "ssh" SOURCE DESTINATION 

The problem is this won’t be automatic because ssh will prompt you for your ssh username and password. That means you can’t use rsync in a script, such as a cron job. To get around this, you can set up an ssh key and copy that to the remote server. To do this, you have to set up an ssh key and copy it to the remote server. This is done by running ssh-keygen, and then leaving the passphrase field empty when it prompts you:

username@local-server:~$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/
The key fingerprint is:
bc:ff:a0:c6:f3:33:36:c2:3a:9b:19:20:22:a4:a1:f8 username@local-server
The key's randomart image is:

Then you normally copy the contents of the /home/username/.ssh/ file to the /home/username/.ssh/authorized_keys file on the remote server you want your rsync to be able to access.

You can test this by then using ssh with your new key:

 ssh username@remote -i /home/username/.ssh/id_rsa

If that works, your ssh key is working. (If you leave off the -i PATH_TO_KEY option, it will work if the key is named with the defaults).

This method works fine, except it isn’t secure. If anyone gets ahold of your private key, they will also have full access to your account on the remote server without any password required. To make it more secure, you can take advantage of the ssh feature that limits you to one command.

The best way to do this, is to find out exactly what command rsync runs on the remote server when it runs. To do this, run your rsync with -vv, turning on very verbose mode:

 rsync -a -vv --delete -e "ssh -i /home/USERNAME/.ssh/rsync_id_rsa" SOURCE DESTINATION 

Then look at the first line rsync returns. It should be something like:

opening connection using: ssh -p 4022 -l username remote-server rsync --server --sender -vvlogDtpre.iLsf . /var/www

What you are interested in, is the rsync command and everything after it. In this case:

rsync --server --sender -vvlogDtpre.iLsf . /var/www

On the remote server, find the line where you copied your ssh key in the /home/username/.ssh/authorized_keys file and prepend this specific command to it in the “command” section. For good measure, you can include other security features. Here is an example:

command="rsync --server --sender -vvlogDtpre.iLsf . /var/www",no-port-forwarding,no-pty,no-agent-forwarding ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDs/DqwIOWrf6K8yUPOMx22jx2vDTnXa9HvAobK1gw5I0Dx/z/HJdr7s2Iopcb7kdEBRJ9xQKWvc6lvdtdxDmSXc7a5WWjV9/2IaZGpJC0GDw79 username@local-server

Keep in mind that the whole thing needs to be on one line, or if you need to put it on more than one line, use the \ character at the end of each line.

That will make so only that specific rsync command can run, thereby securing your rsync connection.

Call out to Early Adapters: Could Smart Stickers Add Value to Your Business?

Smart stickers, or programmable tags, are low-cost pieces of paper or plastic that can communicate with gadgets via a short-range radio technology called near field communication, or NFC. They can be customized to trigger an action on any phone with an NFC chip. According to IHS iSuppli, 186 million NFC-enabled phones will be shipped in 2012, up from 93 million last year. The tags can be purchased through various websites; either bare-bones for a few dollars a piece or $20 or more dollars a piece for tags pre-programmed to do a specific task. Amazon is soon expected to offer the tags with varying program options.

The business potential for smart stickers is tremendous. Use of these stickers is a fresh and intuitive way to attrack smart phone users. Smart Stickers can be attached to shop windows or doors for an eye-catching ‘call to action’ to engage consumers. Smartphone users can ‘tap’ their mobile phone to retrieve details of a property from real estate agents, download a restaurant’s menu, call a taxi or claim an incentive voucher relating to a window advertisement even when the business is closed. The possibilities are only limited by a business’s imagination.

Guru technologies already has the know-how to program Smart Stickers. We are looking forward to opportunities to work with companies on the cutting edge, looking for innovative ways to market to customers.

Source information:

  • Bloomberg Businessweek July 16-July 22, 2012 issue “Plastering the World with Smart Stickers”