MongoDB Wildcard Query

Examples

icon

MongoDB uses regex in certain parts of their query syntax. The following is an example of how to perform a wildcard query:

db.collectionName.find( { fieldName : /.*cnn.*/ } );

This example searches the collection for all documents with a field that contains, “%cnn%”. Of course in your query you need to replace “collectionName” with the name of your collection and “fieldName” with the field you are interested in.

1 Comment

Create Amazon EC2 AMI

Examples

aws

Creating an Amazon EC2 AMI from an existing image seems like a challenging process however, it is actually fairly simple. Before looking at the steps to create the image, first have the following AWS information/files handy:

  • Access key
  • Secret Key
  • Account Number
  • Private key (e.g., pk-37BKCPZ2AVHVSYBK2WZXUQ9D4GQZEB4Q.pem)
  • Certificate (e.g., cert-38BKCPZ1BOHVSYBK4WZXUQ4D4GQZEB2Q.pem)

Next, login to your instance and make sure you have the Amazon AMI and EC2 API tools installed and available in your PATH. Also, upload your private key and certificate to the server.

Now you are ready to create your image file. First create a directory to store this image in.

E.g.

mkdir /mnt/ami

The actual AMI bundle is created by running:

ec2-bundle-vol -d /mnt/ami -k YOUR_PRIVATE_KEY -c YOUR_CERTIFICATE -u YOUR_ACCOUNT_NUMBER

note: The account number should not contain any dashes (‘-’).

Creating the bundle takes a few minutes. After the bundle has been created, it is time to upload it to S3. This is done by running:

ec2-upload-bundle -b YOUR_BUNDLE_NAME -m /mnt/ami/image.manifest.xml -a YOUR_ACCESS_KEY -s YOUR_SECRET_KEY

This walks through the files generated by the bundle command and inserts them into S3.

After your files have been uploaded, it is time to register the AMI using the following command:

ec2-register YOUR_BUNDLE_NAME/image.manifest.xml

The result of running this command is your AMI id.

E.g.

ami-323FEA

Finally, your AMI has been created, uploaded and registered and you are able to launch a new instance of your AMI.

If you need more help, there is a good video available from an Amazon employee. Additionally, take a look at the Amazon docs on the subject.

No Comments

Git Ignore Untracked Files

Config

git-logo

If you do not want to see Git messages about build directories or miscellaneous scratch files then add them to your .gitignore file. To do so, create the file, add the directories/files and then add the file to git.

E.g.

touch .gitignore

Edit the file to suit your needs and then add/commit.

git add .gitignore
git commit .gitignore
3 Comments

MongoDB – Find Documents Missing Fields

Examples

icon

In MongoDB it is possible that some documents will not contain fields other documents have. The following code shows how to find these documents using the mongo shell.

db.collectionName.find("function() { return this.fieldName == null }")
db.collectionName.find("function() { return this.fieldName == null }").count()

The second example shows how to only get the count.

In this example. you would replace “collectionName” with the name of the collection you are interested in querying. Additionally, you would change “fieldName” to the name of the field that interests you.

1 Comment

Push a Branch to Git

Tools

git-logo

I found this example of how to push a branch to Git in the GitHub documentation.

git push <remote_repository_name> <branch_name>

E.g.

git push origin master

Execute this from the base of your local repository. This pushes your local commits to the TOT.

No Comments

Chkconfig Notes

Config

linux

Chkconfig is a simple utility available on Linux that allows you to register services to start/stop on bootup and shutdown. The following are the basic commands you need to know to get things going:

chkconfig --list (lists all the commands that are registered)
chkconfig --add httpd (add httpd to the chkconfig list)
chkconfig  --level 35 httpd on (enables the httpd daemon to start on runlevels 3 and 5)
chkconfig --level 35 mysqld on (enables the mysqld daemon to start on runlevels 3 and 5)
chkconfig --level 35 memcached on (enables the memcached daemon to start on runlevels 3 and 5)
chkconfig --level 2345 sendmail on (enabled the sendmail daemon to start on runlevels 2, 3, 4 and 5)
No Comments

Internet Explorer 6 On OS X

Misc

Recently, the need arose to run IE 6 on OS X. Microsoft released IE for OS X but discontinued support in version 5.x. Fortunately, this problem has been solved by running a IE 6 on top of a Wine port on OS X. The simple steps below describe how to get this running:

It is as simple as that!

Note: Darwine requires the X11 libraries that come with OS X (not installed by default but ships with the OS X install disks).

No Comments

OS X – Remove Glass Dock

Config

apple_logo

When running OS X Leopard, many people are annoyed by the glass dock provided by default. There are several applications that can be downloaded to remove this but we found a very easy way of removing the glass dock. In a shell type:

defaults write com.apple.dock no-glass -boolean YES

Next, it is time to remove a couple of files. Type the following:

cd /System/Library/CoreServices/Dock.app/Contents/Resources

Delete the glass dock images by typing:

sudo rm -Rf bottom*.png

Now it is time to restart your dock:

killall Dock

That is all!

No Comments

Bash – Write A Sequential For Loop

Examples

bashterm

A sequential for loop in bash script is accomplished in the following example:

for i in {1..100}
do
    # Do something here
    echo "${i}"
done

This example iterates from 1 to 100 (inclusive) and prints the index number.

Note: This only works in modern versions of bash (3.x+).

No Comments

OS X – Empty Trash Command Line

Examples

apple-logo

It is possible to empty the trash in OS X from the command line by running the following command in the terminal:

rm -Rf ~/.Trash/*

This command permanently removes all the files you have placed in your OS X trash bin.

2 Comments
« Older Posts