Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2008/12/16

Organizing My Thoughts on Catalyst

I am about three hours from presenting on Catalyst for my Perl Mongers meeting.

For those who don't know, Catalyst is a Web Framework using the MVC (Model-View-Controller) format to make for easier web development.

Imagine the operators that you see sometimes in 1930s movies, or in old reruns of Laugh-In. The Model is the trunk line with people with information trying to connect in. The View is the person in Suite 14 receiving the calls.

The Controller, Catalyst and the code you write for it, is Lily Tomlin.

Up in Suite 14, running the View, is Template::Toolkit. I've never had reason for templating before, but I'm learning to like it. It's a powerful tool. The institutional view here in the subbasement is that you should limit the amount of logic you put in the View, doing all that mess in the Controller.

The Model is DBIx::Class, and the more I deal with it, the more I accept it as a powerful tool. I have been saying that Catalyst has made it hard for me to leverage the awesome power of SQL, but today I have been beating my head against the switchboard and whipping myself with patch cables, trying to do two simple things. If I get those two things done, I can use one View, one Template Toolkit file, with Catalyst

First, we have lastname and firstname, but we want name = firstname . ' ' . lastname . Unless there is no firstname, in which case name = lastname.

Next, each person does something, and there's a table showing each time that person did that thing. We want to count each thing and establish count.

I can do that. I can use DBIx to get all that information. What I cannot do is put the genie back in the bottle. Or, I cannot patch it back into the View.

Which means, LOL fashion, that I'm doin' it wrong.

So, I'm off to read up on DBIx::Class, and there's next to zero chance that I'll be able to get this work before Perl Mongers.

2008/12/11

Taking control of my environment ...

As mentioned, I now have OpenSolaris available at my beck and call via VirtualBox.

Interesting story: Right about the time I finished that installation, I had problems with my screen setup. You see, I was bored, so I was playing with screen resolutions. My #1 monitor wants to be at 1680x1050, and due to my futzing, Gnome wouldn't let me get to anything closer than 1280x1024. Which looked like crap and kept the panels out of view.

By the way, I love multiple monitors.



Anyway, you can right-click on the desktop and set your screen resolution under Windows. You can right-click on the desktop and set your screen resolution via Gnome under OpenSolaris. It is a menu option for Ubuntu. You cannot get to it via right-click, and sometimes you really need to.

That is, without modification.

Make a ~/.gnome2/nautilus-scripts/ directory. Make a file called Screen Resolution. Make it executable. And make it say this:


#!/bin/bash
/usr/bin/gnome-display-properties


Probably the easiest program I ever wrote! And with Intrepid, I didn't have to HUP Nautilus to make it see the scripts, which is always useful.

2008/12/09

Getting it going ....

When i worked at the other place, we used Synergy. Not the bad and byzantine source-control Synergy, but the software KVM tool.

I have a laptop that's unusable as a laptop, so it is my Windows machine. The screen is busted, so I have it connected to a big screen, and the keyboard is busted, so it's not all that much fun to use. So, I tried the power of Synergy, like I had been using at work.

And I failed.

Talking to Patrick, I figured out the issue. Synergy wants to talk names, not raw IP addresses. I had no local DNS. What few machines needed to talk to each other, I have their 192.168 addresses memorized. But Synergy wanted to work with names.

The solution?

/etc/hosts

Or c:\Windows\system32\drivers\etc\hosts

(There's no legacy BSD code involved with XP. Nope.)

So, I made the wired NIC on the laptop static, named it, and set up Synergy again. And I'm writing on my XP machine via the keyboard on one of my Ubuntu machines' keyboard.

Honestly, I have that keyboard hooked to a KVM switch going between two Ubuntu machines, but that's another story.

Showing the most useful piece of Catalyst documentation yet ....



Not that it is particularly useful.

Useful Test

I'm mostly going to test how to put code samples here, but if you're going to test, might as well make it useful, right?

I run Ubuntu, and I have sshfs installed. sshfs is part of FUSE, Filesystems in Userspace. What SSH allows you to do is mount the file systems on other machines via SSH.

The issue I ran into was that I wanted certain continual mounts all the time. I created a ~/Mount directory and put the mountpoints in there, and had mounting and unmounting shell scripts. If I wanted everything, I got everything. If I just wanted to unmount and remount one, well, I had to grep for the commands I want.

I have two example machines to mount: Home and Work. mount.pl mounts both. mount.pl -q unmounts both. mount.pl -m Home mounts just the Home filesystem. mount.pl -u Home unmounts just the Home filesystem.

It could easily be set up to mount and unmount the NTFS filesystem of a dual-boot computer using ntfsmount, or interact with Windows systems via smbmount, or other things. Right now, it seems way too small to try to put together as a project, but if you find it useful, feel free to comment.

#!/usr/bin/perl

use strict ;
use warnings ;
use Getopt::Long ;
use 5.010 ;
use subs qw( mount unmount ) ;

# Definition
# mount.pl                   --   mounts all in the config
# mount.pl -Q                -- unmounts all in the config
# mount.pl -m foo            --   mounts foo, if foo is in config
# mount.pl -u foo            -- unmounts foo, if foo is in config
# mount.pl -m foo -u bar     --   mounts and unmounts can be mixed

my @mount ;
my @unmount ;
my $unmount ;
my %local ;
my %remote ;

my $mountprog   = '/usr/bin/sshfs' ;
my $unmountprog = '/bin/fusermount' ;

GetOptions( 'mount=s'   => \@mount,
            'unmount=s' => \@unmount,
            'quit'      => \$unmount, ) ;

while (  ) {
    chomp ;
    my $line = $_ ;
    next if $line !~ m{\w}mx ;
    my $result = ( split m{\#}mx, $line )[ 0 ] ;
    $line = $result ;
    next if $line !~ m{\w}mx ;
    my ( $name, $remote, $local ) = split m{\s*\|\s*}mx, $line ;
    $local{ $name }  = $local ;
    $remote{ $name } = $remote ;
    }

# UNMOUNT EVERYTHING
if ( $unmount ) {
    for my $mount ( sort keys %local ) {
        unmount $mount , $local{ $mount } ;
        }
    }

# MOUNT EVERYTHING
elsif ( ( $#mount == -1 ) && ( $#unmount == -1 ) ) {
    for my $mount ( sort keys %local ) {
        mount $mount , $remote{ $mount }, $local{ $mount } ;
        }
    }

# MIXED MOUNTS AND UNMOUNTS
else {

    # mounts first
    for my $mount ( @mount ) {
        mount $mount , $remote{ $mount }, $local{ $mount } ;
        }

    # then unmounts
    for my $mount ( @unmount ) {
        unmount $mount , $local{ $mount } ;
        }
    }

exit 0 ;

sub mount {
    my $name   = shift ;
    my $remote = shift ;
    my $local  = shift ;
    return 0 if $name !~ /\w/mx ;
    return 0 if $remote !~ /\w/mx ;
    return 0 if $local !~ /\w/mx ;
    return 0 if !-d $local ;
    say 'Mounting ' . $name ;
    say qx( /usr/bin/sshfs $remote $local ) ;
    return 1 ;
    }

sub unmount {
    my $name  = shift ;
    my $local = shift ;
    return 0 if $name !~ /\w/mx ;
    return 0 if $local !~ /\w/mx ;
    return 0 if !-d $local ;
    say 'Unmounting ' . $name ;
    say qx( /bin/fusermount -u $local ) ;
    return 1 ;
    }

__DATA__
# NAME | REMOTE MOUNT POINT | LOCAL MOUNT POINT
Work     | xxx.xxxx.xxxx.edu: | /home/rant/Mount/work
Home     | xxx.xxxx.xxxx.net: | /home/rant/Mount/home


(I plan to beautify the means to dump code in the near future.)

2008/12/04

Considering the Vast Array of Possibility...

At the end of work today, I had a fully-functional OpenSolaris machine running under VirtualBox.

I have tried, at various points in time, to keep a Solaris x86 machine around — "But, Mom! It followed me home! Honest!" — but in the end, I always wiped it. That is, if I ever got the installation finished. Solaris has not been an easy installation.

This wasn't real. This was virtual. A virtual ISO sat in a fake CD-ROM drive and filled a phony chunk of memory full of OpenSolaris. I clicked "GO", moved to another desktop and beat my head on Catalyst and MySQL for a little while. Then, I moved back to the desktop and clicked OK, and it was done. I had my first stab at Solaris package management trying to install the "Guest" packages.

First time I sat behind a Solaris box, I was using CDE. Ever use CDE? CDE is the reason people started looking in to window managers. So they could get away from it! OpenSolaris comes with Gnome, and it's nice. Nice like the Gnome that comes with Ubuntu. And they're both Live CDs.

If the OpenSolaris user experience is, within Δ, the Ubuntu user experience, why use OpenSolaris? You want to integrate into a huge Sun environment. You develop in Java or otherwise want to have your Sun-based development environment. You're used to Sun. Or you wish to prove your manhood by grappling with the OS that was the go-to Unix when Linus was in high school.

I almost have a use for the similar XP install on my desktop. I don't really have one for OpenSolaris yet. So, what do I use it for?

2008/12/02

Reading the Documentation ....

My boss has a flatbed scanner he wants to work. An HP ScanJet 3670.

I tell you the model number so that you too can do what I have done, which is look up the XSane compatability list. You will find that the 3670 is explicitly listed as not working with XSane, which means ito be non-Linux-compliant.

So, my boss suggests I dual-boot the thing. And my other boss — Boss1 can hire and fire me, but Boss2 controls the hardware I deal with on a day-to-day basis — suggests I try VirtualBox, running XP in a virtual machine under Ubuntu. I'm happy to do this, as I would much rather have most of the user software running on Linux than Windows. That's the kind of guy I am.

This process is complicated by the Thanksgiving weekend, which means that all the people I need for getting XP install media (to run in the VirtualBox) are on vacation just when I need to do it. So, finally, I get my hands on install media, get everything running, and guess what!?!

VirtualBox OSE, the open source edition, has no USB support. None. None at all.

This makes me frown.

Want to know what made me smile?

The VirtualBox License.

You can use VirtualBox, the closed, feature-rich version, if you are
  1. Using it just for yourself
  2. Evaluating it for your company, or
  3. Part of an academic institution


Like, for example, a research lab of a large land-grand university!

So, a little apt-get here and there and I have the real VirtualBox running.

Now I just have to convince the ScanJet to talk nice. I could still be setting up a dual-boot yet.

ETA: Adding this to your /etc/fstab and restarting helped a lot, too.

none /proc/bus/usb usbfs devgid=[GUID of vboxusers],devmode=0666 0 0

Assuming you add your users into that group. Thank you, noorez!

2008/11/19

Rage Taking Over ....

The current job is to create an Electronic Lab Notebook. Basically, you need to be able to access it via the web, you need to be able to link to images and import tables from Excel and the like. I started doing wiki on a UseMod wiki, so when I started rolling my own, I looked to UseMod, which was abandoned, and then to OddMuse. OddMuse has a few things I like. It's modular, it's Perl, and you don't have to use a whole host of odd modules and root access to make it work.

So, when it came time to make an Electronic Lab Notebook, I thought wiki. I thought OddMuse Wiki.

There's an add-on for tables. There's an add-on for simple image linking.

But....

The suggested WSYWIG editor is FCKeditor. And "fck!" is pretty much how I'm feeling about said editor. Because it isn't writing acceptable output, and I do not for the life of me know why.

Either that, or it isn't interpreting the saved output once the page is rendered again.

Edited To Add: That was it. The outputted wiki-text was incompatable with the wiki, so by using a module that speaks that kind of output, I got it to work. Yay me.

Specifically, I used the Markup.pl extension, in case that helps someone.


Edited To Add: Using Markup.pl kills tables.