Sunday, October 09, 2011

.gitignore by example

A git ignore is a file named ".gitignore" that gets placed in the top level directory of your git workspace.

It informs git to ignore files when adding and committing files.

# Exclude files with an extension
*.jar
*.o
*.a


# Do not exclude required.jar
!required.jar


# ignore the file TODO at the top level directory only
# thus /TODO will be ignored, but src/TODO will not be ignore.
/TODO


# To indicate a directory for ignoring it should end with a "/"


# This line ignores all directories and subdirectories named log/
log/


# This line only ignores the top level directory named build
/build/


# This ignores all files ending with txt inside doc/ directory, but not inside doc/example/
doc/*.txt

Important notes:
1. Files starting with / (slash) mean that you should start from the top level directory
2. The * (star) in doc/*.txt does not mean it will match any directories inside. It will only match top level files inside the doc directory ending with *.txt. Thus doc/example/test.txt will not be matched.

Tracking an /etc directory using GIT version control while preserving file permissions

.. while preserving permissions on the linux file system.

Here's how to do it:
1. Download the post hook file setgitperms from here or directly from here http://repo.or.cz/w/git.git/blob_plain/HEAD:/contrib/hooks/setgitperms.perl

2. Place the script inside your .git/hooks directory. You have two options here:

(Option A) To apply this for all git repositories newly created
Copy the file setgitperms.perl inside the directory:

mv setgitperms.perl /usr/share/git-core/templates/hooks/.

(Option B) To apply this hook for a specific directory only
Copy the file setgitperms.perl inside the directory:
mv setgitperms.perl <Your Project Directory>/.git/hooks/.

3. Although git new releases handles this, just to be safe, make sure to add execute permissions for the hook:
chmod +x setgitperms.perl

4. Inside the hooks directory, create a file named "pre-commit" and place in it the following lines:

#!/bin/sh
SUBDIRECTORY_OK=1 . git-sh-setup
$GIT_DIR/hooks/setgitperms.perl -r


5. Create file named post-merge and post-checkout and place the following content inside each:

#!/bin/sh
SUBDIRECTORY_OK=1 . git-sh-setup
$GIT_DIR/hooks/setgitperms.perl -w


6. Save the files and make sure they are executable using chmod +x:
chmod +x post-merge
chmod +x post-checkout
chmod +x pre-commit

7. Thats it.

Reference: http://serverfault.com/questions/5410/using-revision-control-for-server-configuration-files

Saturday, October 08, 2011

Installing Tomcat 6 on Redhat Enterprise

List of commands that took place:

cd /opt
wget http://mirrors.isu.net.sa/pub/apache/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.zip
unzip apache-tomcat-6.0.33.zip
ln -s /opt/apache-tomcat-6.0.33 tomcat
yum install java-1.6.0-sun
alternatives --config java



There are 3 programs which provide 'java'.


Selection    Command
-----------------------------------------------
1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2           /usr/lib/jvm/jre-1.6.0-sun.x86_64/bin/java
3           /usr/lib/jvm/jre-1.6.0-sun/bin/java


Enter to keep the current selection[+], or type selection number: (Press 2 Then Enter)
vim /etc/init.d/tomcat

While in vim type the following in command mode to avoid extra spaces which pasting:
:set paste

Copy the following text and paste it:

#!/bin/bash # # Init file for SixSigns Tomcat server # # chkconfig: 2345 55 25 # description: SixSigns Tomcat server # # Source function library. . /etc/init.d/functions RUN_AS_USER=tomcat # Adjust run user here CATALINA_HOME=/opt/tomcat start() { echo "Starting Razuna Tomcat: " if [ "x$USER" != "x$RUN_AS_USER" ]; then su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh" else $CATALINA_HOME/bin/startup.sh fi echo "done." } stop() { echo "Shutting down Razuna Tomcat: " if [ "x$USER" != "x$RUN_AS_USER" ]; then su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh" else $CATALINA_HOME/bin/shutdown.sh fi echo "done." } case "$1" in start) start  ;; stop) stop  ;; restart) stop sleep 10 #echo "Hard killing any remaining threads.." #kill -9 `cat $CATALINA_HOME/work/catalina.pid` start  ;; *) echo "Usage: $0 {start|stop|restart}" esac exit 0

Then write and quit in vim:
:wq

Make sure the file doesn't contain microsoft new lines:
dos2unix /etc/init.d/tomcat

Now change to executable:
chmod +x /etc/init.d/tomcat

Next create a tomcat user:
groupadd tomcat
useradd -g tomcat -d /opt/tomcat tomcat
passwd tomcat
password: tomcat
retype password: tomcat

Reassign permissions to directories:
chown -R tomcat:tomcat /opt/tomcat
chown -R tomcat:tomcat /opt/apache-tomcat-6.0.33
cd /opt/tomcat/bin
chown +x *.sh

Add tomcat to services:
chkconfig --add tomcat
chkconfig --level 345 tomcat on

Start tomcat:
/etc/init.d/tomcat start


Finding ports and processes running on linux port 80

The command:

# To find processes running on port 80
lsof -i :80

A Wonderful CSS Tricks Website

Installing Tomcat 6 on Redhat Linux Enterprise or CentOS

http://wiki.openbluedragon.org/wiki/index.php/Apache_Tomcat_on_CentOS/RedHat

From: 

Install Tomcat

With CentOS/RedHat you could install Tomcat from the YUM repositories, but they only hold the older 5.5.x version. Of course, if you want to have Version 5.5.x installed then you only have to issue a;
yum install tomcat*
But I do recommend that you install Tomcat 6.0.18 (the current version of this writing), since it features better memory handling and some other improvements. The official Tomcat page is your friend in this regard http://tomcat.apache.org/. Luckily, installing Tomcat is straight forward.
  1. Download Tomcat 6.0.18
    1. Browse to http://tomcat.apache.org/download-60.cgi and download the Binary Distribution or click on the direct link here http://apache.mirror.testserver.li/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz. Wget is your friend.
  2. I recommend to install Tomcat in the "/opt" directory. Thus copy the downloaded file into "/opt".
  3. Extract it with
tar xzvf apache-tomcat-6.0.18.tar.gz
  1. For better handling I always create a symbolic link for "tomcat" with
ln -s /opt/apache-tomcat-6.0.18 tomcat
  1. Test Tomcat
    1. Start Tomcat with:
/opt/tomcat/bin/startup.sh
    1. Hit http://localhost:8080. If all is fine you should see the Tomcat homepage.
All should be fine, right? Ok, move on.

Deploy (Install) OpenBD

  1. go into the tomcat folder
    1. cd /opt/tomcat/
  2. download the openbd.war file (be sure to check the OpenBD download site for the latest war file link)
    1. wget http://openbd.viviotech.net/downloader.cfm/id/64/file/openbd.war
  3. once the file has downloaded move it to the tomcat webapps folder where it will automatically deploy
    1. mv /opt/tomcat/openbd.war /opt/tomcat/webapps
  4. once the war file is in webapps Tomcat will pick it up and create an openbd folder
  5. go to the administrator
    1. http://localhost:8080/openbd/bluedragon/administrator
      1. the default bluedragon administrator password is admin

Configure Tomcat to run on startup

Now, that Tomcat and OpenDB runs nicely you might want to have it automatically started when you reboot your system. For that we can use the following script and "chkconfig" command line.
  1. Create a "tomcat" file in "/etc/init.d"
vi /etc/init.d/tomcat
  1. Copy the below startup script
#!/bin/bash
#
# Init file for SixSigns Tomcat server
#
# chkconfig: 2345 55 25
# description: SixSigns Tomcat server
#

# Source function library.
. /etc/init.d/functions

RUN_AS_USER=tomcat # Adjust run user here
CATALINA_HOME=/opt/tomcat

start() {
        echo "Starting Razuna Tomcat: "
        if [ "x$USER" != "x$RUN_AS_USER" ]; then
          su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
        else
          $CATALINA_HOME/bin/startup.sh
        fi
        echo "done."
}
stop() {
        echo "Shutting down Razuna Tomcat: "
        if [ "x$USER" != "x$RUN_AS_USER" ]; then
          su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
        else
          $CATALINA_HOME/bin/shutdown.sh
        fi
        echo "done."
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        sleep 10
        #echo "Hard killing any remaining threads.."
        #kill -9 `cat $CATALINA_HOME/work/catalina.pid`
        start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
esac

exit 0
  1. Save the file (case you forgot "esc + x) :-)
  2. Add the tomcat startup script to the chkconfig with:
chkconfig --add tomcat
  1. Then activate it for your run level. Since I am not running any X Server on my server I only want to run it on level 345. Do it with:
chkconfig --level 345 tomcat on
  1. You can check if Tomcat will startup on reboot with listing the startup scripts with:
chkconfig --list
You should see a;
tomcat         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
  1. If you have done all well, you should now be able to bounce Tomcat with this script as well. Try it with:
/etc/init.d/tomcat restart

Thursday, October 06, 2011

Speeding up mysql restoration of data

Mysql restoration too slow? Try the following steps:

1. Open the file my.ini inside the MySQL installation directory and do the following:

(a) Search for innodb_buffer_pool_size and set it to approx 20% of your RAM. I set it to 500M.
innodb_buffer_pool_size=500M

(b) Search for innodb_flush_log_at_trx_commit and change it from 1 to 2:
innodb_flush_log_at_trx_commit=2

(c) Search for key_buffer_size and set it to approx 20% of your physical RAM.
key_buffer_size=1200M

(d) In your data.sql file you are trying to restore, if it is an innodb tables, try to modify it and add the lines:
SET FOREIGN_KEY_CHECKS=0 // At the beginning

...
SET FOREIGN_KEY_CHECKS=1 // At the end of the file

Now restart MySQL service.

Start restoring data. It will be approximately a magnitude of 50 times faster.

The Robot Two Leg Problem in Guice DI


Sunday, October 02, 2011

Maven, configuring an http proxy


Go to your user directory (ie. /home/babbas or /c/Users/babbas) then goto ".m2" directory and create a file named settings.xml. Inside that file copy the contents below:

<?xml version="1.0"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>iproxy.isu.net.sa</host>
<port>8080</port>
<username/>
<password/>
<nonProxyHosts/>
<id/>
</proxy>
</proxies>
</settings>


Installing GIT on Linux Redhat or CentOS 5

First is first:

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh epel-release-5-4.noarch.rpm
yum install git

Next steps, configure git configuraiton:

git config --global user.name "Basil Abbas"
git config --global user.email "basil@isu.net.sa"
git config --global color.ui auto

Creating a bare repository on a remote server:

mkdir project_directory
cd project_directory
git init --bare

Cloning the bare remote repository on a development machine:

cd /home/babbas
git clone ssh://hostname/path/to/project_directory






Saturday, October 01, 2011

VIM ignoring case search

Just type:
:set ignorecase



and to return back to normal:
:set noignorecase


If you would like to search case insensitive one time only without changing the mode in vim, for example lets search for the word "earth" case insensitively:

/\cearth

The \c character tells vim that the search should be case insensitive.

Friday, September 30, 2011

Web Session Management White Paper

PDF Link:
http://www.isecpartners.com/files/web-session-management.pdf


Developing an application with secure session management requires developers to understand a few crucial subtleties of cookies — their attributes, their values, and how to keep them confidential — and to understand how real-world attackers are abusing weak session management in real applications today.

Thursday, September 29, 2011

Making VIM on windows behave like linux

The following:

1. Open the file _vimrc which you will find inside c:\Program files\vim

2. Find the line that says:

behave mswin

3. Change it to

behave xterm

4. Save and exit.

This will now allow you to select text by typing the 'vi' then using the arrows to select text.

Deleting all lines that are empty or contain spaces in vim

To delete all lines that are empty in vim:

:g/^$/d

To delete all empty lines or empty lines that contain spaces:

:g/^\s*$/d

Note that \s represents the space character in the regular expression. Or simply, you can also represent the space character with [ ]:

:g/^[ ]*$/d

Pasting code into VIM without the indentation problem

Frequently, when pasting code into vim, i get lots of indentation spaces that really frustrate me.
I discovered that this vim issue can easily be handled by typing in the command mode in vim:

:set paste

Then going to insert mode and pasting the source code.

Disable Autoindent in VIM

To disable autoindent in vim, you can do the following:


:set noautoindent | set nosmartindent | set nocindent

Or place the folowing lines in your .vimrc (linux) or _vimrc (windows):

set noautoindent
set nosmartindent
set nocindent


Sunday, September 25, 2011

Git Cheat Sheets

Goodbye Adobe Photoshop, Goodbye Paint.NET, Good Bye Greedy Pricing Schemes

I lately found this wonderful image processing application named PhotoPlus Starter Edition and I'm now no longer using either Adobe Photoshop nor Paint.NET.

From serif.com:
http://www.serif.com/FreeDownloads/

The best "git log" command to use

This is the best git log command to use:
git log --decorate --graph --oneline

You can alias this command as follows:
git config --global alias.lol "log --graph --decorate --oneline"

Now you can use it as follows:
git lol

Making two branches identical after a git merge

I had two branches, heavy_refactoring and master branch in git.
I have already merged heavy_refactoring into master, but I had some trouble since master looks different than heavy_refactoring at the end due to some changes that took place on master before the merge. These changes I dont want.

What I wanted is that the 'master' branch look exactly like heavy_refactoring.

So here are the steps:

1. Go to the master branch first.

git checkout master

2. First you do a git diff between the two branches:

git diff --summary master heavy_refactoring

This will shows us the differences that should take place for master to become heavy_refactoring. It is very important that you type 'master' before 'heavy_refactoring' to advise the git diffing to give the differences so that I can get from master to heavy_refactoring.

The --summary is a switch to tell the diff not to show the contents inside each file.

3. After running the command, a list of deleted, modified and created files show up.

4. If the diff tells you that I file is "deleted", this means it should be removed from the master branch using:

git rm file_to_remove

5. If the diff tells you that I file is "created", this means you have to copy it from the heavy_refactoring branch to the master branch using:

# Copying a file from another branch to the current branch
git checkout heavy_refactoring src/main/java/com/basil/TargetFile.java

6. If the diff tells you that I file got "modified", this means you also have to copy it from heavy_refactoring branch to the master branch. Notice that my objective here is to make master exactly like heavy_refactoring.

git checkout heavy_refactoring srcmain/java/com/basil/TargetFile2.java

At the end, I can run the git diff again and it will show me an empty result which will indicate that the two branches are exact:

git diff --summary master heavy_refactoring


Monday, September 19, 2011

Enabling SSL in Apache Tomcat 6 The Easy Way

NOTE: This article does not use the APR tomcat module but rather the default Tomcat 6 deployment.

To enable SSL for Apache Tomcat 6, perform the following:

1. Create an SSL certificate using the java supplied keytool:

$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA

NOTE: If you get the error:
keytool error: java.lang.Exception: Key pair not generated, alias <tomcat> already exists
Then most probably you have a key file already in your user directory. If you are root, this will be /root/.keystore

2. You will be requested for data that will show on your user browser's certificate, fill them all in.
Notice that the bold font is my input. No problem if you stick to the password "changeit" as it is the default password used by tomcat.

Enter keystore password: changeit
Re-enter new password: changeit
What is your first and last name: Jeremy Atkins
What is your organizational unit: OU
What is the name of your organization: NOYO
What is the name of your city or your locality: MyCity
What is the name of your state or province: Saudi Arabia
What is the two-letter country code for this unit:  uk
Is the entered data correct: yes

Enter key password for <tomcat>
        (RETURN if same as keystore password): PRESS RETURN KEY

It is important to have the keystore password and the key password the same. This is done by pressing the RETURN KEY in the last step. This is necessary since Tomcat doesn't support having different passwords in the keystore and key.

3. When you're done with the previous step, a keystore file gets created in the user directory named keystore. Since I'm the root user, I will find it in /root/.keystore.
Check that the file /root/.keystore got created.

4. Next, open the tomcat server.xml for editing:
vi ${tomcat_installation_dir}/conf/server.xml

And uncomment the following section by removing the <!-- and the --> surrounding them from top and bottom:

   <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               />

5. Change the port number from 8443 to 443 which is the default SSL port known to all browsers.
Switch to 8443 while in development if needed.

   <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               />


6. Now add the following line in between to tell tomcat where to locate the keystore and specify the password you specified:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
   maxThreads="150" scheme="https" secure="true"
   clientAuth="false" sslProtocol="TLS"
   keystoreFile="${user.home}/.keystore" keystorePass="changeit"
               />

Tomcat will automatically replace ${user.home} with the path of the home directory for the user tomcat is running under. Which in my case is "/root"

7. Restart apache tomcat using:
<tomcat_installation_dir>/bin/catalina.sh stop
<tomcat_installation_dir>/bin/catalina.sh start


Disabling WebDAV DELETE, PUT, OPTIONS in Apache Tomcat 6

It really took me more than two hours searching over the internet just to understand how to do this simple configuration of disabled the WebDAV methods in apache tomcat 6 for all applications.

Here is how to do it:

In your apache tomcat 6 installation, simply open the file <installation_directory>/conf/web.xml for editing. Note that this web.xml file acts as a global file for all web applications and is processed before the web.xml's web application file.

At the end of the global web.xml file and just before the closing tag place the following text:

<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>

The above security-constraint simply denies the above WebDAV methods to be processed by tomcat and returns a forbidden message.

The <auth-constraint /> simply means: "For any user, deny access to PUT, DELETE, OPTIONS, and TRACE methods".

After that, restart apache tomcat 6 using:

<installation_directory>/bin/catalina.sh stop
<installation_directory>/bin/catalina.sh start

To be able to verify that these methods are now forbidden, I used some javascript jquery code:
1. Open firefox with the firebug plugin installed
2. Open a webapplication that has jquery javascript file included within it.
3. Open firebug and select the "Console" tab from firebug
4. Write the following javascript code:

$.ajax({
  type: 'DELETE',
  url: "http://212.138.70.94",
  data: {},
  error: function() {alert('ERROR');},
  success: function() {alert('SUCCESS');},
});

5. Click the Run button.
6. You should see an alert dialog with the message ERROR and a response in firebug with the following message:
"NetworkError: 403 Forbidden - http://212.138.70.94/"

7. Repeat the above for the OPTIONS, TRACE and PUT methods.

I'm sure there's a simpler way to verify it other than javascript. But I don't know how.

Monday, September 12, 2011

Creativity is Not Design

From: http://jessewilson.net/notes/creativity-is-not-design
Too often I notice designers and non-designers alike equating creativity with design. I find this assumption disturbing because it is one of the many fallacies that allow unskilled but creative pretenders to consider themselves capable design professionals when they’re nothing of the sort… Creativity is bound by no laws, rules, or strictures… Design, on the other hand, is based entirely on math, psychology, human perception, and a host of rigid rules and laws that can be broken by only a highly skilled few…

Automatic Java Class Diagram Generation Using ObjectAid

I was looking for a tool that would allow me to view my classes graphically, until I bumped into this question from stackoverflow.com:

http://stackoverflow.com/questions/1120032/what-is-your-favorite-automatic-class-diagram-generator-for-eclipse

And after trying several tools, I think ObjectAid beats'em all.

Object Aid Website:
http://www.objectaid.com/

Wednesday, July 13, 2011

A Wonderful Tool Called Briss, Crop your PDF margins for Kindle Reading

Wonderful tool that will crop the white spaces in your PDFs to make them clearly readable on your Kindle 3.
http://sourceforge.net/projects/briss/
Its freeware.

Important Information Concerning SATA 3 Support on Laptops / Notebooks

Read this question:
http://superuser.com/questions/234754/revision-3-sata-6gb-s-capable-laptops-do-they-exist

Then this link:
http://www.intel.com/products/notebook/chipsets/ec-qm67/ec-qm67-overview.htm

Then this link:
http://www.intel.com/Assets/PDF/datasheet/324645.pdf

When purchasing a laptop, check for a 6 series intel chipset.
They are supported on laptops with the QM67, QS67, HM65, UM67, and HM67 chipset.

Tuesday, May 03, 2011

Setting a default program to open files with unknown extensions or no extension on Windows 7

I always get frustrated having to select a program to open a file when most of the time this program is notepad.

I searched the internet for a way to define a default program to open files for all other files that have extensions not defined on windows. Luckily, I found this article:
http://www.fortypoundhead.com/showcontent.asp?artid=2738

To modify the registry you have to run regedit.exe and modify or add the following:

[HKEY_CLASSES_ROOT\*\shell]

[HKEY_CLASSES_ROOT\*\shell\open]
@="Open With Notepad"

[HKEY_CLASSES_ROOT\*\shell\open\command]
@="notepad.exe %1"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.]
"Application"="Notepad"

Note the following, if the key does not exist, you have to create it.
Example, create the key "open" and created under it the key "command"
Also @= means the default value for the key
Application=Notepad means you have to create a string value containing Application and value Notepad
Also, the last key make sure to notice the ".", its not "FileExts" but rather "FileExts\.", a subkey inside FileExts labeled dot.

Or simply, the above could be saved into a *.reg file and executed.

After that you will get in the context menu the option to open with Notepad for any unknown file.

Monday, February 14, 2011

The Rise Of Mashups

As much as I hate the over-over-over-engineered java Portlet specification JSR-168 and JSR-268, as much as I  felt safe with the Mashup concept. Though in its early stages, I believe mashups will eventually replace Portals and Portlets forever.

To follow up on Java mashup news, keep a close eye on the following:
http://www.jackbe.com/enterprise-mashup/mashups-and-java/

Tuesday, February 01, 2011

An excellent article explaining custom tags in JSP2

This is an excellent article explaining custom tags in JSP2:
http://www.vsj.co.uk/java/display.asp?id=408

The custom tag development has been simplified and the complicated java API is no longer needed to develop a custom tag. A *.tag file is created instead.

JSP custom tags are an advantage in the JSP language that does not exist in other web technologies I'm aware of (ie. PHP).

Saturday, January 01, 2011

Ten Ideas for Making Sys Admins Life Easier

http://queue.acm.org/detail.cfm?id=1921361

A message from administrators to application vendors:
1. DO have a "silent install" option.
2. DON'T make the administrative interface a GUI.
3. DO create an API so that the system can be remotely administered.
4. DO have a configuration file that is an ASCII file, not a binary blob.
5. DO include a clearly defined method to restore all user data, a single user's data, and individual items
6. DO instrument the system so that we can monitor more than just, "Is it up or down?"
7. DO tell us about security issues.
8. DO use the built-in system logging mechanism 
9. DON'T scribble all over the disk.
10. DO publish documentation electronically on your Web site.

Three Common Application Problems Developers Should Watch Out For


In summary:
- ORMs can really be dangerous on your application if you don't understand whats happening internally.
- Very few developers (a fringe of a fringe) really understand threading and can write multithreaded applications.
- Memory leaks take place in java by not closing and freeing resources and could become a real performance problem if not tracked correctly.

Finding Free Use Fonts

Don't look any further: http://www.fontsquirrel.com

Wonderful site with many free for use fonts.

Wednesday, December 01, 2010

Denying A Program To Connect To A Network

Imagine that one day you download a free password manager on your windows machine, and use it to store all your passwords for online banking accounts, emails, etc.

Knowing that this same executable is capable of connecting to the internet and doing different things like connecting to a server and checking for updates...

Imagine that one day the guy developing the tool inserted some malicious code to forward password information in your password manager.

Paranoid thinking? But can we blame paranoids, I mean the world is full of negative surprises that only paranoids were able to predict.

Better than blaming, is protecting yourself without losing the privilege of the software you want to use. On windows 7, here's how:

1. Go to the Control Panel.
2. Click on the Windows Firewall icon.
3. Make sure that your windows firewall is turned on by clicking on Turn Windows Firewall on or off
4. When this is done, go back to the Windows Firewall and click on "Advanced Settings".
5. Click on "Outbound Rules"
6. On the right, click on "New Rule..."
7. Make sure Program is selected in the radio buttons and click Next.
8. Enter the path of the program exe then click Next.
9. Make sure "Should be Blocked" is selected then click Next.
10. Enter a display name for this rule.
11. Click Finish.
12. Open the desktop tool you want to protect against and select "Check for updates.." in your tool if available. The tool should crash or tell you that it is unable to connect to the internet. No connection available.

Capiche. You're done.

Monday, November 29, 2010

The Google Chrome Dictionary Plugin

I always have trouble finding and installing the google chrome dictionary plugin, therefore, I'm posting this link as a reminder:

https://chrome.google.com/extensions/detail/mgijmajocgfcbeboacabfgobmjgjcoja?hl=en-US

The Exercise Every Developer Needs

Exercises for tendonitis and carpal tunnel:
http://www.youtube.com/watch?v=hUyMNyrOHJQ

Before its too late.

Tuesday, November 09, 2010

wxWidgets versus Qt?

Both are good frameworks for writing a C++ desktop application. By the way, Qt is used in Google Earth and the Skype application.

For a wonderful comparison between wxWidgets and Qt, read the following:


My final conclusion, Qt wins.

Wednesday, November 03, 2010

Sticky Notes Utility and More...

I've been used to using ATNotes, which is a sticky notes utility that was very light weight but had some frustrations. I'm telling you, writing your todo's on a sticky note on screen is an excellent way to keep your mind fresh and at the same time keeping all your TODOs as a reminder.

However, some frustrations with ATNotes bothered me, so I've started looking for alternatives. Usually I do this be searching on google for "ATNotes alternativeto" (without double quotes), which displays the alternetiveto.net site.

Luckily, I found a wonderful alternative which is named Stickies. I've installed it and found it great, simple, lightweight and doesn't interfere with your system or registry.

If you still need more alternatives you can check the list on http://alternativeto.net/software/atnotes/.

More interestingly, I found that the company that made this utility also made some interesting utilities which I name a few here:

1. Stickies (The already mentioned sticky note utility).
2. ZBar (multiple task bars for multiple screens)
3. Bart (A wonderful simple backup utility).
4. Caffeine ( A utility that simulates a key press every one minute to avoid your PC from stand by or screen saving).

Sunday, October 03, 2010

Where to find good images for your website?

A good friend of mine named Maximos, originally Rami the 17th gave me this link which is excellente:


Don't look any further.

Tuesday, September 28, 2010

Wednesday, August 25, 2010

Catching up with Nuxeo: Switching from Python to Java

I recently read this article on infoq.com. Summarizing the findings in this post, here's the story.

Nuxeo - an ERP company - took the decision on 2006 to port their core products from Python to Java. Infoq recently got hold of their CEO to discuss how the conversion went and also discussed the merits of static very dynamic typed languages since Nuxeo now tried both.

Summary of reasons to convert to Java
1. The availability of components and frameworks in Java like Hibernate, Lucene and Eclipse makes it much easier to build applications. Although they admint Python is great, it wasn't suitable for the platform they were envisioning to build.
2. The range and depth of the Java libraries was one of the main drivers for switching to Java. The Nuxeo product is using 100 libraries in total, including jBPM, OpenSocial, OAuth for widget inclusion, Apache Shindig, Apache Chemistry for CMIS, JXA-RS, JPA, JDBC, JTA, JSF, Seam and RichFaces.
3. Build system facilities based on Maven, Hudson, JUnit. Supporting Jetty, Tomcat, JBoss and bare OSGi.
4. Market Reasons. The market for java applications is huge. All companies know Java. Most already have java applications running. A lot of companies require Java for their IT. All system integrators have extensive java knowledge.
5. Community Reasons. The community is again, huge. The Java Apache community is tremendous. There are big annual conventions around Java (JavaOne, ApacheCon, Devoxx, Jazoon, etc.) and hundreds of small ones.
6. Specification Reasons. Many technologies in the Java world are based on published specifications that have many implementations and reference implementations promoting clean specs.
7. High availability of tooling for Java. The VM itself, debugging tools, IDEs, monitoring, performance benches, etc.

The results of the new Nuxea java based platform
1. Performance scales of about 10 to 100 times more.
2. In terms of features, its around 4 times the scope of what had been.
3. In terms of developer compatibility and ease-of-use, its about the same, but with alot more tooling experience.
4. Doubling or even tripling the capabilities of the old platform.

How customers reacted?
1. 80% were okay with the change.
2. For those organizations that didn't want to move, the community stepped forward to ensure their ongoing support (the open source advantage).

Merits of Python versus Java (Merits of Dynamic versus Static typing)
Merits of Python and Java is a subset of the merits of Dynamic versus Statically typed languages. Lets see what both sides have to say.

Advocates of Dynamyic types languages argue that they are faster to code in, since the languages are inherently more expressive.

Advocates of Static typed languages argue that time saved in development using Dynamic languages is time lost in testing. This is because the lack of type information makes testing harder. In addition, dynamic languages are generally slower than statically typed languages and thus tend to be more expensive to scale.

Nuxeo Opinion on Static and Dynamic Languages
In Nuxeo's case, they tried both dynamic and static languages to write their large scale product that consists of thousands of classes and hundreds of thousands of lines of code. Nuxeo's CEO says: Without a doubt, statically typed languages are better for such applications and yield many benefits giving you:

1. An IDE with proper autocompletion
2. An IDE that knows all the uses of a given method or field in all of your classes thus vastly improving search and refactoring.
3. Many compile time checks.
4. Tools that find patterns and bugs in your code.
5. Tools that extract documentation based on the actual types in your code. This is because a statically typed language will explicitly indicate the type of an argument passed to a function. This is rarely a hindrance and always good documentation. Dynamism on the other hand doesn't bring you anything except for less typing of the argument types.


What about the advantages of dynamic languages?
IMHO, dynamically typed languages are useful only for tiny applications or fast written scripts that perform different tasks.

Another interesting thought that comes up when debating dynamism versus static languages, is an analogous subject that has sparked myriads of debates in the United States when Obama's administration applied a new set of regulations on businesses (which in some people's opinions is freedom limiting).

I've spotted this interesting analogy from comments placed by the infoq.com visitors on the same article discussing the new regulated economy.

Chat Abbreviations and IMHO

Nowadays, people are using chat abbreviations very frequently to save time and typing along with emoticons.

What surprised me recently is a very popular abbreviation used widely on the internet that I never read or used before. Its "IMHO", from the letters used and the "O" at the end, I first thought that it is an international organization of some type. But when I looked it up, I discovered that what IMHO really stands for is:

"IMHO = In My Humble Opinion"

So you can now safely add IMHO to your set of chat abbreviations including LOL, BRB, NP, BR.

Wednesday, July 14, 2010

How BP Handles a Coffee Spill

Simulating how BP handled it's oil spill on a smaller scale scenario ... a coffee spill.

http://www.youtube.com/watch?v=2AAa0gd7ClM&feature=fvhr

Disclaimer: If you didn't follow the news then you wont get it.

Sunday, July 11, 2010

A good Drupal alternative?

Frankly, I'm quite fedup with Drupal.

My plan is to find an alternative. And here's my research findings.


I bumped into the following excellent CMSs that I would like to try out:


1. Concrete 5 http://www.concrete5.org/ (PHP using Zend Framework)
2. BrowserCMS http://www.browsercms.org/ (Ruby on Rails)
3. Silver Stripe http://www.silverstripe.org/silverstripe-cms/ (PHP using Sapphire)
4. modx http://modxcms.com/download/ (PHP)
5. Frog CMS http://www.madebyfrog.com/ (PHP)
6. MiaCMS http://miacms.org/
7. CMS Made Simple http://www.cmsmadesimple.org/
8. TextPattern http://textpattern.com/
9. ImpressCMS http://www.impresscms.org/


Well, I think all of them are excellent. I really likes the Concrete 5 video preview though.


Also have a look at this top chart:
http://amplicate.com/rankings/475-top-ten-content-management-systems-cms/

In search for a User, Group, Role & Security Java Library

I've been longing for a Java library that would cover all the needs of authorization and authentication within an application in a sensible manner. The library shouldn't require huge EJB structures and should allow being used within a POJO context.

I've searched and found three useful libraries:
3. Spring Security http://www.acegisecurity.org/

The one that drives my curiosity the most is Apache Ki. Seems very promising.

Thursday, January 28, 2010

Jobless, need money, why not freelance from home?

You can start freelancing effectively using these websites:



One day, I'll need these websites badly.

Wednesday, June 13, 2007

A Useful Command Prompt Tip

netstat -an |find ":80"

The above command I use so frequently. It really helps me out figure if there is a webserver running on the machine (ie. listening on port 80).

Actually, this command is a combination of two commands. The first is netstat which displays a boring long table.

The second is find "XX" which ignores all strings that dont contain "XX".

The '|' is the pipe operator. Now the command simply pipes the output of 'netstat' into 'find', the result is the line that contains the string "80".

If you're from a linux background, you'll find this post a bit too obvious. Since we're used to using the 'grep' command (which is similar to 'find' on windows).

Sunday, June 03, 2007

Microsoft PowerToys

Add convenience to your life ...

Try these free tools:

1. Alt-Tab Replacement
When using Alt-Tab, this will show you a small thumbnail of the program you are switching too. Very helpful when switching to multiple instances of the same application.

2. Power Calculator
Enhanced calculator for your OS.

3. Open Command Window Here
Allows you to open the command window for any folder you are currently in.

4. Image Resizer
Resize images on the spot.

5. ClearType Tuner
This PowerToy lets you use ClearType technology to make it easier to read text on your screen, and installs in the Control Panel for easy access.

Download any or all at:
http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx

Saturday, June 02, 2007

Who Said You Cant Learn Karate From A Book?

You can learn anything from books. A good book with good illustrations and a comprehendable language style can teach you anything.

The only extra large step you need is to continually practice. If you dont, then most probably you're dropping everything you've read.

Now wait a second, I know what you're thinking... but watch out for what I said; I said 'you can learn', but I didn't say 'its the best way!'. So lets face it, someone whom read a book about Karate will definitely know more than someone who haven't read (assuming both initially start in the same state).

Here's my evaluation of the different ways to learn ordered from best to worst:

1. Let an expert teach you, practice well, see what other experts teach, read about it, apply, understand the different schools on the same subject.

2. Let an expert teach you and practice well.

3. Read a book, and practice.

4. Read a book.

5. Do nothing.

Please note that I'm writing this post without any pre-research or good analysis on the subject. Therefore, please forgive my 'hardly scratching the surface analysis' (abbreviated HSTSA) on this subject.

Tuesday, May 29, 2007

File System Storage Versus BLOB Objects

Document Management Systems nowadays are heading towards storing all documents as BLOB objects in the database. You rarely find any server side applications that deal with documents as files.

Whether its a... Document, Content, Bug, Project, Knowledge Management System, they're all implementing document storage using BLOB objects.

Why it that then?

Well...

1. The first advantage of having everything stored in the database is the ease of backups and restorations. You no longer need to backup the database then backup your document's directory, then make sure they are synchronized.

2. The second advantage is that the documents are stored the same way on all platforms and partitions. Whether its FAT32, NTFS, or any other filesystem, you can store them all in the same way.

3. The third advantage is, you have full control of versioning documents, storing interesting information like diffs, dates, users performing on them.

4. The fourth advantage is that third party applications that connect to the database need only to have the database port available. No need to provide extra ftp access to acess the documents.

Thats it. Bottom line...

If you're building some kind of server application, consider a Database File System.

Wednesday, May 23, 2007

The 3arabeezy Habit

In the old university days, whenever I met someone speaking half english half arabic, I usually felt so intimidated of such personalities. I used to think of them as people whom try their best to show off by mixing sophisticated english terminology with verbal mingled arabic pronounced english sounding words. At those days, 3arabeezy for me was a 100% Yukk.

Today, I became one of them (A 3arabeezist). I just cant stop it, I keep mixing english and arabic whenever I speak, I dont know how it came up to be, it just happened. Gradually, I started substituting english words for words that I cant find an arabic alternative for, and vice versa.

It seems that mixing two languages makes me feel smoother. Its not only in verbal languages. Its also in computer languages. You need to write Embedded C in Java code for certain functionalities, and to write PHP extensions using C in others, or even assembly in some C code, mixing languages could be an advantage.

However, mixing arabic and english proves that you are proficient in using both simultaneaously, but very weak in utilizing one at at time.

Even when trying to talk completely in English... one or more 'ya3neeez' have to slip through the conversation. And when I talk in complete Arabic, one or more 'simply', 'basically', 'soon enough', 'I think' have to slip in between.

In funny cases, I'm also starting to use the plural form of arabic words in english form... examples are 'Raheeebz', 'Raw3az', '7abaaaybax' and 'Jee3aanz'.

Lets jump to the lessons learned of this post. I guess there's one really serious lesson to mention. 3arabeezy aint that bad, but could make you look REALLY bad in first impressions. So here's my advice:

1. When introduced to new people, dont use 3arabeezy whatsoever. Stick to one language. Talk professionaly. Dont mix. It will only leave an impression of either a show-off or an improficient talker.

2. In public speech, dont use 3arabeezy unless the audience are people you've worked with before.

3. When dreaming, feel free to use 3arabeezy. Totally acceptable.

4. Sometimes you need to use 3arabeezy when talking to people who know neither arabic or english. This raises the chances that there could be an arabic or english word that sound something similar to their native language.

5. Only use 3arabeezy if you feel that a certain word has a better alternative in the other language that will ease up understanding. Again, this proves weakness in the former language.

Till then, we'll meet again in a next epi-post of 'Lost in the Code Carribeans'.

Tuesday, May 15, 2007

The Long Easy Way Versus the Short Hard Way

Today I had a small discussion with a good technical friend of mine ;) The discussion started with trying to handle an SQL Query with one shot.

The SQL Query got a bit too complicated to handle and needed some extra research, reading and thinking to figure out the correct way to do it. It took two technical brains, good MySQL experience, about forty minutes of work, and at the end some testing. It resulted with a long SQL statement.

Through our work we had another solution, its a very easy solution, get the data you need through multiple SQL statements. Thus, a long but easier way to do it.

We felt so proud that we were able to tackle the short difficult path, but at the end, considering the long easy path we missed, I felt a bit unrelaxed, but as soon as that happened, I was reminded with an important wisdom (by my amigo):

"If you keep choosing the easy and long path, you'll hardly learn anything. It's the difficult short path that provides you with extra skill and power."

Now imagine the amount of skill and power you can gain by choosing the long difficult path. Hmmmm, cool as long as no fatal mistakes takes place.

There's always alternate wisdom supplements when twisting different stories around.

Monday, May 14, 2007

The 'Call Super' Antipattern

A common design problem that is usually solved using the 'Call Super' antipattern (also referred to as code-smell). Simply stated, the problem occurs when the subclass needs to share the implementation of the super classes over-ridable methods.

In such case, 'Call Super' anti-patten is usually used by calling the over-ridden methods from within the subclass's over-riding methods.

I'll show a 'Call Super' code sample, then show a much better and neater solution (proposed by Martin Fowler).

The Bad Solution (Using the 'Call Super' AntiPattern):

class Penguin {
public void intoduceYourSelf() {
System.out.println("Hi, I'm classified as a penguin.");
}
}

class EmperorPenguin Extended Penguin {
public void introduceYourSelf() {
super.introduceYourSelf();
System.out.println("My real name is Emperor Penguin");
}
}
A Better Solution
A much better solution is to have an abstract method in the super class for the extra actions the subclasses will perform. And thus, the subclass only needs to implement that abstract method:

class Penguin {
public void introduceYourSelf() {
System.out.println("Hi, I'm classified as a penguin.");
talkAboutYourselfMore();
}


abstract public talkAboutYourselfMore();
}


class EmperorPenguin extends Penguin {
public void talkAboutYourselfMore() {
System.out.println("My real name is Emperor Penguin");
}
}



Thats it. A neat alternative solution that I love to use.

Wednesday, May 09, 2007

Curiosity Never Killed The Cat...

... it was Boredom which did.

The amount of boredom I've been through in the past three days has been killing me softly.

Unfortunately, this time it's the result of practicing a boring repititive task; writing code that tests code. You just keep on writing code and checking the result, then writing another line and checking the result, then another line, and checking the result.

Trying my best to be creative with this task, I only modified the code a bit to show errors in red color and success in green color. Thats about it.

Wisdom of the day:

Ok, curiosity might have killed the cat. But boredom will kill anything!

Monday, May 07, 2007

The Best Free Utilities

Check them out at:

http://www.techsupportalert.com/best_46_free_utilities.htm

Enjoy. I liked the sticky notes utility ;)

Saturday, May 05, 2007

Swapping Two Integer Variables Without Using a Temp Variable

The first time I heard this question, I thought it was a joke of some kind. I never thought such was possible.

Turned out to be possible and even faster than the normal technique, here you go:

Let X be an integer variable.
Let Y be another integer variable.
X = X xor Y
Y = X xor Y
X = X xor Y

Wont buy it? Then try it out for yourself.

One more technique, you can use the - (minus) operator instead, but be careful not to step over the integer max and min limits. Here you go:

(eg. X = 12, Y = 7)
X = X - Y ( X is now 5)
Y = X + Y ( Y is now 12)
X = Y - X ( X is now 7)
(result: X = 7, Y = 12, Voila! Swapped)

Hmmmm. Coming to think of a practical use. The only way such would be useful is to swap two large memory binary buffers.

This swapping enhancement breaks the common myth of 'its either memory or speed, but not both'. The swapping algorithm you just saw proves better in both memory consumption and performance gain.

Wednesday, May 02, 2007

Sticky Notes No Longer Stick

Ok, we all use pieces of paper for jotting notes and todos from time to time.

Some use white paper, lined paper or 3M sticky notes. When no physical resources are available I'll usually use notepad for quick note jotting.

This usually happens when I'm jotting down a quick description of a street address of phone number.

The problem with the notepad approach is the extra steps you have to walk through to actually open notepad and save the file. Which turns out to be so inconvenient when urgency is required.

I mean you need to go to Start > All Programs > Accessories > Notepad, oooft! or even Start >Run then 'notepad' and enter. I also use the quick launch, but at the end, notepad for note taking creates an intimidating experience. Not to mention having to remember the filename you saved on the desktop.

So long for notepad, what about the paper and pen approach? Well...

First, you need them to be around your desk somewhere and you need them to be around instantly. Pen and paper are easily un-noticed on your desk until you discover that you need them (comparing them to a laptop).

Second, paper and ink are limited resource, ie. They will run out. And you'll have to purchase them again.

Third, ok, anyone can afford paper and ink, but what about the environment.

The amount of paper waste caused from temp note storage is unjustified with the alternative tools available. Consider the amount of trees wasted for the sake of disposable paper notes and todo items.

Ok, I'm sure you're thinking now. What point is this post building up to?

Well, its all about a small and cute sticky notes tool (that mimics 3M sticky notes) named "ATNotes".

You can download it for free from:
http://atnotes.free.fr/download.html

Yep. Yep. No more notepad files on your desktop, no more scattered paper, no more ink, and guess what? You're now an environment friendly person.

A Big Thanks goes to its developer & author - "Thomas Ascher".

Hope you like it.

Tuesday, May 01, 2007

The Programmers Notepad

If you're one of those people whom dislike thick fat development IDE's, and at the same time you miss many of those rich highlighting and search/replace features in your simples editors.

Then go no further...

Try "The Programmers Notepad".

1.3 MB in size, free, wonderful, and very light-weight.

I loved it from first 'site' : /
at http://www.pnotepad.org/

I think I'll let go of EditPlus. My X-Favorite Editor.