Convert text files from DOS to UNIX and vice versa.

Here are few recipes to convert DOS text files to UNIX.

How do you know whether you have a DOS text file or a UNIX text file? A line feed and a carriage return terminate the DOS text files lines. UNIX uses only a line feed character. By using the Unix command file you can figure out which type of file you are dealing with.
$ file dosfile.txt 
dosfile.txt: ASCII text, with CRLF line terminators
$ file unixfile.txt 
unixfile.txt: ASCII text

$ file dosfile.txt
dosfile.txt: ASCII text, with CRLF line terminators
$ file unixfile.txt
unixfile.txt: ASCII text

To convert files back and forth from one format to another you have several options. A few of them are showed here.
 
Posted on Feb 22, 2009 by: Fred Cirera @ 14:03 Leave a comment Comments: 18

Twitter Weather station

Create your own weather station on Twitter.

With these few simple steps and this following code, you can have the weather information from where live automatically updated to you twitter account. These following steps are for a Unix/Linux/Mac environment but I am sure they can easily adapted on Windows.
 
Posted on Feb 17, 2009 by: Fred Cirera @ 22:35 Leave a comment Comments: 28

Heartbeat code for cluster environment

Working in a cluster environment, I often need to check in my Python programs, if some of the nodes of my cluster are dead or live. To do so I have in my Python toolbox, a class called Heartbeat. This is a simple heartbeat class does a ping on the cluster node, and return True, or false depending on the health of the targeted node. This class implement a stripped down version of ping. It send a ICMP_ECHO_REQUEST packet and wait for the answer.

To use this call I call the constructor with the node name, or IP address, followed by the number of seconds between heartbeats. Then every time I need to check in my program if the node is still alive, I call the method is_alive() which returns a Boolean.
 
Posted on Jan 31, 2009 by: Fred Cirera @ 23:46 Leave a comment Comments: 11

Fortune cookies on Twitter (part 2)

A couple of day ago I posted an article Unix fortune cookies on twitter containing the source code for a Python script allowing you to post Unix type fortune cookies to your Twitter account.

In that code, I was using a package called fortune developed by Brian M. Clapper. The problem is that this package does not allow you to use the existing fortunes files provided by your operating system. The .dat file used by that package are not compatible with the .dat file of your operating system. Also the actual version of the package contains a bug and the creation of the .dat file doesn't work. That's why I developed the following get_fortune() function, which can use the operating system's fortunes files.
 
Posted on Dec 07, 2008 by: Fred Cirera @ 14:00 Leave a comment Comments: 28

Python code to check your Google PageRank

The Google PageRank is a numeric value that represents how important your page is on the web. It is based on the number and quality of "backlinks" a webpage has. A high PageRank indicates that the page must be important since many sites are linking to it.

 
Posted on Aug 28, 2008 by: Fred Cirera @ 18:09 Leave a comment Comments: 38

IO Stats for NPT servers.

I am running two NTP servers for the project pool.ntp.org, one located in France, the second here in California. I am monitoring my servers with Munin. Munin comes with plenty of plugins to monitor the temperature of your computer, your disks, your CPU, etc, etc. It also comes with plugins to monitor your NTP daemon, but there is no plugin to monitor how much your NTP server is used. Since I am running open servers I was interested in finding out how much my servers where used.

 
Posted on Aug 08, 2008 by: Fred Cirera @ 18:50 Leave a comment Comments: 11

Zonbu Server

For the few last day I’ve been working on a project to turn a Zonbu machine into a NAT Server for home and small business settings.

The Zonbu machine is a small diskless computer, with 512MB of ram, and six USB2 ports, sold by Zonbu, Inc. for only $99. For that price and the addition of a few external disks, you can make a nice little NAS Server, to store, and share your videos, music, and important documents.

The NAS appliance I am building is based on the latest FreeBSD version FreeBSD-7.0. I am planning to use ZFS for volume management. That will allow the user to configure their disk with any kind of RAID, from RAID 0 to RAID 5. You will be able to share these disks on the net with any computer from Unix to Windows.

I haven’t completely definitively defined all the features this home sever will offer yet. I guess I’ll define them ad the project advances and I get feedback.

The geeks who are interested in this project can view the configuration for the kernel I am using to boot my Zonbu machine.

 
Posted on Apr 01, 2008 by: Fred Cirera @ 18:06 Leave a comment Comments: 8

Network programing with bash

In my last article I showed how to use file descriptors in shell scripts. If your shell happens to be bash you can even have a file descriptor map to a network socket.

When executing a command on a /dev/tcp/$host/$port pseudo-device, Bash opens a TCP connection to the associated socket.

 
Posted on Jan 30, 2008 by: Fred Cirera @ 17:50 Leave a comment Comments: 20

File descriptors in shell

Usually people don't know or have forgotten that they can open file descriptors in shell.

Open a file descriptor in shell can be useful for two things. Manipulate several input and output as the same time, and for performance.

 
Posted on Jan 30, 2008 by: Fred Cirera @ 12:31 Leave a comment Comments: 27

Send a multipart email in Python

This short example show how to send a mail with attachments using Python.
First we create a Mime container using the class MimeWriter and then the message is sent using smtplib package.

 
Posted on Jan 24, 2008 by: Fred Cirera @ 13:28 Leave a comment Comments: 28