Sending GPS coordinates through url using Symfony 1.4

I’ve been developing an API using Symfony 1.4.18 version and I’ve noticed that you can’t send “dots” as part of the url.
Basically if you have something like this in your routing.yml:

checkin_hotel:
 url: /checkin/hotel/:minLon/:minLat/:maxLon/:maxLat
 param: { module: service, action: checkin, type: hotel }

and you try to call this url:

http://myurl/checkin/hotel/-9.15794/39.34242/-8.95677/42.34532

This wont work!

This happens because by default symfony interpret “.” and “/” as separators and so the route “checkin_hotel” wont be called.

To fix this you should specify directly that it should only use “/” as separator:

checkin_hotel:
 url: /checkin/hotel/:minLon/:minLat/:maxLon/:maxLat
 param: { module: service, action: checkin, type: hotel }
 options:
   segment_separators: [/]

Best regards,
Daniel Botelho

Blackberry Javascript Extension using an external library

I have a BlackBerry WebWorks project that needed to use Omniture reporting. Since Omniture already have an library for BlackBerry, I’ve decided to create an JavaScript Ext that would expose that functionality to the web application.

The only thing that you need to do differently from creating another regular JS Ext is that you need to include a new “<dependencies>” tag in the library.xml file, with the relative location of the external library.
Here it’s the example:

<library>
  <extension>
   <entryClass>xxx</entryClass>
  </extension>
  <features>
   <feature id="xxx" version="1.0.0" >XXX</feature>
  </features>
  <dependencies>
   <jar path="omni.jar" />
  </dependencies>
 </library>

Android Simulator/Emulator: Delete directory

One thing maybe (or maybe not) you’ve noticed is that you can’t delete an entire directory using DDMS on eclipse.

To be able to delete a directory on simulator sd card you can use the ADB command and connect to device via shell.

The first thing to do, is to go to “<android-sdk-PATH>/platform-tools” and from there type:

./adb devices

Then connect via shell to the device that you want:

./adb -s emulator-5554 shell

Now you’ve connected to the device “emulator-5554″  and now you can remove the files or directories that you want!

Protect your clients: Save hashed passwords in your database!

I’m always surprised when I open my Feed reader and over and over again I stumble upon another report saying that some website store users passwords in plain text and that those passwords got exposed.

Now, why do you need to store those passwords in plain text?

Just hash them in the database and when some user tries to login into your site, hash the password that he gave you and try to match it with the one that is stored in database.

Now if someone cracks your database security the users will not be harmed because they don’t get access to theirs passwords (at least in plain text)!

If you want to add an extra protection, append a “salt” string to the users password and hash the new string all together. (This is how it’s done in symfony sfGuardPlugin http://trac.symfony-project.org/browser/plugins/sfGuardPlugin/lib/model/sfGuardUser.php?rev=3980#L31)

Parsing XML namespace elements with jQuery

Let’s assume that we have loaded through AJAX an XML file and we wanted to parse a XML element “artist” with the namespace “palcoprincipal” to get the Artist name:


<palcoprincipal:artist>Cool Artist </palcoprincipal:artist>

You may be tempted to parse it like this:

$(xml_string).find(‘palcoprincipal:artist’).text()

but it won’t work.
The correct way (and multi-browser-way) is like this:

$(xml_string).find(‘[nodeName=palcoprincipal:artist]’).text()

How to add a new user to a vsftpd server

Assuming that you already have the vsftpd installed and configured, to create a new ftp user with an home directory you just need to use this commands.

The first thing you need  to do is to create an FTP root directory:

# mkdir <path_directory>

Then you should create an user and make the <path_directory> the user’s home directory:

# useradd -d <path_directory> <ftp_new_user>

Then add a password to the newly created user

# passwd <ftp_new_user>

Add <path_directory> permissions:

# chown <ftp_new_user> <path_directory>

# chmod 0744 <path_directory>

Restart the server:

# /etc/init.d/vsftpd restart

And it’s done!

Now you can access to this ftp account using the <ftp_new_user>

Subclipse 1.4.7 in Eclipse 3.4 (Ganymede) using Ubuntu 8.10

Since I’ve made a Fresh Ubuntu install in my laptop, now I’ve to setup the environment so I can do some working in the laptop ;)

The company that I’m working now only uses PHP, so the production IDE that I use is Eclipse PDT. The great thing about Eclipse, is it’s huge plugin repository, and the one that’ll be talking here is the Subclipse.

Subeclipse is on 1.4.7 version and it’s a great SVN plugin (the only one I know ;)).

Installation Instructions

This installation instructions are based on Download and Install with the difference that here I’ll be showing Subclipse installation process for Eclipse 3.4 (Ganymede) and screens were captured in Eclipse 3.4.0 running on Ubuntu 8.10.

Step 1:

Begin the installation from the Eclipse Help menu item.

Software Updates
Software Updates

Step 2:

This screen will vary depending on the features you have installed already. You want to click on the New Remote Site button. If you are behind a proxy and the Eclipse install mechanism does not work, then you can download a zipped version of the update site and then click the New Local Site button instead.

Software Updates and Add-ons
Software Updates and Add-ons

Step 3:

This screen is showing the Add Site dialog, filled in with the correct information to install Subclipse 1.4.7 (url: http://subclipse.tigris.org/update_1.4.x)

Add Site
Add Site

Step 4:

When you first come back to this screen, the site you added will NOT be selected. Be sure to select it before clicking Next.

Install
Install

Step 5:

This next screen shows all of the features that are available to install.

Confirm Install
Confirm Install

Step 6:

Click the button to accept the license agreement.

Confirm
Confirm

Step 7:

Eclipse needs to be restarted after installing Subclipse.

Restart
Restart

Step 8:

Finally, after restarting Eclipse, you can do Import and checkout a Project from SVN

Import
Import

“Multithreading” with Bash script

Actually is not Multithreading, but the ability to run scripts in parallel and synchronization also ;)

In Linux systems each process has an associated “process identification number” (PID) that you can monitor using the “ps” application. If you want to run a process in background you just need to append the caracter “&” to the command and it will free the console for you.

So basically the script below, executes commands, gathering all PIDs and in the end it waits for them to finish:

#!/bin/bash

function jobidfromstring()
{
local STRING;
local RET;

STRING=$1;
RET=”$(echo $STRING | sed ‘s/^[^0-9]*//’ | sed ‘s/[^0-9].*$//’)”

echo $RET;
}
runmultitask()
{
JOBLIST=””
TASKLIST[0]=””
i=0

for TASK in “$@”
do
$TASK &
LASTJOB=`jobidfromstring $(jobs %%)`
JOBLIST=”$JOBLIST $LASTJOB”
TASKLIST[$i]=$TASK
i=$(($i+1))
done

i=0
for JOB in $JOBLIST ; do
wait %$JOB
echo “${TASKLIST[$i]} – Job $JOB exited with status $?”
i=$(($i+1))
done
}

runmultitask “your parallel” “your parallel”