Archive for October, 2008

Ubuntu: Your Custom Command PHP Script

31/10/2008

While it’s obvious for experienced users, I’m sure many newcomers to Linux might be wondering how to have a command like chmod, mv, ls, etc.

In other words, a command that accepts parameters, switches, and does interesting things in a language we all love and understand.

First of all, we’ll try phpLipsum, my newest CLI script. I wanted to have a way to access lipsum.com without any fancy GUI, just a quick command.

At YubNub.org they have online commands (very useful!), this command was the one I needed on my computer.

Handling the switches should be easy enough. We’ve seen this before, in previous articles. ;-)

$data = @file_get_contents($url) or die("\nError: Could not download the data.\n\n");
$xml = simplexml_load_string($data);

Once we have our URL built, we can make SimpleXML parse the XML for us. The text will be available through $xml->lipsum.

echo $xml->lipsum;

To make it a little bit easier on the eye I did this:

echo "\n    ".wordwrap(str_replace(".\n", ".\n    ", $xml->lipsum), 80)."\n\n";

This way, the text will be formatted nicely on the CLI. And the spaces shouldn’t affect its appearance on HTML!

Once our script is done, we make it executable. Remember how?

chmod +x lipsum.php

But I wanted to use it like this:

lipsum -a 2

So, we move it to /usr/bin/

sudo cp lipsum.php /usr/bin/lipsum

Note: You can move it (mv) or copy it (cp). I chose to copy it, so that I can keep a backup.

Now, we can finally have our own “command”! It’s quite easy and practical, and we haven’t abandoned our dear PHP. <3

Download phpLipsum

Advertisements

DreamHost: Promo Codes

30/10/2008
  • 2FREEDOMAINSWOOT: gives you two free lifetime domain registrations
  • GOOD4LESS: gives you some discount in the final price
  • TENPCENTBONUSDIS: gives you 10% more bandwidth and space, 1 free lifetime domain registration, and a $15 discount in the final price
  • TENPCENTBONUS: gives you 10% more bandwidth and space and a 1 free lifetime domain registration
  • DULCEDELECHE: gives you 20% more bandwidth and space, a 1 free lifetime domain registration, and a $16 discount in the final price
  • MOAR4ME: gives you 40% more bandwidth and space
  • 4FREEDOMAINSWOOT: gives you four free lifetime domain registrations

Ubuntu: Automatically Sort Firefox Downloads (Beta Code)

26/10/2008

IMPORTANT: This is still in testing mode. Should you try this, make sure the download is not important. If you have a monthly limit of downloads or a low bandwidth, wait and see until I have done more tests! I’ll try to keep this post updated.

You probably have heard of the famous “cron jobs” – be them from your web hosting service or your own Linux computer. In fact, I’ve covered how to use them both in Ubuntu and in Windows XP, with PHP scripts. A cron job lets you execute a command at a desired time. However, there is also incron, which stands for inotify cron. incron monitors your file system for changes, and executes a command on a specific action. Say, for example, every time a file is deleted, a script is called to log the affected file’s name and its deletion time.

(more…)

Pages: 1 2 3 4

Ubuntu: OpenOffice.org 3.0 DEB archive

13/10/2008

OpenOffice.org is a powerful free open source alternative to Microsoft Office. As the newest version came out today, the OpenOffice.org site was so strained they had to shut it down! They only use the front page to show all the downloads, for now. But for a while, some people reported it was completely offline.

Here is a mirror for the Gzip archive with all the Deb packages needed to install OpenOffice.org 3.0. It’s for Debian-based Linux distros, so if you have Ubuntu or Debian, this is what you need.

Note: I would recommend uninstalling the OOo version that comes with Ubuntu, as it might conflict with the new version.

OOo 3.0 asked me if I wanted to start afresh or import settings from OOo 2.x… So maybe you can keep the old version, import the settings by running OOo 3.0 once, then uninstalling OOo 2.x.

Important: If you’re new or not in a rush, you could wait until it’s available in the Ubuntu repositories.

Once you extract the contents of the archive, open the Terminal in the directory where all the Deb packages are, and run the following command:

sudo dpkg -i *.deb

Enjoy!

Ubuntu: OpenOffice.org 3.0 DEB archive

13/10/2008

OpenOffice.org is a powerful free open source alternative to Microsoft Office. As the newest version came out today, the OpenOffice.org site was so strained they had to shut it down! They only use the front page to show all the downloads, for now. But for a while, some people reported it was completely offline.

Here is a mirror for the Gzip archive with all the Deb packages needed to install OpenOffice.org 3.0. It’s for Debian-based Linux distros, so if you have Ubuntu or Debian, this is what you need.

Note: I would recommend uninstalling the OOo version that comes with Ubuntu, as it might conflict with the new version.

OOo 3.0 asked me if I wanted to start afresh or import settings from OOo 2.x… So maybe you can keep the old version, import the settings by running OOo 3.0 once, then uninstalling OOo 2.x.

Important: If you’re new or not in a rush, you could wait until it’s available in the Ubuntu repositories.

Once you extract the contents of the archive, open the Terminal in the directory where all the Deb packages are, and run the following command:

sudo dpkg -i *.deb

Enjoy!

Ubuntu: Piping and PHP

06/10/2008

On the Piping and File Manipulation post, I talked about directly copying the files elsewhere.

But, what if I wanted to rename and then copy them?

Well, I have yet to research how to strip certain characters from file names with the shell commands, but since I can do PHP, I decided to simply use that knowledge.

Basically, we have our script that takes a file name (with path) and parses it. Then, we can either output the new file names (for another pipe command), or we can use the exec command in PHP!

find . -name "*.mp3" | while read n; do ~/scripts/rename.php "$n"; done

Note: Remember to make the PHP file an executable (chmod +x file.php).

Note 2: The dot represents the current path. You can also replace that with a full path, if you’re not currently in the directory you wish to scan.

To access the file name, you’ll have to use the $argv array. The first index contains the full call (~/scripts/rename.php /path/to/song1.24.a.mp3), the second index contains the file name (/path/to/song1.24.a.mp3). In other words, use $argv[1].

Ubuntu: Piping and PHP

06/10/2008

On the Piping and File Manipulation post, I talked about directly copying the files elsewhere.

But, what if I wanted to rename and then copy them?

Well, I have yet to research how to strip certain characters from file names with the shell commands, but since I can do PHP, I decided to simply use that knowledge.

Basically, we have our script that takes a file name (with path) and parses it. Then, we can either output the new file names (for another pipe command), or we can use the exec command in PHP!

find . -name "*.mp3" | while read n; do ~/scripts/rename.php "$n"; done

Note: Remember to make the PHP file an executable (chmod +x file.php).

Note 2: The dot represents the current path. You can also replace that with a full path, if you’re not currently in the directory you wish to scan.

To access the file name, you’ll have to use the $argv array. The first index contains the full call (~/scripts/rename.php /path/to/song1.24.a.mp3), the second index contains the file name (/path/to/song1.24.a.mp3). In other words, use $argv[1].

Ubuntu: Piping and File Manipulation

06/10/2008

A little case scenario:

I used Rhythmbox to copy some songs to my cell phone’s memory card, and I had a nasty surprise: they all got separated into various directories, and I dislike that.

I didn’t want to manually move each file… So, instead of spending a few minutes doing just that, I spent a couple of hours finding out what piping is and stuff like that.

Most examples are very unrealistic. (“Let’s imagine we have file1, we move it to dir1…”) So I’ll use my particular case as an example.

Okay so I had all my MP3s deep into two directories each: Author / Album / Song

As some of the songs had incorrect or no information, most directories had one or two songs each. It was chaotic to find a song!

Important: If you don’t know what piping is, read this great visual explanation.

We can do this in the Terminal, from the directory that has all our subdirectories/MP3s:

find . -name "*.mp3" | while read n; do cp "$n" /new/path/; done

In the first part, we find all the MP3 files in the current directory (the dot) and its subdirectories. Then, we read its output, line by line. Each line is saved in a variable called n. As each line is, in fact, a file with its complete path, we simply use it as the source argument for the cp command.

Note: I encapsulated “$n” in quotes, otherwise, files with spaces will throw errors.

Note 2: You can replace the copy command (cp) with the move command (mv).

That way, all files are copied into one directory. ;-)

Ubuntu: All GIMP 2.6 debs in one ZIP

04/10/2008

The people at Meet the GIMP have archived all the deb packages for the GIMP 2.6, for Ubuntu Hardy Heron 8.04 (32bit).

Here is a mirror, in case their site is down or something.

Download: gimp-2.6-ubuntu32.zip (15MB, ZIP)

Extract all debs into a directory, then in the Terminal, go to that directory and run the following command:

sudo dpkg -i *.deb

Ubuntu: Windows Live Hotmail Full

01/10/2008

If you’re using the default Mozilla Firefox that comes with Ubuntu Linux, you might realize that you can’t use the full version of Windows Live Hotmail. (I like the fact that I can right-click and choose to mark as read, something the plain HTML version doesn’t allow me in any simple way.)

This isn’t because Microsoft is blocking Linux, as some people believe. The reason is that the version Ubuntu ships replaces “Firefox” with “Ubuntu” in one of its settings, and this is the setting that WLH seems to need for the full version of its AJAX interface.

All you need to do is modify a string. Go to about:config (you type that in the address bar), and search for the following setting:

general.useragent.vendor

It should say Ubuntu. Double-click on it, and a pop-up prompt will allow you to change it. Type Firefox, hit OK.

Now you should be able to go to the full version of Windows Live Hotmail.