
Mar 14, 2009
A fast bash based solution for executing a find on a directory with a lot of files that you want to log to a file:
find /my/data/ -name '*.xml' -type f -fprint my_xml_files.txt
This example looks in the /my/data/ directory for all files with the xml extension and then writes the results to the my_xml_files.txt file.

Feb 12, 2009

Switching to Git has been an incremental learning experience. Below, are some useful links for learning about Git:
If you know of other useful introductory Git links, add them in the comments and we will update the post.

Feb 6, 2009

One of the more annoying features of OS X is that iPhoto automatically launches when you connect your iPhone. Apple is trying to make importing photos as easy as possible so the camera in the iPhone triggers the launching of iPhoto when connect your device. Follow the steps below to disable this feature:
- Open the Image Capture application in your Applications folder
- Click Image Capture and then Preferences in the top application navigation
- In the drop-down select “No application” for, “When a camera is connected, open.”
The following screenshot shows the Image Capture Preferences dialog:


Feb 3, 2009

Creating a wildcard query in Hibernate (HQL) is similar to how SQL handles the same funciton. The query is accomplished by using the, like keyword.
The example below searches for people with a name that contains Mik – an obvious match would be Mike.
Query query
= getEntityManager().createQuery("SELECT p FROM Person p WHERE p.name like :name");
query.setParameter("name", 'Mik");
query.getResultList(); // Returns a list of People.

Jan 25, 2009

There are always subtle nuances to every computer language. Recently, I found the following NaN (not a number) nuance in Java:
Bad:
if (value == Double.NaN)
// Do something...
Good:
if (Double.isNaN(value))
// Do something....

Jan 19, 2009

Storing and retrieving negative infinity in a MySQL database is accomplished by inserting an arbitrarily large negative number. Negative infinity is handy when storing default values in a database.
The following SQL statement is an example of inserting negative infinity:
INSERT INTO test(negative_infinity) VALUES('-1e500');
Here is the test table:
CREATE TABLE test (
negative_infinity DOUBLE NOT NULL
) ENGINE=INNODB character set utf8;
The value in the database is stored as the maximum negative value for the data type, double (-1.79769313486232e+308).
mysql> select * from test;
+------------------------+
| negative_infinity |
+------------------------+
| -1.79769313486232e+308 |
+------------------------+
1 row in set (0.00 sec)
In Java, the Double contsant for max infinity, directly correlates to the value stored by MySQL.

Dec 30, 2008

Creating an XML document in Python can be accomplished by executing:
from xml.dom import minidom
doc = minidom.Document()
testElem = doc.createElement("test")
testElem.setAttribute('id', '1234')
doc.appendChild(testElem)
print doc.toxml()
The example above creates an XML document, creates a child element, sets an attribute and then appends the child element to the document.
The XML document in the above example looks like:
<?xml version="1.0" ?><test id="1234"/>

Dec 30, 2008

Parsing an XML document in Python is easy. Below is a simple example that loads an XML document from a file, parses and prints:
from xml.dom import minidom
dom = minidom.parse('test.xml')
print dom.toxml()
For more information, see the Python minidom documentation.

Dec 23, 2008
Formatting the date output in bash is simple:
date + "%Y-%m-%d";
An example of assigning to a variable and using:
now=`date + "%Y-%m-%d"`;
cp /etc/hosts ~/hosts_${now};
For more information, see the manual.

Dec 20, 2008

The Amazon Web Services blog has a good post on how to setup an EBS volume using ElasticFox:
Amazon EBS (Elastic Block Store) – Bring Us Your Data
I do not see a way to schedule snapshots through the UI so, you may have to write a script to accomplish this feat.
Once you have created your EBS volume you still have to mount the new device. First add the following line to /etc/fstab:
/dev/YOUR_DEVICE_NAME /data ext3 defaults 0 0
E.g.
/dev/sde /data ext3 defaults 0 0
Next, you need to format the device. This is accomplished by executing:
mkfs.ext3 /dev/YOUR_DEVICE_NAME
E.g.
mkfs.ext3 /dev/sde
This post assumes you are using the ext3 filesystem. Next, you need to mount the device. This is done by issuing:
mount -t ext3 /dev/YOUR_DEVICE_NAME /DIRECTORY_TO_MOUNT_IN
E.g.
mount -t ext3 /dev/sde /data
After you mount the device you should be good to go. If possible, reboot your instance to make sure the process mounted properly on a restart.