2008-12-26

Nautilus as Root in Ubuntu

Firstly, you can just run Nautilus as root from the command line with:

gksudo nautilus

The following procedure will add a root file browser to the Applications | System Tools menu.

I got this from http://ubuntuforums.org/archive/index.php/t-256998.html.

Create a text file with:

gksudo gedit /usr/share/applications/Nautilus-root.desktop

Add these lines to the file:

[Desktop Entry]
Name=File Browser (Root)
Comment=Browse the filesystem with the file manager
Exec=gksudo "nautilus --browser %U"
Icon=file-manager
Terminal=false
Type=Application
Categories=Application;System;

Open Nautilus with: Applications -> System Tools -> File Browser (Root)

An Alternative

This is from a comment by Cerebrux to this post:

1) Open Synaptic and install the "nautilus-gksu"

2) Logout- Login

3) And now do right-click on a folder and "open as administrator".

P.S. If you want the "open terminal here" in your right-click, then just install "nautilus-open-terminal"

Firstly, you can just run Nautilus as root from the command line with:

gksudo nautilus

The following procedure will add a root file browser to the Applications | System Tools menu.

I got this from http://ubuntuforums.org/archive/index.php/t-256998.html.

Create a text file with:

gksudo gedit /usr/share/applications/Nautilus-root.desktop

Add these lines to the file:

[Desktop Entry]
Name=File Browser (Root)
Comment=Browse the filesystem with the file manager
Exec=gksudo "nautilus --browser %U"
Icon=file-manager
Terminal=false
Type=Application
Categories=Application;System;

Open Nautilus with: Applications -> System Tools -> File Browser (Root)

An Alternative

This is from a comment by Cerebrux to this post:

1) Open Synaptic and install the "nautilus-gksu"

2) Logout- Login

3) And now do right-click on a folder and "open as administrator".

P.S. If you want the "open terminal here" in your right-click, then just install "nautilus-open-terminal"

2008-12-24

SQLyog on Ubuntu

SQLyog is a popular MySQL GUI client that can be very convenient for certain operations like quickly dumping a database, schema changes. For operations that are awkward via the command line, it is useful.

I've installed SQLyog on my Ubuntu (Hardy Heron) laptop. It was very easy using Wine.

To install SQLyog with Wine

Install Wine on your Ubuntu system using the Synaptic Package Manager. As of this writing, version 1.0.0.1 was current. the exact version of Wine is probably not important.

Download SQLyog from here. I use the community edition. It is not important where you download the installation (Windows EXE) to. Just save the program file someplace convenient that you can easily navigate to via bash in the Terminal.

Open a Terminal window and change to the directory where you stored the EXE installation file. Type:

wine SQLyog714.exe

This is the exact filename that I downloaded. You will probably need to change it to the filename you downloaded.

Follow through the installation process using the standard SQLyog installer. Accept defaults. The program will be installed under a directory in your home directory called .wine.

At the end of the installation, the dialog will allow you to run the program. Go ahead and run it for the thrill of seeing a Windows program run on Linux. Wine is great!

Create a shortcut to run SQLyog in Terminal

I like to run SQLyog from the command line. I could change to the program's directory and start the program with wine SQLyog.exe. Like this:

cd ~/.wine/drive_c/Program\ Files/SQLyog\ Community wine SQLyog.exe

For convenience, I created a script to start SQLyog just by typing sqlyog. I created a text file called sqlyog with the above two lines and made it executable with chmod +x sqlyog. I have a directory in my $PATH for scripts like this, so I can fire SQLyog from anywhere.

Adding SQLyog to the Ubuntu Applications menu

On my installation of SQLyog, an entry was not made in the Applications menu to launch SQLyog. I added it to Applications | Wine by right-clicking on Applications and selecting Edit Menus. I added a new menu item with the New Menu button. The command to run SQLyog is:

env WINEPREFIX="/home/andrew/.wine" wine "C:\Program Files\SQLyog Community\SQLyog.exe"

2008-12-23

Virtual Web Server Sandboxes on Ubuntu

Problem: Multiple virtual web sites are needed on an Ubuntu machine.

Solution: Set-up virtual servers in Apache and modify the /etc/hosts file so URLs of your choosing will resolve to the virtual sites that you create.

This procedure was tested using Ubuntu Hardy Heron.

For Apache's documentation about name based virtual hosting, see:

http://httpd.apache.org/docs/1.3/vhosts/name-based.html

Step One: Modify the hosts File

The /etc/hosts text file is owned by root and allows a simple means to resolve a URL that your type into your web browser to an IP number. In this case we want our example URL of my.example.com to resolve to the IP address of the local machine, just like localhost. This is normally 127.0.0.1. Edit the /etc/hosts file with:

sudo vi /etc/hosts

Find the line that reads:

127.0.0.1 localhost

On the same line, after localhost, add a space and the name of your virtual site:

127.0.0.1 localhost my.example.com

That's it for the hosts file. You do not need to restart anything.

Step Two: Set-up a Virtual Website on Apache

Apache has the handy ability to discern the URL from a browser's address line and serve up the site that has been configured for it. This allows a server with a single IP address (like our 127.0.0.1) to host several sites at once.

For each virtual web site on the server, create a text file in the /etc/apache2/sites-available directory. Use the following template to create the file (called my.example.com in this example):


<VirtualHost *:80>

ServerAdmin username@localhost
ServerName my.example.com
DocumentRoot /home/username/public_html/my.example.com
CustomLog /var/log/apache2/my.example.com.log combined

</VirtualHost>

You will need to create this file as root, so:

sudo vi /etc/apache2/sites-available/my.example.com

Now, you can use a Debian (Ubunto is a Debian variant) utility to easily create a link to this configuration file:

sudo a2ensite my.example.com

The above line simply creates a link to the my.example.com file in the /etc/apache2/sites-available directory. This allows you to enable and disable sites easily. The Debian disable counterpart to a2ensite is a2dissite (which just deletes the link).

Lastly, reload Apache:

sudo /etc/init.d/apache2 reload

After ensuring that you have something to sever in the site's document directory, enter the URL you used in your browser's address field and try it out!

2008-04-22

Reading a File on the Internet with vi

Enter the fully qualified name of the file that you want to open in the current buffer, for example:

http://andrewault.blogspot.com/ Place the cursor over the name somewhere. In Normal Mode (not Insert Mode) type: gf

vi will use the appropriate unix utility (in this case, wget) to download the file and then read it into a new buffer.

2008-04-21

New Blog Design

I grew tired of my blog's previous design. It was a little too green, plain and sort of depressing. I've given it a bit of a makeover. I hope people this is attractive.

vi Cheatsheet Work in Progress


I've been working on a vi cheatsheet. This is still a work in progress. When it is done I want to make some coffee mugs wrapped with this graphic. Any comments or e-mail messages with suggestions are welcome.


New Google Gadget

This is a new Google Gadget I developed for The Curious Dreamer. It is available here.

2008-04-20

Healthcare Systems Compared

I love America! I am American through and through. Do I think the US is perfect? No,it is not. It is important to change and adapt as human capabilities increase and with the global marketplace. As a country we have pursued global competition the best available path for the well being of the United States and her citizens. For all these reasons, we must study the very best systems and product in the world and improve upon the best and adapt it s our own. The US spends over 15 percent of GDP on healthcare, but does not cover every citizen in a systematic and rational fashion. The US is ranked 35th (!) in quality of care and coverage by the World Health Organization. The US is ranked 37th in infant mortality in the world. Can we improve our healthcare? Frontline (on PBS), this week has an excellent comparison of five top ranked healthcare systems from around the world in relation to the US. The show, Sick Around the World, is very well done and interesting. In particular, Switzerland is an interesting case, as it is one of the countries covered that is privately based. It may be beneficial for us to dispassionately study the world marketplace and to adjust to new realities. Can GM compete with competitors that pay much less for healthcare? It is unfortunate that this is a political hot button, because it may very well be that we could improve overall health in the US at a lower cost.

SNL on Mahmoud Ahmadinejad

Man, this video is funny!

2008-04-17

Screen Capture on a Mac

It took me a while to figure out how to capture the screen to an image file using OS/X. As is usual, the answer is simple once you know it: Capture. Just run Capture using Spotlight (Command-spacebar).

2008-04-14

Google Gadgets

This weekend I researched Google Gadgets, while looking for an alternative web widget framework to the one I used for The Curious Dreamer widget I created. I have been educating myself on these semi-autonomous chunks of code that can be dropped in other sites. I want to be able to offer the creation of such things in my freelance developer business. I looked at the Microsoft version, but it is, as may be naturally expected, sort of tangled up with Windows and Microsoft development tools. At least the expectation is that you will use a Windows development system and do things the Microsoft way. There is nothing wrong with that, but I'm more comfortable in a Unix style environment, using vi as my editor and a combination of shell scripts and commands with Nautilus. Also, some research revealed that Google Gadgets can be repurposed as Microsoft widgets. I delved into Google Gadgets with the thought that I would try to get a hello gadget working and start to understand the framework. Fortunately, my experience with Prototype was useful in my understanding of how Javascript is used in Google Gadgets. I started late Sunday morning, and my five o'clock I had a working prototype that duplicates the functionality of The Curious Dreamer web widget. After I complete my current client project this week, I will flesh out the gadget I've created and test it. Google's framework is a pleasure to use and is really well designed and practical. I'm going to be able to finish this gadget and I'm keeping notes on some others that I think people will find to be useful. I want to be able to approach site owners and offer a service to create such work for others.

2008-03-29

New Version of Inkscape!

After by last post, I checked to see if the new version of Inkscape was released yet. It has been! Version 0.46 at http://www.inkscape.org/. I installed Ubuntu Gutsy and checked some of my annoyances, which are...gone! It is not perfect, but it is much better. It remembers file paths better and the Fill and Stroke dialog is now docked in the main program window. Everything I've tried has been a little bit better. Nice job Inkscape crew!

New Banner Ad Created with Inkscape

I just finished a new banner ad for my wife's dream interpretation site, MyDreamVisions.com.

I did the ad using Inkspace under Ubuntu. Open source drawing programs have come a long way. The current version of Inkscape works pretty well. With a little thought, I can create just about any image I can imagine (the limiting factor, in my case). The next version is a major upgrade and is adding a whole bunch of new features. I hope they are going to improve the user interface, which is a bit of a hodgepodge. Things pretty much work, but there are odd bugs and inconsistencies throughout.

But, like I said, it works well enough and it is possible to draw what I want to.

Here is the banner ad I made:

2008-03-27

Mac OS/X Bash Shell

Most Mac users do not have an interest in the Unix shell (running in Terminal). The Mac was carefully an exhaustively developed so an Apple user would not require it. The question is, could a more advanced user enjoy using the shell? I think, yes. Most things are done very efficiently using the Mac's graphical interface. Searching for files, opening them, copying them...all easy and efficient. Spotlight works great. But, what if you want to do something with every file found in a search? That is an example of when good old Unix shell commands or shell scripts (little programs written to run on the Bash shell) are extremely useful. How to Open Terminal Terminal is the program that the Unix shell runs in. To open Terminal, use Spotlight. Type command-spacebar (hold down the command key and press the spacebar) and enter "terminal" in Spotlight. Select Terminal from the results list. Note that the command key is the one that says "command" and has a cloverleaf looking icon - it is next to the spacebar. Or, use Finder and locate Terminal in the directory: /Applications/Utilities/ Groundwork Current Macs use a version of the Bash shell. This is the most common type of Unix shell. Most of what works generally in common versions of Unix, works on the Mac. So, when you want to use Google to find a command, or how to use a command, adding the word "unix" usually helps. If you are going to use less common parameters, make sure to also check out specific OS/X reference pages, because there are differences from one Unix to another. Case is important. Filenames, directories...just about everything is case sensitive. Therefore, you could have "photos" and "Photos" in the same directory. "ls" is the list files command. "LS" and "Ls" are not! Switches: In Unix, switches are demarcated with a hyphen ("-"). In Windows/DOS a slash character is used ("/"). When more than one switch is selected, they can be strung together after the hyphen. For instance, with the "ls" (list files) command, if you wanted to use both the "-a" (all files, including hidden files) and "-l" (long listing format) switches, the command line would be:
ls -al
Globing: Globing is the term for Unix-style "wildcards". These are handled completely differently than they are in Windows/DOS. In Windows, the program being executed is responsible for expanding wildcard characters. In Unix, the shell expands the filename specified. The Unix globing characters are:
? Matches any one character in a filename. * Matches any character or characters in a filename. [ ] Matches a character within the brackets. - A hyphen used within [ ] denotes a range of characters. ~ A tilda at the beginning of a filename expands to be the user's home directory.
Note the absence of a "." period character. Unix does not have the equivalent of Windows-style filename extensions. A Starter Set of Commands Here are a few shell commands to start with.
ls List files. This is sort of like DIR in DOS. cd Change directory. mkdir Make directory. rmdir Remove directory. cat Concatenate file(s) to standard output. Can be used to display file contents.
Jump in and get your feet wet. Next, I'll revisit this topic and expand on it a bit.

Unix Equivalent of DOS COPY CON

This is an answer to a question I got by e-mail.
"A lot of times I need to create a quick text file, like a script (like I used to create Batch files in DOS/Windows). I used to use COPY CON for this. How can I do this in Unix?"
This is just as easy in Unix. Instead of COPY CON filename, use cat >filename. As before enter the text for the file. Then close the file by hitting enter one more time and entering control-D. Remember, if you are creating a shell script, make the file executable with chmod +x filename. Also, to execute the script, remember to include the path to the script, even if you are in the same directory as the script, like this ./scriptname.

Taxpayer Demands Competent Government

It does not seem as though voting for one party or the other affects the basic competency of our government.

Is it too much to ask for? No it is not.
It is our duty to the next generation to leave a better world than the one we were born into.
The science of government it is my duty to study, more than all other sciences; the arts of legislation and administration and negotiation ought to take the place of, indeed exclude, in a manner, all other arts. I must study politics and war, that our sons may have liberty to study mathematics and philosophy. Our sons ought to study mathematics and philosophy, geography, natural history and naval architecture, navigation, commerce and agriculture in order to give their children a right to study painting, poetry, music, architecture, statuary, tapestry and porcelain. - John Adams
I wish that it was not necessary to concern myself with government. I just want to live my life, love my wife, write what I like, play music, write some code and make things. But, my morning paper sickens me with my government meddling endlessly in my life, my rights, my peace of mind and doing things in my name, with my money, that are stupid and counter to American interests.

The Adams quote I heard while watching the current HBO series. Embedded therein is the distaste for needing to understand and improve government, out of duty to his country and his children. Just a hard working and intelligent man, doing what he can in the face of loss of liberty and freedom.

2008-03-25

Something like XCOPY on the Mac?

