Hello world!
Wednesday, January 30th, 2013Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
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]); } }
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
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: Python
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.
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”
Did you know? You can Set file timestamp using touch command. One way to do this is:
touch -c -t YYMMDDhhmm filename.txt
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.
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 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:
So to create a new 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: