Archive for March, 2008

Downloading Files from Command Line via FTP

At the command line, enter ftp <serverName>.

If you have a user name and password, enter them. Otherwise, use the default of Anonymous and a blank password.

Use cd, ls, etc. to work your way around the directory structure.

If you want to download a particular file, specify get <fileName>.  If you want to download many files, use mget <filePattern> (for example, mget *.gz). By default it will ask you to confirm every file download. You can disable this by entering prompt and then hitting Enter before doing the mget.

Enter bye to exit.

(I think this works the same on Windows as it does on *nix operating systems.)


March 31, 2008 at 10:15 pm Leave a comment

Upgrading MySQL on Red Hat Linux Despite Dependency Conflicts

Recently I needed to upgrade MySQL from version 4.1 to 5.0 on Red Hat. I was having some dependency conflicts that were vexing me. After searching around the Web I figured out how to do it. Because I’m a Linux novice, I’m sure there are more details I don’t understand, so if anyone wants to provide insight, that would be great.

Here are the basic steps I performed:

  1. Downloaded the .rpm files from the MySQL site (server, client, shared libraries, shared compatibility libraries) for my O/S version to a single folder on the server.
  2. Tried the basic install (from the directory with the .rpm files): rpm -ivh MySQL-*
  3. That gave me errors about dependency conflicts with previously installed MySQL packages. I used this command to find out which packages were installed: rpm -qa | grep mysql
  4. I went through one by one trying to uninstall them (rpm -e <package name>). However, I ran into problems because there were some duplicates. For the duplicates I ran the following command: rpm -e –nodeps –allmatches <package name>.
  5. Then I reran the install command from step 2, and it worked!

This page has some helpful tips on starting up the MySQL service and setting the root password, etc.

March 31, 2008 at 9:12 pm Leave a comment

Sorting Dictionaries in Python

Newer versions of Python have a built-in function called sorted that can help you sort dictionaries. Below is the basic functionality.

Sort by key:


Sort by value:

class SortedDictionary:
  def __init__(self, dictToSort):
    self.keys = sorted(dictToSort.iterkeys())
    self.values = [dictToSort[key] for key in self.keys]
    self._lastIndex = -1

  def __iter__(self):
    return self

  def next(self):
    if self._lastIndex < (len(self.keys) - 1):
      self._lastIndex += 1
      return (self.keys[self._lastIndex], self.values[self._lastIndex])
      raise StopIteration

x = {}
x['abc'] = 1
x['aaa'] = 2

y = SortedDictionary(x)
print y.keys
print y.values

for z in y:
  print z

March 28, 2008 at 10:36 pm Leave a comment

Copying from One Directory to Another in Linux

cp FileName.txt DirectoryName/

March 27, 2008 at 7:50 pm 1 comment

How to Install tar.gz Files in Linux

cd Download_Dir/
tar -xvfz file.tar.gz
cd file_dir/
make install

March 25, 2008 at 3:24 pm Leave a comment

Append a List to a List in Python

(Note: Please see my latest posts at my new blog!)

An easy way to do this is with the extend function:

x = [1,2,3]



March 19, 2008 at 4:47 pm 11 comments

Simple Method to Calculate Median in Python

(Note: Please see my latest posts at my new blog!)

def getMedian(numericValues):
  theValues = sorted(numericValues)

  if len(theValues) % 2 == 1:
    return theValues[(len(theValues)+1)/2-1]
    lower = theValues[len(theValues)/2-1]
    upper = theValues[len(theValues)/2]

    return (float(lower + upper)) / 2  

def validate(valueShouldBe, valueIs):
  print “Value Should Be: %.6f, Value Is: %.6f, Correct: %s” % (valueShouldBe, valueIs, valueShouldBe==valueIs)  

validate(2.5, getMedian([0,1,2,3,4,5]))
validate(2, getMedian([0,1,2,3,4]))
validate(2, getMedian([3,1,2]))
validate(3, getMedian([3,2,3]))
validate(1.234, getMedian([1.234, 3.678, -2.467]))
validate(1.345, getMedian([1.234, 3.678, 1.456, -2.467]))

March 17, 2008 at 10:14 pm 21 comments

Older Posts