This is an answer to a question about how to recursively copy newer files from one directory to another with a Mac. By "recursively" I mean including sub directories. ...Oh, and this is using the Unix shell in Terminal. (Remember, the easy way to get to Terminal is Command-Spacebar to open Spotlight and then type Terminal and open it. xcopy C:/source X:/destination /e/s/d/y In Windows, the above command does this and does not prompt when overwriting files. My first thought was "cp -fuRp * /destination" but there is no -u parameter in OS/X! Egad. So, then I thought of "rsync" and that seems to do the job: rsync -aruv * /destination This example assumes the directory you are copying from is the working directory.
-a Archive mode - retains file settings including dates -r Recursive - subdirectories -u Update - only copy newer files -v Verbose
Remember! Don't use "*.*" in unix. There are no Windows-style file name extensions. Yes, it is different from Windows. Yes, it has to be learned to be used. Keep in mind that you had to expend effort to learn DOS/Windows commands and that Unix isn't going away - what you learn will continue to be useful are a long time. One more thought: Pop music is enjoyable right away, but grows tiresome quickly. Classical music can take effort to learn to enjoy, but grows more enjoyable in time. So it is with shell commands - they take effort to learn and enjoy, but continue to pay dividends forever.

2008-03-24

Mass File Renaming in Unix or Linux

Here's a quick script that you can use to rename a bunch of files. It will rename all of the files in the working directory that have certain text to something else that you specify. For example, when you have a group of photos from a digital camera with sequentially numbered files like "IMG1.JPG, IMG2.JPG, IMG3.JPG...etc." that your would like to be called "2008-feb-baseball-1.jpg, 2008-feb-baseball-2.jpg, 2008-feb-baseball-3.jpg...etc.". The Code Create a text file called massren with this as the content:
#!/bin/sh for filename in *$1* do mv -fT "$filename" `echo $filename | sed -e "s/$1/$2/"` done
Then, make the file executable with:
chmod +x massren
Usage
masren textfrom textto Where: textfrom is the text to replace in each file name. textto is the new replacement text.
Example For example, to rename the files cited in the first paragraph:
./massren IMG 2008-feb-baseball- ./massren JPG jpeg
The first command replaces "IMG" in every file name to "2008-feb-baseball-". The second command replaces "JPG" in every file name to "jpeg". The reason I put "./" at the beginning pf each line is that on my system the working directory is not in the path. So, this addresses the script "massren" in the working directory explicitly...pretty normal in unix shells. Examining the Code
#!/bin/sh for filename in *$1* do mv -fT "$filename" `echo $filename | sed -e "s/$1/$2/"` done
This tells your unix shell where to file the program that executes this script. in this case, it is a Bach shell script and the program on my system is called "sh" and is in the "/bin/" directory. This line, in unix jargon is called the shebang line. This creates a variable called "filename" in a loop (from "do" to "done on the following lines) for each file in the working directory (the current directly) for each file that has the "textfrom" text that you specified. The "$1" in "*$1*" is a variable that contains the first parameter (like "IMG" in the example). The asterisks surrounding it mean that any file with this text somewhere in the file name will be selected. The "do" and "done" lines contain the loop. The code between them will be executed for every file matched on the green line. This line renames each file. In unix, "mv", the Move command is also used to rename files. The -fT parameters tell mv to go ahead and rename the file and that the file is being renamed and not being moved to another directory. You can see that we are using the $filename variable that was created on the green line - remember that this is a loop and will be run for every file that meets our criteria. "$filename" is enclosed in quotes in case the files being renamed has spaces in the name (in which case, the fromtext parameter would need to be quoted also. The next part is where the new file name is created using the "sed" command. Note that it is enclosed in "`" characters, called back ticks in unix jargon. Everything enclosed in back ticks is executed and the results of that execution is substituted in the brown command line. So, the current file name (in the $filename variable) is echoed through the sed command. "echo" gets the file name, the "|" (called a pipe in unix jargon) takes that text (the file name) and pipes it into the sed command. The sed command being used substitutes all of the fromtext (in the $1 variable) with the totext (in the $2 variable). Check out a reference for sed for details. You will see that the "s//" command does a simple substitution of one instance of text with another. Make your Own Command Take what you learn here and create your own mass file renaming script! Replace "*$1*" with a globing specification that selects the files you want to process. Replace the sed command I used here with, for example a tr command. You could use tr to rename file from UPPERCASE to lowercase: tr '[A-Z]' '[a-z]' You can easily debug your new script by inserting echo at the beginning of the brown line to just show the mv command line being created for each file instead of executing it. For example, for the new rename to lower case:
#!/bin/sh for filename in * do echo mv -fT "$filename" `echo $filename | tr '[A-Z]' '[a-z]'` done
Note that the selection criteria went from "*$1*" (select files that contain specified text) to "*" (all files in the working directory). Production Version
#!/bin/sh
#
# massren: Mass file rename utility
#
if [ $# -eq 2 ]
then
    for filename in *$1*
    do
          mv -fT "$filename" `echo $filename | sed -e "s/$1/$2/"`
    done
    exit 0
else
    echo "\nUsage:"
    echo "masren textfrom textto"
    echo "\nWhere:"
    echo "textfrom is the text to replace in each file name."
    echo "textto is the new replacement text.\n"
    exit 1
fi

2008-03-16

My Dream Visions Updated

I just finished converting My Dream Visions to a database-driven, CSS-formatted website. Part of the update is a streamlined order processing system for the site.