How To

How to Print Prime Numbers, a C++ Example

The following code uses the Sieve of Eratosthenes method to print all prime numbers in the range of 2 to n, while n being the upper limit, command line integer you feed into the program. You could also just hard code n if you wanted to. Since it's in C++, this code can easily be ported to PHP or other languages that share similar syntax.

How to Recursively Copy Files from a Remote Host using wget and FTP

Tags:

wget -r ftp://username:password@your.ip.address/dir/*

OR

wget -r –user=your_username –password=your_password ftp://ftp.yoursite.com/dir/*

Note the * at the end of the commands, you will need this else wget just retrieves the single, index file 

How to get the last created auto-increment ID from a MySQL table

If you’re like me then you’re developing like crazy.  Once in a while you may need to retrieve the auto-increment ID value from the last created row you inserted into a particular mysql table.  Yea… when you insert a new row into a mysql table there is no apparent way to just return the ID from the row’s auto-increment field.  So to do this using PHP, simply use the

mysql_insert_id()

functin, which will return the last created ID as an interger.

How to Help Eliminate Spam with SPF Records

Tags:

I really hate spam.  I’m sure just about everyone does.  I really hate it though when spammers forge my own email address as the sender, then I mark it as spam, then I inadvertantly end up having legit emails dumping into my spam box!  Ouch, talked about a breakdown in communication.

Searching for a string in a gz compressed file

Tags:

Gzip is a compression technology available on most unix/linux systems.  Once in a while you might see a file such as filename.gz or filename.tar.gz and you may need to search through that file… I know some popular web server programs, such as apache, compress old log files to save space…

If you need to search through a .gz file, just use the zcat command (similar to cat):

zcat file.gz

Linux: change a large number of file names, all at once

Tags:

How do I change a lot of file names all at once, and using the linux command line?  Look no further.  Let’s say you have a bunch of images in your current directory (let’s create them like so for testing purposes):

for x in {1..100}; do touch “image$x.gif”; done

Now that you have all 100 gif images files, just run the following command to change them to have the .jpg file extension:

for x in *.gif; do mv “$x” “${x%.gif}.jpg”; done

Syndicate content