Archive for the ‘Tips’ Category

Django is an excellent web-framework written in Python.

Here is a quick setup guide for installing Django and MySQL-python on Mac OS X Lion.

Setup Django

– Download latest Django here

– At this point I am assuming that you are familiar with the Terminal, so simply execute the following commands on your Downloads folder:

tar -xzvf Django-1.3.1.tar.gz
cd Django-1.3.1
sudo python setup.py install

Test Django installation

Type on the Terminal:

import django
print django.get_version()

Setup MySQL-python package

Download the latest MySQL (64-bit, tar archive) here

– Extract tar contents
– Rename folder to “mysql”
– Copy folder to /usr/local/
– You should now have mysql installed on /usr/local/mysql

Download the latest MySQL-python package here

Type on the Terminal:

tar -xvzf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3

Edit site.cfg on your favorite text editor and change the mysql path as below: mysql_config = /usr/local/mysql/bin/mysql_config

You are now ready to build and install MySQL-python:

sudo python setup.py build
sudo python setup.py install

Edit your ~/.bash_profile, add the following line:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

If you are already using MAMP you still have to follow the above MySQL installation process, as MAMP by default doesn’t include the required header files to build MySQL-python.
Moreover if you prefer MAMP, you don’t have to run mysql from /usr/local/mysql.
On your settings.py remember to set “” as your preferred db host in case that “localhost” doesn’t work.

Test MySQL-python installation

Restart Terminal and type:

import MySQLdb

If you are not getting any errors at this point, then you are all good to go!
I’d suggest starting from the Django’s excellent introductory tutorial.

Read Full Post »

PHP: How to json_encode numbers properly

Here is a handy tip about PHP’s json_encode function.

In some cases numeric data may  appear as numeric strings, for example 1 as “1”. While consuming the json data on a client app that would mean an extra parsing to get for example an int from the string.

The solution is to simply use an extra option (JSON_NUMERIC_CHECK) on the json_encode function call:

<?php echo json_encode($data, JSON_NUMERIC_CHECK); ?>

I have to point out that this option requires a PHP version of 5.3.3 or higher.

Read Full Post »

Everyday more and more developers are switching to a Mac for development. For instance take a look at photos taken from the recent Google IO 2011 event, MBPs are everywhere. I am writing this post to help future or current Mac developers, so here is the list of my coding tools of the trade on the Mac. Please leave a comment if you find one of the following apps useful, or have alternative apps/solutions!

1. iOS (iPhone/iPad) and Mac development
For iOS and Mac coding Xcode is the ultimate tool. Xcode 4 has a really intuitive interface, compacts everything (code editor, UI editor etc) on a single window, supports tabs, and lot more. If you enrol on an Apple developer program, then you can get it for free, else you can find it on the Mac app store for 3.99€.

2. HTML/PHP/JavaScript/jQuery

For HTML/PHP/JavaScript/jQuery web projects I prefer Komodo Edit. Komodo Edit is a cross-platform (runs on Mac, Linux, Windows) editor, offering autocomplete syntax, project management, integrated file browser. I really enjoy the fast search (or search and replace) functionality. Hardcore users can even use VIM shortcuts. Have I mentioned that it is completely free? Yeap, and you can even code in Python, Ruby and more.

3. Java

For Java projects I choose Eclipse over NetBeans. I am not going to compare those two on this post, I am just more comfortable with Eclipse, Google provides official plugins for Eclipse (GWT, App Engine, Android). Both of them are free, and come in lots of flavors depending on the type of projects you want to develop.

4. Single file code viewing/editing
Sometimes you just have to quickly view or edit a single file. For this purpose TextWrangler  always comes in handy. I have previously reviewed TextWrangler as the best alternative to Notepad++ for Mac OS X. TextWrangler is free and available on the Mac App Store.

5. Source control

Every coding project should be under source control. I am a Git fan, managing it only via the terminal. Git is a free and super fast distributed source control system. You can also find valuable open source projects online at GitHub.

6. Apache/MySQL/PHP environment

For setting up an Apache/MySQL/PHP environment, the easiest solution is to install MAMP. Although you can individually setup Apache, MySQL, and PHP on the Mac OS, MAMP keeps everything in a single place. MAMP allows you to single-click start Apache/MySQL services using a widget. Of course you have full access to the httpd/php/mysql configuration files, you can install plugins, tweak etc. MySQL can be directly managed from the bundled phpMyAdmin. MAMP behaves like a regular app, meaning that you can uninstall it via a single drag and drop operation.

7. FTP/S3 file transfers
For  FTP/S3 file transfer purposes I have recently switched to Transmit. Transmit provides fast and reliable file transfers, easy favorites/bookmarks site management, and a dual-pane interface. You can buy Transmit via the Mac App Store for 26.99€, or purchase additional licenses via their website.

8. SQLite manager
SQLite databases can be accessed via a Firefox plugin called SQLite Manager.  SQLite Manager has a simple UI for running SQL queries, importing/exporting data, and managing your database. Free.

Read Full Post »

Eclipse is an excellent IDE, however some of its preferences may not be that straight-forward.

On one of my recent Java projects I had to work with a character encoding other than the default ANSI encoding.
Thus, I managed to set up the database connection properly to use the required UTF-8 encoding, as well as handle the returned data correctly as UTF-8 in the Java code.
When I tried to output some of the data, for logging purposes, in the console, the output couldn’t not be read correctly. The first thought was to double-check the source code, connection properties etc, and despite the fact that everything looked just fine, the console output still was unreadable.

After spending some time trying to find a relevant option in Eclipse, I stumbled upon the “Common” tab in the Configurations panel. And indeed this is where I found the answer to the encoding problem!

