Bash Find On A Large Dataset – Write The Results To A File

Examples

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.

No Comments

Useful Git Links

Tools

git-logo

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.

2 Comments

Disable iPhoto When Connecting iPhone

Config

apple_logo

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:

image_capture_pref1

5 Comments

Hibernate Wildcard Query

Examples

hibernate_icon

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.
No Comments

Java – Not A Number Gotcha

Examples

java

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....
2 Comments

MySQL and Negative Infinity

Examples

mysql

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.

No Comments

Python Create XML Document

Examples

python_logo2

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"/>
2 Comments

Python Parse XML Document

Examples

python_logo2

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.

1 Comment

Format The Date Command In Bash

Examples

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.

No Comments

Create Amazon EBS

Examples, Tools

aws

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.

1 Comment
« Older Posts
Newer Posts »