Archive for the 'Uncategorized' Category

Hello world!

Wednesday, January 30th, 2013

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Java: Split Strings

Sunday, November 6th, 2011

I was using Java to add users to a system by parsing a comma seperated value (CSV) file of user entries and I needed to split the file to gather the separate entries. There is also the StringTokenizer class that can seperate the entries as well.

So the following code snippet was used:

String fileline;

FileInputStream fis = new FileInputStream("filename.txt");
DataInputStream dis = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(dis));

while((fileline = br.readline()) != null) {
  String[] entries = fileline.split(",");

  for(int i=0;i < entries.length;i++)
  {
    System.out.println(entries[i]);
  }
}

Cron Job entry format

Friday, August 26th, 2011

If you ever need to schedule a job regularly on a Unix system, they have a great utility called cron. This will run a job at a regularly scheduled time.

Here is the format:

* * * * *  command to be executed
_ _ _ _ _ 
| | | | |
| | | | +--- day of week (0 = Sunday - 6 = Saturday)
| | | +----- month (1 - 12)
| | +------- day of month (1-31)
| +--------- hour(0-23)
+----------- minute (0-59)

example of a script that runs every day at 7:

* 7 * * * sendmeupdate

How to exit python script

Tuesday, August 23rd, 2011

When I was trying to terminate a python script after a failure, I tried to find the nicest way to exit. The sys.exit() command provided by importing the sys library was what I found.

The function can take an optional numeric argument, usually in the range of 0-127, and with no argument it returns 0. The return code is passed back to the Operating System.

import sys
sys.exit(1)

When exit returns a non-zero value, it is considered an error.

Tags:

Mounting drives in Linux

Tuesday, August 9th, 2011

Sometimes you have a drive that your want to mount under Linux. The mount command can make the drive available to you. But you need to also create a directory to hold the mount point.

mkdir /mnt/drivepoint

Then you can mount the drive to that mount point by using the mount command and giving the device identifier, in this case it is /dev/sda1, and the mount point which we created as /mnt/drivepoint. One thing to note, is that the mount will use whatever directory you specify, so if there are files located in the directory you use as a mount point, they will no longer be visible.

mount /dev/sda1 /mnt/drivepoint

This must be run as root or with the sudo command.

Tags: , ,

Using tar over ssh

Thursday, July 21st, 2011

Every once in awhile, I need to backup a large directory from another computer. This can be done by creating a zip or tar of the files you are looking to save and then copying those zips to the other computer. But what it you have a very large directory and not enough room to store the extra file. Here is a way to use tar over ssh:

ssh tar zcvf – /wwwdata | ssh root@backupserver.mydomain.com “cat > /backup/wwwdata.tar.gz”

Setting timestamp with Touch

Wednesday, July 20th, 2011

Did you know? You can Set file timestamp using touch command. One way to do this is:
touch -c -t YYMMDDhhmm filename.txt

Best Learning sites(in progress)

Tuesday, July 19th, 2011

Learnable
www.learnable.com
Brought to you by Sitepoint. They have created a site to host their on-line classes and a place for people to create their own as
well.

Udemy
www.udemy.com
Just checking this one out, I found some interesting courses, but many seem to be placeholders for classes to come later.

LiveMind
www.livemind.com
Just read about this one and have not looked thorugh it very much yet.

Vi: Remove Ctrl-M characters from a document

Thursday, June 30th, 2011

I regularly have to move scripts between Windows and Linux systems. The line endings from
Windows can make running my scripts on Linux fail. I have been on a few systems where the
dos2unix command was not available, so how do I get rid of the Ctrl-M at the end of the lines?

Command: vi -b <filename>

The -b sets vi into binary mode. This displays the extra control characters. In vi, I remove the
ctrl-Ms.

In vi, I use the following key sequence in command mode:

 :%s/<ctrl-v><enter>//g 

The ctrl-v tells vi to take the next character and display it as a ctrl char sequence. And hitting the
enter key displays the ctrl-M. The :%s///g is a command to replace the characters in the first // and replace
it with the chars in the second // and the g says to do it to every line.

Windows 7: Create Library

Tuesday, May 3rd, 2011

Windows 7 has introduced the concept of a Libary. This is a folder that can contain other folders and is available in the Windows Explorer. So you may have decided that the 4 defaults folders aren’t enough:

  • Documents
  • Music
  • Pictures
  • Video

So to create a new library:

  1. Select : Start menu->All Programs->Accessories->Windows Explorer
    or
    Press + e
    and click on the Libraries folder in the left hand column.
  2. Right click in an empty space on the folder view and select New->Library
  3. Then name your Library
  4. Right-click your new library and select properties.
  5. Select Folders to include in your library.

Each library can contain multiple folders. Now everytime you open the explorer your library will be available to you and you do not have to dig into your file hierarchy to find your most used files.

Suggested Applications:

  • Work folders
  • Project folder