Here is what you have got to do if you are having a similar issue:

(Current setup is Eclipse Galileo – 3.5 on Mac OS X Snow Leopard)

Go to Run -> Run Configurations…

Create or select an existing configuration for your project, and switch to the “Common” tab.

Choose you preferred Console Encoding as shown on the image above!

Read Full Post »

Recently I had to setup a Java app on my Mac, which was running from the Terminal, and needed the JAVA_HOME variable set.

Here’s what had to be done:

– Start the Terminal app.
– Create/Edit ~/.bash_profile file.
Note: I first tried creating and using the ~/.bashrc file, but that didn’t work (Mac OS 10.6.2), while ~/.bash_profile worked as expected.


$ vi ~/.bash_profile

… and paste the following (make it a single line):

export JAVA_HOME=/System/Library/Frameworks/

… save and exit vi.

Restart Terminal app just to be sure that it worked, and try accessing it by typing:

$ echo $JAVA_HOME

If you see the correct JAVA path, then it is all done!

Read Full Post »

If you are a Firefox 3.6 user, you must have noticed that new tabs are now opening right next to the current tab. All previous Firefox versions were opening new tabs as the rightmost tab (on the far right of the tab bar). As far as I remember Google Chrome browser introduced this nifty idea first (although it’s not implemented exactly like that), and Firefox just followed.

I personally like it, although I have to get used to it, sometimes I am still looking on the far right to find the new tab.

For those of you who would like to retain the old style behavior, have a look at the following instructions:

1. Type on your browser’s address bar:  “about:config
2. Press the “I’ll be careful …” button.
3. Scroll down to the “browser.tabs.insertRelatedAfterCurrent
4. Double-click on it to set its value to “false
5. Enjoy, there is no need to restart Firefox

Read Full Post »

The most common problem of ADSL connections, especially on long lines, is a low SNR margin value. The SNR margin (or Noise margin) is the relative strength of the DSL Signal to Noise ratio.

In case that you have upgraded your ADSL connection to a higher bandwidth (for example from 2 Mbps to 8 Mbps), you might be experiencing frequent line drops (disconnects). Especially during the night-hours there is a higher probability of having a lower SNR margin.

Depending on your ADSL router’s brand/model, you might be able to tweak the advanced connection settings.

Here I am going to describe how this can be achieved on a Netgear DG834PN router.  It could be working with similar Netgear models (Google is your friend!).

Please make sure that you follow the instructions carefully, and only change the settings that suit you.

The first step is to enable telnet connections to the router. Thus, start up your browser and paste the following URL:

The IP address should match your router’s address, so please change it accordingly.
The web interface is going to ask you for the administrator username/password.
Upon entering the correct details, you will see the message “Debug Enable!”.

Now that the telnet option is enabled, you need to connect to the router.
For example on a Windows command prompt just type “telnet”. On Mac/Linux just use the Terminal.

If the telnet connection is successfully established, type the following command to increase your SNR margin:

adslctl configure –snr 150

The 150 value is the percentage of the original SNR value.
For example if your original SNR value was 6 dB, than the 150 percentage would mean that you prefer an SNR value of 9 dB.

Increasing your SNR value, is decreasing your connection’s download bandwidth as well. However it’s better to have a lower bandwidth, than having a connection which constantly drops.

If you would like to restore the setting, than simply type:

adslctl configure –snr 100

… or just reboot your router. It has to be mentioned that the debug options are vanished after a router restart.

Read Full Post »

This is something that I am frequently being asked about, so I decided to post the simple solution.

For SQL Server table columns that have the IDENTITY property enabled, their respected values are being auto-incremented according to the IDENTITY’s incremental value.

The seed value is the value that is used for the very first row inserted into the table.
Therefore, if at some point all table records are cleared, there might be the need to reset the seed value back to zero or some other value.

Here is how we can reset the IDENTITY value with a simple SQL statement:

DBCC CHECKIDENT ('table-name', RESEED, new-value)

It has to be mentioned that the next value that will be inserted on the table would be the value of ‘new-value’ + 1. So for example if the new-value is 0, the next row value will be 1.

Read Full Post »

One of my favorite components of Mac OS X is the underlying UNIX-based Terminal.
The Terminal has lots of valuable tools that give you insight information about the processes that are running, the system etc.

This article is going to use one of these tools, the “lsof” command, to show all running processes / applications, which are accessing the Internet.

Here is how to:

– Fire up the Terminal app (you can find it on Applications/Utilities, or simply type terminal on the Spotlight)

– Run the following command:

lsof -i -n -P

Depending on how many open applications are accessing the Internet, you might get a shorter or longer list of results. The first column of the results is showing the process name, and the last columns are showing the port type, port number, corresponding target IP addresses, and the connection status (e.g. established).

If you would like to have host names rather than IP addresses, omit the command’s -n switch:

lsof -i -P

Moreover if you want information for a specific application only, for example Firefox, type:

lsof -i -n -P | grep firefox

As a reference only, the -P switch inhibits  the conversion of port numbers to port names, and the -i switch can be used to filter IP addresses. If you would like to find more about the “lsof” command, type “man lsof” on your Terminal.

Read Full Post »

Today I have been typing on Gmail chat, and by accident I have found out how to type a word in bold. With a bit more of a search, I have also found out how to type in italics, and also strikethrough a word.

Here is the cheat sheet:

Bold: Surround the word with asterisks, e.g. *word* -> word
Italics: Surround the word with underscores, e.g. _word_ -> word
Strikethrough: Surround the word with hyphens, e.g. -word- -> word

If you know more “secret codes”, feel free to leave a comment!

Read Full Post »

Older Posts »