2008-07-18

A simple HTML-CSS scrolling data box with fixed column headers

I have a number of web pages where large tables of data are presented, and I wanted a way to display them so that when the user scrolled through the data the column headers would stay fixed and not scroll out of view.

My solution was to create a div with a fixed height and width and with its overflow property set to scroll, and then put the actual data table inside that div. Then I put the column headers in a completely separate table outside and right before the div. This way the column headers stay fixed on the page and the user can use the scroll bar that appears on the data div to scroll through the data without moving the whole web page.

The toughest challenge was figuring out how to get the column headers to consistently line up properly with the data columns, since the default behavior for HTML tables is for the columns to be sized based on the data in each cell, and so left to their own devices the columns of the data table would be different each time your data changed.

Just setting the width property of the table cells in CSS, alone, did not work since it appears to me that the default behavior is ignore the width property on td elements. After a lot of trial and error I discovered that the following combination appears to work for me:

- In CSS set the table-layout property for the data and column header tables to fixed.

- In CSS set the width properties for both the data and column header tables to be some value which is less than or equal to the sum of all of the column widths. If you don't do this (i.e. just leave the table width property blank or set it to more than the sum of the column widths) then the columns will not stay fixed in at least Firefox 2, though it will probably still work in IE7. I think this is because in FF2 even if you set table-layout: fixed in CSS it will expand the cells as needed to take up the whole width of the table, and if you don't set the table's width explicitly it will inherit the width of the div it is inside.

- Create a CSS class for each column and set the width property for each column to the right number of pixels, and then give each td of both tables the appropriate class.

Here is rough outline of the code elements. This particular code is not designed to be fully cut and paste, and its air-code, so just use it to understand the idea:


CSS

div.datagrid
{width: 1000px;
height: 400px;
overflow: scroll;
border: 1px solid black;
font-size: 11px;}

table.headers_and_data
{border: 1px solid black;
border-collapse: collapse;
table-layout: fixed;
width: 980px}

td.col_0
{width: 71px}

td.col_1
{width: 150px}

td.col_2
{width: 300px}

td.col_3
{width: 478px}

HTML

// Output column headers table
<table border="1" class="headers_and_data">
<tr>
<td class="col_0">Column 0</td>
<td class="col_1">Column 1</td>
<td class="col_2">Column 2</td>
<td class="col_3">Column 3</td>
</tr>
</table>

//Start a new div with specified height and overflow set to scroll so that table
// of items is scrollable (see style for this div) and then start data table.
<div class="grid">
<table border="1" class="headers_and_data">
<tr>
<td class="col_0">Mississippi</td>
<td class="col_1">Jackson</td>
<td class="col_2">Delta swamps</td>
<td class="col_3">Possum</td>
</tr>
</table>

2008-05-02

How to import POIs from Google Maps to Maemo Mapper

This is just one method and I haven't tried it with anything more complicated than a short list of POIs.

  • Go to My Maps in Google Maps and save all the placemarks on a new map.
  • Click the View in Google Earth link, and then save the KML file to your computer.
  • Go to GPS Visualizer and convert the KML file to a GPX file.
  • Save the GPX file to your computer, and then move it onto your N800.
  • In Maemo Mapper choose POI -> Import and import the GPX file.
  • Done (hopefully)

2008-04-27

Xubuntu 8.04 on Dell Inspiron 8100

Here are the steps I went through in installing Xubuntu on an old Dell Inspiron 8100. This is not a How-To!


  • Downloaded the CD for Xubuntu 8.04 from the Xubuntu site and burned to a CD.

  • Booted laptop from CD and chose the option for trying Xubuntu without making any changes. Successfully got the Xubuntu desktop, but the wireless card wasn't working.

  • Rebooted laptop with CD in drive and this time chose Install Xubuntu.

  • chose the right language, keyboard, and location for me.

  • On the partitioner options I chose guided, resize windows partition and create a new partition for ubuntu. However, this option failed after a long time of the system working on it, saying something about some write to disk failed. So I clicked the back arrow on the installer dialog until I got back to the beginning of the partitioner and chose to reformat the entire disk.

  • Rest of install finished without any problems. Removed install CD and rebooted into Xubuntu without any problems.

  • The little 'Restricted Drivers' icon was on the top toolbar, and when I clicked on it it said that NVIDIA accelerated graphics driver was available. I am a little scared of NVIDIA drivers on Linux due to some past experiences so I decided to leave this alone for now.


Getting the Netgear WG511 v2 wireless card to work.

  • The wireless card didn't show up under Networking, so I started following the instructions given here:
    https://help.ubuntu.com/community/WifiDocs/WirelessTroubleShootingGuide

  • First ran $lshw and saw that my wireless card was apparently detected as
    Product: 88w8335 [Libertas] 802.11b/g Wireless
    vendor: Marvell Technology Group Ltd.
    physical id: 0
    bus info: pci@0000:0d:00.0
    configuration: latency=0

  • According to the web page, if there is no driver listed under configuration that means no driver is loaded, which is what I suspected anyways.

  • Poked around a bit on google, doesn't look like there is a native linux driver for this chipset, so on to plan B.

  • Wireless card is Netgear WG511 v2. Googling this and linux led me to this blog entry:

    http://verens.com/archives/2005/02/21/installing-a-netgear-wg511-v2-marvell-chipset-in-linux/

    Unfortunately the link there to the Windows driver for this card are broken. Looked for the CD for the card and couldn't find it.

  • Went to the NDISwrapper website list of supported chipsets and found an entry for the Marvell chipset and a few entries for the card. Downloaded the drivers from each.

  • Used Synaptic to install ndiswrapper-common ndisgtk and ndiswrapper-utils-1.9

  • Downloaded drivers from here:
    http://www.parseerror.com/cache/drivers/WG511v2/WG511v2-cd/Driver/
    and then used the ndisgtk front end (Applications -> System -> Windows Wireless drivers) to install it. After that iwconfig seemed to show it as wlan0 so I guess it worked.

  • Next went to install WPA supplicant using Synaptic but it was already installed. So I went ahead and followed the instructions here for setting it up:
    http://ubuntuguide.org/wiki/Ubuntu:Feisty#How_to_enable_WPA_with_Ndiswrapper_driver

  • Success! Wireless is working using WPA.


Trying out the NVIDIA restricted driver. I noticed that the backlight was still on when the screen blanked after being idle, which meant that there would be no power savings from screen blanking, so I decided to go ahead and try the restricted NVIDIA driver (Applications -> System -> Hardware Drivers). I checked the NVIDIA box, let it do its stuff downloading and installing the driver, and then rebooted. Thank goodness the new driver worked!


Connecting to NSLU2 network attached storage device

  • Tried a bunch of variations on the mount command with no luck

  • On a hunch, opened up Synaptic and searched on smb and saw that the smbfs package is not installed by default. This packaged is needed in order to read and write from Samba/windows shares. Installed package.

  • Created mount point:
    $mkdir /home/andy/mount_point

  • Then mounted share (which has no password protection on it):
    $sudo mount -t cifs //10.10.10.123/DISK\ / /home/andy/mountpoint

  • Success! Able to get files from the NSLU2


Transferring Firefox Profile

  • Tried the old way of just copying my Firefox profile from another computer over the profile at /home/andy/.mozilla/firefox/jdkfjld.default but the bookmarks didn't come through

  • Tried deleting everything out of the Firefox profile and copying the old profile into it, and that seems to have worked, though I think there was probably a better way to get the bookmarks in since I think Firefox 3 uses a different system for bookmarks.


Installing MS core fonts and cleaning up font appearance.

  • Used Synaptic to install msttcorefonts. Got a message that I would need to install and configure x-ttcidfont-conf in order to use them in X-windows. However, after I installed msttcorefonts Times New Roman showed up as an option in Firefox for default font, and when I checked Synaptic it showed x-ttcidfont-conf as already installed.

  • Next clean up font rendering. Applications -> Settings -> Settings Manager -> User Interface, check 'Use sub-pixel hinting' and also changed 'Use hinting' setting from Full to Slight.

  • Much better; Fonts look a lot better on Firefox, not as blurry


Remove one panel and move the main panel to the bottom of the screen.

  • Applications -> Settings -> Settings Manager -> Panel, then in Panel Manager select Panel 2 and then click minus sign to remove bottom panel.

  • Move remaining panel to bottom by going into Panel Manager and clicking button for bottom of screen, then select Normal Width instead of full width to make it look more Mac Dock like (but not really)

  • Add icons for open windows to panel by right clicking on panel, then choose add new item then find and select Icon Box.

  • Slim down the Applications button by right clicking itm, choose properties, and then unchecking the box that says show title in button

  • Get a more Mac look by going to Applications -> Settings -> Settings Manager -> Window Manager and then select Agua or Agualemon.

2008-02-15

BASH scripts on Mac OS X

I learned today how to use a BASH script on Mac OS X.

Just create a text file and put #!/bin/bash on the first line, and then write the rest of your BASH script and save.

Then make the file executable by opening Terminal and running
chmod +x scriptname.sh

Then you should be able to run it from the Terminal command line.

To make it so you can run the script by just double clicking on it in Finder, just change the extension of the script file to be .command

See Introduction to Open Source Scripting on Mac OS X

2008-02-05

Proper Mapping of Modifer Keys for Synergy with Windows Server and Mac Client

Synergy is a great program that allows you to use one keyboard and mouse to drive a number of computers whose monitors are next to each other. See http://synergy2.sourceforge.net/. I have it set up so that my keyboard and mouse connected to my Windows box can be used on my Mac mini whose monitor is to the right of my Windows box monitors. When I move the mouse off the right edge of my Windows monitor it magically shows up on my Mac mini monitor, and if I then use the keyboard it magically sends to the Mac mini instead of the Windows box its physically connected to. I can also block and copy text between the two systems. At free its a heck of a lot cheaper than a KVM switch, and since switching between computers is as easy as moving the cursor from one monitor to the other, its a lot more convenient than hitting a switch to move.

In any event, the real purpose of this post is to show how to correctly map the modifier keys (Ctrl, Alt, Windows etc) when your Synergy Server is on a Windows box and your client is a Mac. By default, for me, the Alt key on my keyboard was acting like Command on my Mac. Here is how to get the Windows key on a keyboard connected to a Windows box to map to the Command key on a Mac.

Start up Synergy on the Windows box.
Click on the Configure button next to Screens & Links.
In the Screens box click on the name of your Mac, and then click the Edit button below the screens box.
In the Modifiers area assign Alt to Super and Super to Alt.
Click OK, exit Synergy, restart your Synergy server and it should work.

2008-02-04

Using Mac OS X Leopard Preview to Manipulate PDF Files

Update 2011-01-09: I finally got around to installing Snow Leopard on my main Macbook and discovered that Preview handles this stuff a little differently.  The instructions have been updated for Snow Leopard 

I do all my filing paperless, so I am in the habit of scanning batches of snail mail as a single PDF and then breaking out and saving pages as separate PDFs for filing, and sometimes combining multiple PDFs into a single PDF. In Windows I had always used Adobe Acrobat Professional to do this, but my personal Mac mini challenge was to replicate all the functionality I have in Windows in Max OS X Leopard.

I didn't see an obvious tool for this built-in to Leopard, so I spent a lot of time downloading and trying out various freeware applications (mostly Java based) for breaking apart and merging PDFs, but they are were all pretty awkward to work with. Then I decided to take a hard look at Preview to see if I could get it to do what I wanted. Here is what I found:

To extract a single pages of a PDF in Snow Leopard Preview:
1. Highlight the page(s) you want in the Sidebar and hit Command-C to copy to the clipboard (For some reason you can't seem to do this with multiple pages).
2. Then go File -> New from Clipboard (or just Command-N). A new Preview window opens up with just the single pages you copied.
3. Then do File -> Save As or Shift-Command-S to save the new PDF.
4. You can also drag the selected pages to the Desktop and it will create a new PDF of those pages.

To extract multiple pages of a PDF in Preview:
1. Extract a single page as outlined above.
2. Open your new single page PDF in Preview next to your already open source PDF.
3. Select all of the pages you want to extract in the Sidebar of your source PDF, and then drag and drop and drop them where you want them to go in the Sidebar of your target PDF. They show up in your target PDF where you dropped them.
4. Save your target PDF using File -> Save As or Shift-Command-S.

To combine multiple PDFs in Preview:
1. Open one PDF in Preview.
2. Drag the PDF file you want to add from Finder onto the Sidebar of the PDF you have open in Preview and drop it directly on top of the existing page (if it is a single page) or directly on top of the page with the binder showing (if the existing PDF is multiple pages).  In Snow Leopard, if you just drop the file on the sidebar it doesn't combine the PDFs by default; you have to drop directly onto a page.

2008-01-30

Getting started with my Mac Mini

After using MS operating systems for 20 years (DOS then Windows) I finally decided to buy a Mac to be used as my primary non-work machine. I got a Mac Mini 1.83 GHz Intel Core 2 Duo with 1 GB of RAM and Mac OS X 10.5.1. What follows are some notes on my thoughts and experiences over my first few days as a Mac owner.

The Mac font smoothing makes fonts look really blurry to me. Under System Preferences -> Appearance its possible to turn off font smoothing for font sizes 12 or smaller, and if you download TinkerTool its possible to use it to turn off font smoothing for larger sizes. After some playing around I decided to set the font smoothing cutoff at 16 pt. Turning off smoothing helps a bit, however, Mac's rendering of unsmoothed fonts is definitely not as good as Windows, and may not be as good as Ubuntu (I haven't done a real side by side comparison yet). According to various posts on the web the difference is explained by Apple deciding to optimize their screen fonts so they match the printed appearance as much as possible, while Microsoft optimizes for screen appearance. Since I maybe print out 6 pages of hard copy a year, you can imagine which approach I favor.

One thing about the Mac that surprised me was its lack of built-in support for working on mixed networks. After hearing about how everything 'just works' on a Mac, and how Mac OS X was built on some flavor of Unix, when I wanted to edit a PHP file on my Linux home web server I cheerfully clicked on mount network drive and typed in sshfs://10.10.10.120 expecting to quickly mount the drive from my Linux box using sshfs. Nope. SSHFS is not built-in in OS X Leopard. After poking around a bit it looks like Apple offers a download to add sshfs support, or you can use a shareware filemanager that includes sftp support, or you can use MacFuse from Google. I decided to give MacFuse a try, and so far it seems to work, though I haven't really given it a workout.

Other options I have discovered for working with sFTP/sshfs are to use a 3rd party file manager that includes support for it (I am trying out Forklift at the moment, but there are others), or for text files using the TextWrangler text editor which has built-in support for editing files over ssh.

I was also shocked that although I could mount an ftp volume in Finder it was read-only even though the ftp server was set to give me read-write privileges. According to the Apple website this is a feature, not a bug, and you have to use a 3rd party app to be able to upload files to an FTP server. I tried Filezilla, but didn't like its apparent lack of keyboard shortcuts for copying files Same with Fugu, another free application for sftp transfers. Downloaded beta of Forklift and so far it looks like what have been looking for. You can choose Commander keyboard shortcuts which gives you F5 to copy a file from one pane to the other like I am used to. I didn't get around to trying Cyberduck.

No luck getting my Xerox Documate 250 scanner to work with the Mac Mini. Apparently there are no Mac drivers for it, and just plugging it and seeing if it would work didn't. When I ran out of possible leads to pursue I went ahead and ordered the $86 OEM version of Windows XP from Newegg.com so that I can dual-boot XP on the Mac Mini so that I can scan PDFs. It may sound extreme, but I am a fanatic about being paperless and I gotta have my scanner. Anyways, I am sure that I will discover other things that I will need to have a copy of XP around for.

Once I committed to having a dual boot machine I looked into running both OSs at the same time using either VMware Fusion or Parallels. From posts on the web it seems they both work well and are more or less equivalent. However, one friend who uses Parallels remarked that it takes a lot of RAM to run two OSs at the same time, so I promptly went to Crucial.com and ordered 2 GB of RAM for the Mini, which showed up on my doorstep 2 days later.

Upgrading the RAM on the Mac Mini is not for the faint of heart. I followed the excellent directions at:
http://www.methodshop.com/gadgets/tutorials/macmini-ram/index.shtml
You haven't lived until you are prizing off the cover of your brand new expensive toy with a couple of plastic putty knives and hearing all kinds of snap-crackle-pop noises as the little tabs pop loose. To make things more fun, the RAM in the Intel Mac Mini is hidden underneath the hard drive and optical drive, so things have to be unscrewed, and a little cable carefully removed, to get at it. Although it was an intimidating process to launch into, in actual execution it went pretty smoothly and the whole thing took less than an hour from start to finish.

2008-01-29

IE7 puts a margin around form elements but Firefox doesn't

I was going nuts trying to figure out why IE7 put some unwanted white space around a table but Firefox rendered it properly with no margin, despite explicitly setting margins for the table as 0 in CSS.

After a lot of trial and error, and fruitless Google searches, I figured out that it was the Form element that I had inside the table that was causing the problem. Apparently IE7 puts a margin around a Form element by default but Firefox doesn't. To get rid of the unwanted whitespace I just added the following to my CSS:

Form
{margin: 0px}

2007-10-30

Font problems with Nvidia driver in Ubuntu

After I switched to using the Nvidia proprietary driver in Ubuntu instead of the nv driver, the font sizes on my system were all wacky (many, but not all, became too small). After some research I discovered that it was due to the DPI being set wrong in X. There is a great post here about what causes the problem and how to fix it:

nVidia versus fonts!

The short version is you need to figure out the DPI of your screen and then add the following lines to the Device section for your nvidia driver in xorg.conf:

Option "UseEdidDpi"   "false"
Option "Dpi" "92 x 92"

Replace 92 x 92 with the horizontal and vertical DPI of your display.

2007-10-07

Javascript date spinner control to roll ISO 8601 dates in a text field using arrow keys

I have a couple web applications where the user enters or edits dates in the near future or near past in a text field using ISO 8601 format (yyyy-mm-dd). I wanted a javascript function which would allow the user to quickly modify the date by a few days without having to delete an old date and type in a new one, i.e. just hit one key to increment or decrement the date by one day. Since I couldn't find anything out there to do this I wrote my own. The main function here is roll_dates() which gets called by the onkeydown event of a text field on a HMTL form.

I am a self-taught coder, a beginner with javascript, and I haven't carefully tested this, so please only use this as an example to help give you ideas for your own coding (i.e. don't blindly block and copy this into your own code and then be surprised when it doesn't work right or breaks something).


function date_object_to_iso_date(date_var)
{// Converts a date object to an ISO date (YYYY-MM-DD)
// Add 1 to month value since Javascript numbers months as 0-11
var month_var = (date_var.getMonth()+1)+"-";
// Add a leading zero if its a one digit month
if (month_var.length==2)
{month_var="0"+month_var}
// Add a leading zero if its a one digit date
var day_of_month_var = (date_var.getDate())+"";
if (day_of_month_var.length==1)
{day_of_month_var="0"+day_of_month_var}
var iso_date_var=date_var.getFullYear()+"-"+month_var+day_of_month_var;
return iso_date_var;
} // close function

function increment_date(date_var, var_amount)
{//Takes a date object and adds one day
date_var.setDate(date_var.getDate()+var_amount);
return date_var;
} // close function

function iso_date_to_date_object(iso_date_var)
{ //Converts an ISO date (2007-10-01) into a date object
var array_temp=iso_date_var.split("-");
var date_var=new Date(array_temp[0],array_temp[1]-1,array_temp[2]);
return date_var;
} // close function

function roll_dates(event_var, id_var)
{// Increments or decrements an ISO date using up or down arrow
// Designed to be called by the onkeydown event of a textfield
// i.e. onkeydown="roll_dates(event,'fieldid')"
var keynum_var = event_var.which;
// Only do rest of function if user hit up or down arrow
if (keynum_var == 38 || keynum_var == 40)
{var textfield_var = document.getElementById(id_var);
var iso_date_var = textfield_var.value;
// Use regular expression to check if ISO date was entered,
// and if not use today's date
var iso_check_regex = /20[0-3][0-9]-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])/;
if (iso_check_regex(iso_date_var))
{var date_var = iso_date_to_date_object(iso_date_var);}
else
{var date_var = new Date()}
// Increment or decrement value based on whether user hit up or down arrow.
switch (keynum_var)
{case 38:
date_var = increment_date(date_var,1);
break;
case 40:
date_var = increment_date(date_var,-1);
break;
} // close switch
iso_date_var = date_object_to_iso_date(date_var);
textfield_var.value = iso_date_var;
} // close if
} // close function

2007-09-30

Mount remote filesystem on Ubuntu Feisty using SSH

First install the ssh filesystem:
sudo aptitude update
sudo aptitude install sshfs


Create a mount point for the remote computer and make yourself owner:
sudo mkdir /media/remote_computer_name
sudo chown andy /media/remote_computer_name


Add yourself to the fuse group:
sudo adduser andy fuse

Log out and log back in so that the new group membership takes affect.

Mount the remote computer:
sshfs 10.10.10.120:/ /media/remote_computer_name/

There were additional steps listed on one HowTo that I didn't follow but it worked anyways:
http://ubuntuguide.org/wiki/Ubuntu:Feisty#How_to_mount_remote_host_folders_into_local_Ubuntu_machine_.28sshfs.29

2007-09-24

How to permanently mount a windows (samba) share on Ubuntu

These are barebones directions for mounting an NSLU2 drive on an Ubuntu box.

Install the smb file system: sudo apt-get install smbfs

Create a new directory under /media to use as a mount point: sudo mkdir /media/newdirectoryname.

Edit /etc/fstab: sudo nano /etc/fstab

Add a line for the new mount:
//10.10.10.110/DISK\0401 /media/newdirectoryname smbfs username=defaults,password=defaults,uid=username 0 0

Remount filesystem: sudo mount -a

For more detailed instructions: http://www.justlinux.com/nhf/Filesystems/Mounting_smbfs_Shares_Permanently.html

Additional Notes on how to allow users on Linux machine to read and write to a smbfs share that is mounted by adding entry in fstab:

  • The fourth field in an etc/fstab entry specifies the mount options for the drive being mounted. See the fstab man page or http://www.die.net/doc/linux/man/man5/fstab.5.html
  • The fstab man page doesn't give the mount options for every type of file system. For that you need the man page for the file systems. The man page for smbmount gives the syntax for specifying options in this fourth fstab field for smbfs mounts. See http://www.die.net/doc/linux/man/man8/smbmount.8.html
  • You can either use uid=username or gid=groupname to specify what user or group of users is the owner of the smbfs mount.
  • Here is the fstab entry that allowed linux user fred to copy files to smbfs mount on an NSLU2:
  • //10.10.10.110/DISK\0401 /media/nslu2 smbfs username=defaults,password=defaults,uid=fred 0 0
  • EDIT 2008-11-10: I believe that fmask and dmask properties discussed below have been deprecated and you should use umask in their place. I think a single umask=0000 in place of fmask and dmask should work, but I have not verified this.
  • After a lot of trial and error I figured out that its not enough to add the gid=groupname to the fstab entry. You also have to set fmask and dmask values which determine permissions for the mount. This fstab entry allows all members of group fredsfriends to read and write files on an smbfs mount:

    //10.10.10.110/DISK\0401 /media/nslu2 smbfs username=defaults,password=defaults,uid=fred,gid=fredsfriends,
    fmask=770,dmask=770 0 0
  • Apparently if you don’t set fmask and dmask then it uses the system default (umask value?) for file and directory permissions, which on my ubuntu install was read access but not write access.
  • I had a hard time finding out what values to use for fmask and dmask, but apparently 777 means all users have read & write access (which was apparently confirmed by running ls -l on the mount, which showed fred fredsfriends -rwxrwxrwx when dmask=777 and fmask=777), and a value of 770 gives read-write access to only the members of the group identified in gid=groupname (ls -l shows fred fredsfriends -rwxrwx—).
  • Another thing to note is that apparently in Linux only the owner of a file can change the timestamp, so a user that has read-write access to a smbfs mount by virtue of being a member of the group specified in gid=groupname will not be able to change timestamps on files on the mount, which means that when that user copies a file to the mount the file’s existing timestamp will not be carried over and instead it will be given the timestamp of when the copy action occurred.

2007-09-18

Ubuntu cheat sheet

BASH prompt tricks

  • To search back through the command line history for a particular term hit Ctrl-r and then type the term. Hit Ctrl-r again to move backwards to the next instance of the term.
Cron
  • To edit the current user's cron jobs: crontab -e
File operations
  • See size of current directory: du -hs
  • See size of specified directory: du -hs /mydirectory
  • See listing of subdirectories with sizes: du -h /mydirectory
  • List of directories sorted by size: du /mydirectory | sort -nr
  • Recursively delete directory and its contents: sudo rm -Rd /media/temp/mydirectory
  • Recursively delete the contents of the current dir: rm -R *
  • Recursively copy /media/source/Documents to directory Documents under current directory preserving permissions, ownership & timestamps: sudo cp -av /media/source/Documents Documents
  • Recursively copy /media/source/Documents to /media/temp/Documents preserving permissions, ownership & timestamps: sudo rsync -av /media/source/Documents/ /media/temp/Documents
    - Note that if you run this without sudo the ownership of all of the files and directories gets changed to the current user and at least some hidden files won't copy because of permissions issues.
Filesystem
  • Get information about a drive partition: sudo fdisk -l
  • Mount partition from command line: sudo mount -t ext3 /dev/sdb1 /media/mountpoint
    • Where ext3 is the filesystem type, /dev/sdb1 is the location of the partition and /media/mountpoint is the directory where the partition should be mounted
  • Filesystem mounting configuration: /etc/fstab
  • Remount filesystem after editing fstab: sudo mount -a
  • Unmount mount: sudo umount /mount_point
  • Fix smbfs mount that has stopped working:
    1. Unmount smbfs mount: sudo umount /problem_mount_point
    2. Delete mount point: sudo rmdir /problem_mount_point
    3. Recreate mount point: sudo mkdir /problem_mount_point
    4. Remount smbfs mount (assuming its in fstab): sudo mount -a
  • Mount Samba share from command line or script:
    sudo mount -t smbfs -o username=defaults,password=defaults,uid=usersname,gid=groupname,umask=0000 "//10.10.10.110/DISK 1" /media/zihuatanejo
Networking
  • Network configuration file: /etc/network/interfaces
  • Hosts file: /etc/hosts
  • Log on log: /var/log/auth.log
Permissions & Ownership
  • Give all permissions to all users: chmod a+rwx filename
  • Give all permissions recursively to all users to all files and directories under MyDirectory: sudo chmod -R a+rw /home/andy/MyDirectory/
  • Change ownership of file: sudo chown andy /home/andy/myfile
  • Change ownership of all files and sub-directories recursively: sudo chown -R andy /home/andy/MyDirectory
Repositories and Package Management
  • Basic Aptitude command line commands:
    • $sudo aptitude update | Updates the package lists
    • $sudo aptitude safe-upgrade | Upgrade as many packages as possible without removing existing packages.
    • $sudo aptitude full-upgrade | Upgrade everything, including deleting existing packages to solve dependencies
    • $sudo aptitude [ install | remove | purge ] pkg1 [pkg2] | Take actions on individual packages
    • $sudo aptitude search search terms | Search packages for terms
    • $sudo aptitude show pkg_name | Show information on the package

  • Repositories file: /etc/apt/sources.list
  • Editing Repositories from command line: https://help.ubuntu.com/community/Repositories/CommandLine
  • To install and configure predefined package collections, like LAMP server: sudo tasksel
SciTE
  • To configure fonts (among other things) edit: /usr/share/scite/SciTEGlobal.properties
  • To configure PHP syntax highlighting edit: /usr/share/scite/html.properties
Scripts
  • In order to run a BASH script you have to:
    • First make the file executable by running chmod 700 scriptname
    • Then to execute it from the current directory you have to use ./scriptname which translates to 'run scriptname from the current directory'
Services (Samba, SSH, Apache, etc)
  • As of Ubuntu 10.04 you can no longer start and stop services using /etc/init.d/apache2 stop.
  • The new method for starting and stopping services is: sudo service apache2 start
SSH
  • Good article on SSH port forwarding here:
    http://www.securityfocus.com/infocus/1816
  • To make a tunnel to a server behind a firewall:
    ssh -L 8888:10.10.10.120:80 andy@10.10.10.120 -p 1234
    Where 8888 is a port on the client machine, 10.10.10.120:80 is the port and IP address that you want traffic forwarded to from localhost:8888, and andy@10.10.10.120 -p 1234 is the username, IP address, and port of the remote machine you are making the ssh connection to.
  • Whenever you make configuration changes you have to restart to have them take effect:
    $sudo /etc/init.d/ssh restart
SSHFS
  • To mount:
    sshfs username@remotemachine:/remotedirectory localmountpoint
  • To unmount: fusermount -u localmountpoint

2007-09-16

MythTV Reference

To start MythTV backend: /etc/init.d/mythtv-backend start

To shutdown MythTV backend: sudo /etc/init.d/mythtv-backend stop

To backup the MythTV database: mysqldump -u mythtv -ppassword mythconverg -c > mythtv_backup.sql

To refresh listing data (if listings got messed up somehow): sudo mythfilldatabase --refresh-all
(note that this will not refresh today's listings!)

To refresh today's listing data: sudo mythfilldatabase --refresh-today

Schedules Direct: http://www.schedulesdirect.org/

Installing HP Laserjet 1012 on Ubuntu Feisty box with no GUI

This is only meant as a rough guide to the steps involved. I haven't checked it carefully and there are probably errors and omissions.

I first installed HPLIP using sudo apt-get install hplip. I then followed the instructions on how to get it set up found at http://hplip.sourceforge.net/ using the recommended driver for the HP LaserJet 1012 (HP-LaserJet_1012-hpijs.ppd) which I found at http://linuxprinting.org . It appeared to work, but whenever I tried to print a test page at the end of the hp-setup program it didn't work. I ended up with a couple versions of the same printer installed because I couldn't figure out how to delete printers from the non-GUI version of hp-setup (the particular box is an old laptop acting as a server which doesn't have a GUI).

I decided to move on for the moment and installed CUPS using sudo apt-get install cupsys.

Poked around at http://www.cups.org to figure out how to edit /etc/cups/cupsd.conf to allow access to the CUPS web interface at port 631 from a remote machine (since the box has no GUI) and how to configure CUPS so other machines on the network could connect to it to print. Made a bunch of changes, which I can’t remember, but eventually got it so I could access the CUPS web interface from my laptop by pointing to http://10.10.10.120:631/admin.

Using CUPS web interface I was able to delete all the unsuccessful printers I had created using hp-setup. When I deleted printers, etc. it prompted me for a username and password. I used root and my root password successfully. If you don't have a root password set up you may need to do some research on a workaround on cups.org to get that part to work.

I tried using the CUPS Add Printer wizard a few times to install the same recommended HPIJS driver for the HP LaserJet 1012, but whenever I tried to print a test page I got “Foomatic-rip failed” error. I poked around on Google and couldn't find anything helpful about this error.

Finally solved the Foomatic-rip failed error by deleting printer using CUPS web interface and then installing printer but choosing the HP LaserJet Series PCL 4/5 CUPS v1.2 instead of the hpijs 1012 specific driver.

I had installed Samba before using sudo apt-get install samba which presumably was necessary to allow me to share the printer with a windows machine (though I am not sure about that). I was able to successfully set up the printer as a network printer from a Windows machine following tips here: http://ubuntuforums.org/showthread.php?t=268245

2007-09-09

How to set hard drive power management in Ubuntu

To set Ubuntu so that a particular hard drive will power down after a certain amount of time enter the following:

sudo hdparm -S60 /dev/hda

The "hda" refers to the hard drive the command should apply to. Check your system to make sure you are referring to the right name for the drive your want (it was sda on my laptop).

The number following the S defines how long until the drive powers down as follows (from the hdparm man page):

Values from 1 to 240 specify multiples of 5 seconds, yielding timeouts from 5 seconds to 20 minutes. Values from 241 to 251 specify from 1 to 11 units of 30 minutes, yielding timeouts from 30 minutes to 5.5 hours. A value of 252 signifies a timeout of 21 minutes. A value of 253 sets a vendor-defined timeout period between 8 and 12 hours, and the value 254 is reserved. 255 is interpreted as 21 minutes plus 15 seconds. Note that some older drives may have very different interpretations of these values.


To turn on advanced power management for a hard drive:

sudo hdparm -B1 /dev/hda

According to the man page:

"Set Advanced Power Management feature, if the drive supports it. A low value [following the -B flag] means aggressive power management and a high value means better performance. A value of 255 will disable apm on the drive."


On my laptop I had to refer to /dev/sda, and a value of -B1 seemed to make the hard drive power down pretty quickly after use, while the hard drive seemed to keep running for a long time with a setting of -B5.

2007-08-06

Take some of the mousing out of Microsoft Word

One of the things that I hate most about Microsoft Word (and there are many) is the fact that so many frequently used actions have no keyboard shortcuts. While its possible to assign keyboard shortcuts to actions its easy to quickly run out of Ctrl-key or Alt-key combinations that can be remembered.

To solve this problem I decided to write some macros to make Microsoft Word operate more like good old XyWrite, which had a key that took you to a command line where you could enter short commands for every function.

The first step is to set up a hotkey to open the macro dialog. To do this click Tools - Customize - Keyboard (on bottom line of dialog), which gets you to the Customize Keyboard dialog. Here, select Tools in the Categories box, and then select ToolsMacro in the Commands box, then go to the Press New Shortcut Key box and hit Ctrl-m (or whatever hotkey you want), and then finally click the Assign button at the bottom. Now, whenever you hit Ctrl-m it will open the Macros dialog box, where you can type in any macro name and then hit enter to run the macro.

Next, record some macros for your most frequently used menu items, and assign them two (or three) letter names. Here are some of my favorites:

Sub pu()
' Paste Unformatted
' Same as Edit - Paste Special - Unformatted Text
Selection.PasteSpecial Link:=False, DataType:=wdPasteText
End Sub

Public Sub hy()
'highlight yellow
'Same as clicking on the highlight icon on the toolbar
Selection.Range.HighlightColorIndex = wdYellow
End Sub

Public Sub aa()
' Accept All tracked changes
ActiveDocument.AcceptAllRevisions
MsgBox "All tracked changes have been accepted."
End Sub

Sub uc()
'Upper Case; Same as Format - Change Case - Uppercase
Selection.Range.Case = wdUpperCase
End Sub

Once you have written the two letter macros for your commonly used menu items you can run them from the keyboard without ever touching the mouse by hitting Ctrl-m, then typing the two letter macro name, and then hitting Enter. It looks more cumbersome than it is; its really only a total of 4 keystrokes to run any command.

2007-05-17

Save energy and money by turning off your computer at night

I save a significant amount of electricity by turning my computer all the way off at night.

My desktop computer draws about 120 watts when its on but idle with the monitors off. Assuming I only need to have my computer on 10 hours a day, if I left it on all the time annual power consumption while idle would be:

(120 watts * 14 hours * 365 days)/1,000 = 613.2 kwh a year

Here in Arizona I pay around $0.10 per kilowatt hour (kwh) so that works out to $61.32 a year.

The first step was just powering down the desktop at night. However, since I do a long backup routine every night when I end my work day it was initially inconvenient to start my nightly backup routine, and then come back later to turn off my computer. So I used http://www.autohotkey.com/ (a multipurpose utility for Windows which can map hotkeys and automate tasks using a nice scripting language) to write a script to do all the tasks of my nightly backup routine and then shut down the computer.

However, when I took my trusty Kill-A-Watt to my workspace powerstrip I discovered that between my desktop, my Cisco IP Phone 7960, my HP printer, my Linksys router, my Xerox sheet-fed scanner, my Plantronics wireless headset, etc. I was pulling 30 watts even with everything powered down.

To a normal person leaving something on all the time that draws 30 watts is no big deal, but I am not that person. I figured that this 30 watt draw works out as follows, assuming that I want my workspace power on about 15 hours a day 6 days a week:

(((9 hours * 6 days) + 24 hours) * 30 watts * 52 weeks)/1,000 = 121.68 kwh or $12.12 per year

So, I hooked up power timer I had laying around to my powerstrip and set it so it turned the power on at 04:00 and off at 19:00.

2007-05-16

How to view multiple PDFs in separate windows using Acrobat 6

I have 2 monitors and work with a lot of PDF documents, and one thing that has always driven me crazy is that Adobe Acrobat 6 only lets you view PDFs within the application window, and it won't let you run multiple instances of Acrobat, so the only way to look at 2 or 3 PDFs side by side is to maximize Acrobat and then juggle and resize the document windows until you can see both.

Today I found a solution. Firefox (and probably IE) has an Acrobat plug-in, so to easily open multiple PDFs in separate windows you just right click on the PDF file in Windows Explorer (or your favorite file manager) and then choose "Open with" and then choose Firefox. That will launch a new instance of Firefox with the PDF

2006-10-15

How to make group decisions by email

When you are trying to get a group to make a decision via email it helps to propose something concrete for people to respond to, rather than just starting an open ended discussion.

Here is someone trying to set up a get together for a group of mothers with young children via emails sent to a list of 8 people:

Joan: "Hi. I am hoping to get some people together on Sunday. I was wondering if anyone was up for a get together around 10. I am thinking a park or the zoo?"

Joan: "I should have asked before does 10 AM or 3 PM work better? I just assumed before nap is easier."

Mary: "10am for me. Did we pick a place yet?"

Polly: "Morning is also better for us. Do we have a confirmed time and place (and directions) yet?"

Joan: "As for places, I say either Jones Park or Smith Park (we have never been there before) or Greenberg Park. What works for you all?"

Betty: "We will be there at 10 am , what park are you thinking of?"

Kathy: "Im up for trying out a new park (Smith Park) but am fine with what ever the group decides. "

Joan: "
I think a park is easiest. What is central to all of us?"

Betty: "Smith Park sounds good, 10am."

Joan proposes not only multiple options for times but also multiple possible venues. Notice that as time goes by she does nothing to converge the group down to a single place and time. The only reason closure was ever reached was that Betty took charge and picked a park and time for the group.

The lesson? When tying to set something up with a group of people by email you should not present the group with a number of decisions that need to be made. Give the group a complete proposal, "I am going to Smith Park Sunday, 10 am, and I hope some of you can join me" that people can either choose to accept, reject, or make a counterproposal. Sending an email to a group asking the group to make a number of decisions is a recipe for endless dithering.