Cookie Notice

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

2009/05/29

Dr. Henry's Emergency Lessons for People!

You know on-paper forms where they have checkboxes? "Did you hear about us from A? B? C? Other?" Then there's a place to write in what "Other" means? That's what I'm doing, except I'm doing it online.








That's the roughness. I'm trying to make a general solution, so I have a span after every select. And here's where the problem comes.

I want to watch every select click. That's easy in jQuery. I want to then check to see if the value is now 'other'. That also is easy.

$( 'select' ).click( function() {
var strVal = $( this ).attr('value') ;
if ( strVal == 'Other' ) {
...
}
else {
...
}
}) ;


What I want to do now is create an input box to put the "other" text in. And if I could do it in an object-y kind of way, I can.


$( 'select' ).click( function() {
var strVal = $( this ).attr('value') ;
var strOther = $( this ).parent().attr('id') + '_other' ;
var strHTML = ''
if ( strVal == 'Other' ) {
$( this ).parent().children('.other').html( strHTML ) ;
}
else {
$( this ).parent().children('.other').html('') ;
}
}) ;


But wouldn't it be better to do things with a more object-like interface? I fill one of those selects dynamically, with code that works like this:

clearSelectBox( document.getElementById('test') ) ;

function fillSelectBox_SOLiD ( obj_sel ) {
var valueArray = new Array( '1 cell' , '4 cell' , '8 cell' , 'Other' ) ;
for ( var i = 0 ; i < valueArray.length ; i++ ) {
var obj_option = document.createElement('option') ;
obj_option.text = valueArray[i] ;
try {
obj_sel.add( obj_option , null ) ;
// standards compliant; doesn't work in IE
}
catch(ex) {
obj_sel.add( obj_option ) ;
// IE only
}
}
}

I would much rather create the input by saying something like var newInput = document.createElement('input') than just writing the HTML, but until I can do something like that in JS, I will keep as is.

Any pointers?

2009/05/08

Self-Introduced Bugs

So, I have 3 different SQL statements that handle three different cases, and the mechanism that dealt with it spat out hashes. (I code Perl. Just making this clear early on.)

I wanted to unify the three hashes into one hash. The way I liked best was to push pointers to the hashes into an array, iterating through that array, and taking each hash and dumping the values into a master hash.


my %te_ids ;
my @loop ;
push @loop, \%te_ids1 ;
push @loop, \%te_ids2 ;
push @loop, \%te_ids3 ;
for my $hash ( @loop ) {
for my $k ( keys %te_ids2 ) {
$te_ids{ $k } = 1 ;
}
}


That might not be the best way to join hashes, but it is the way I liked. I have the join code once, so if I decide "hey, this works much better!", I don't have to fix it more than one place.

But do you see the problem? Do you see why I wasn't getting values off %te_ids1 and %te_ids3? Do you see it?

I didn't. Not for a while.

(And to be honest, I used sort keys %te_ids2, when sorting the keys added to the overhead with no benefit at all. Just a piece of cargo-cult programming I have to rid my mind of.)

This is the fixed version. The version where I actually use the refs to hashes I shove into the array.


my %te_ids ;
my @loop ;
push @loop, \%te_ids1 ;
push @loop, \%te_ids2 ;
push @loop, \%te_ids3 ;
for my $hash ( @loop ) {
for my $k ( keys %$hash ) {
$te_ids{ $k } = 1 ;
}
}

2009/04/25

That's A New One On Me (Vista Content)

A friend of my wife is doing low-level web stuff for a class. On Vista. Her name has a space in it. Think Var Lo instead of Varlo. This means that her desktop is at C:\Documents\Var Lo\Desktop\.

There are many things that annoy me here, and only some of them relate to Vista. You cannot tell Vista's Windows Explorer to tell you the extension of known file types. This, to my telling, is Microsoft telling the users that it has nothing but disgust for them and everything they have done, are doing and will ever do. And then there's when the friend asked how to do something with a web page. I said "open that in your browser". She was unable. She then asked if I thought she was stupid. I said no. I didn't say that I thought she was deliberately being obtuse to try to annoy me. I do think she was being deliberately obtuse to try to annoy me.

But the biggest thing was that the page she was writing had an image.





dogpic.jpg existed and was in the same directory as the page. It should've worked. It didn't work. I suspect that the issue is that IE has problems with filenames with spaces, and while seeing dogpic.jpg as c:\Documents\Var Lo\Desktop\dogpic.jpg and then broke upon seeing that space.

They're currently using FTP (ack!) to move the file to the server. We'll see how that goes.

2009/04/09

And the jQuery is just that simple!


$(document).ready(function(){
$("legend").click(function(event){
if ( $(this).parent().children('div').is('.hidden') ) {
$(this).parent().children('div').removeClass('hidden') ;
}
else {
$(this).parent().children('div').addClass('hidden') ;
}
});
});


Except I think I will want an external link, so I'll have to add another level of parent(). But jQuery is hardly distinguishable from magic.

Investigating jQuery

So, you have a bunch of HTML elements. Let's say they're Fieldsets.



x
XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX


x
XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX


x
XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX



Now, you want to be able to hide some of those fieldsets. You could make the legend clickable.



x
XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX



hide_element() is dead easy. I do it in five lines. I could drop one if I wanted. Just a bit of stylesheet manipulation. But there's a problem. As written, that hides the fieldset for good. I really want to toggle. So, something must remain.



x
XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX




This is better, but you have to name every single fieldset. There should be a way to address everything anonymously. And there is. jQuery. Which I don't quite grok yet. But that's where my head is.

2009/04/01

Confronting Big Avatars with Perl and Magick

I do twitter. I run Linux. I use Twitux, not because I like it the most but because I dislike it the least of everything I can run without installing AIR.

It has a problem, however. Avatars are 48x48, but if you upload a way-too-freakin'-big avatar, like the huge pics you can get off your phone these days, it doesn't complain. It just screws up your display. And I finally got sick of it.


#!/usr/bin/perl

use Modern::Perl ;
use Image::Magick ;
use subs qw{ check_image fix_image } ;

# probably an easy change to make this more portable.
# oh well
my $dir = '/home/jacoby/.gnome2/twitux/avatars' ;

#go through all avatars
if ( opendir my $DH , $dir ) {
while ( defined( my $file = readdir( $DH ) ) ) {
next if $file =~ m{^\.}mx ;
my $full_filename = join '/' , $dir , $file ;
check_image $full_filename ;
}
}
else {
say 'Fail' ;
}

# are they 48x48?
sub check_image {
my $file = shift ;
my $image = new Image::Magick ;
$image->Read($file) ;
my $width = $image->Get('width') || 0 ;
my $height = $image->Get('height') || 0 ;
return if $height == 48 && $width == 48 ;
return fix_image $file ;
}

#make them 48x48.
sub fix_image {
my $file = shift ;
my $image = new Image::Magick ;
$image->Read($file) ;
$image->Resize(width=>48,height=>48) ;
$image->Write($file) ;
return ;
}


You need Perl. You need Image::Magick. You need crontab to run it ever so often.

2009/03/26

Setting your GTalk Status with Perl

When confronted with a problem, I used to go to Google and type perl problem-domain , but I stopped that, because that, at best, sent me to a module page on CPAN, which, unfortunately, doesn't always tell you how to use the module.

I have started to use perl problem-domain site:blogspot.com instead, as it is likely that someone hit the same problem and found a solution. When I started looking into the problem of changing the status for Google Talk, I did this, and found this page, ending with the line "Worked? Or Crap?" I could not help responding "Worked AND Crap."

"Worked" is nothing to sneeze at. The IETF motto is "rough consensus and running code", and when you have code that does what you ask it to, what more do you want? But when you use the same variable name three times for three different things, you have to wonder if you could do a better job with it.


#!/usr/bin/perl
# http://digitalpbk.blogspot.com/2009/02/perl-change-google-talk-status.html
#usage : perl stat.pl

use Modern::Perl ;
use Net::XMPP ;
use subs qw{ get_status set_status } ;

my $status = get_status ;
if ( defined $status && length $status > 1 ) {
set_status $status ;
}
exit ;

sub get_credentials {
#this is the point where my setup sucks
my %creds ;
$creds{ username } = 'NO' ;
$creds{ password } = 'A Thousand Times NO' ;
return %creds ;
}

sub get_status {
return join ' ', @ARGV ;
}

sub set_status {
my $status = shift ;
my %cred = get_credentials ;
my $username = $cred{ username } ;
my $password = $cred{ password } ;
my $hostname = 'talk.google.com' ;
my $port = 5222 ;
my $componentname = 'gmail.com' ;
my $connectiontype = 'tcpip' ;
my $tls = 1 ;
my $Con = new Net::XMPP::Client( debuglevel => 0 ) ;
my $con_status = $Con->Connect( hostname => $hostname,
port => $port,
componentname => $componentname,
connectiontype => $connectiontype,
tls => $tls,
timeout => 10 ) ;

if ( !( defined( $con_status ) ) ) {
exit( 0 ) ;
}
my $sid = $Con->{ SESSION }->{ id } ;
$Con->{ STREAM }->{ SIDS }->{ $sid }->{ hostname } = $componentname ;
my @result = $Con->AuthSend( username => $username,
password => $password,
resource => "neuron" ) ;
$Con->Send(
"<iq type='get' to='gmail.com'>"
) ;
$Con->Process() ;
my $iq = $Con->SendAndReceiveWithID(
"<iq type='get' to='$username\@gmail.com'>"
) ;
my ( $cur_status, $statuslist, $show ) = ( "", "", "" ) ;
$cur_status = $1 if ( $iq->GetXML() =~ m/(.*?)<\/status>/ ) ;
$statuslist = $1
if ( $iq->GetXML() =~ m/(<status-list(.*)<\/status-list>)/ ) ;
$show = $1 if ( $iq->GetXML() =~ m/<show>(.*?)<\/show>/ ) ;
##Change status
$Con->Send(
"<iq type='set' to='$username\@gmail.com'>
<query xmlns='google:shared-status'>
<status>$status

<show>$show
</query></iq>" ) ;
$Con->Process() ;
$Con->Disconnect() ;
return $status ;
}


I'll admit that set_status is fairly cargo-cult. But I think it is a little less crap that it was before. Thanks to digitalpbk for the code.

2009/03/16

Ubuntu Intrepid + development Gnome+Do = Transparent Terminals



I don't know why that happened. I have not been able to touch the Compiz stuff, but I think Gnome-Do back-doors it in. Still, way cool.

2009/03/10

Simple Firefox Hack ...

Want more than one "Home Page" in Firefox?

In the "Main" tab of your Preferences/Options, where it has the Home Page text bar, separate your preferred home page URLs with a pipe character (|).

2009/03/06

Making Administration Illegal?

You guys heard about this?

It seems to me that, if I was an admin, I would be well advised to steer clear of San Francisco, because from where I'm sitting, I can't see where he's done anything wrong.

I remember when Kevin Mitnick was arrested. There were "Free Kevin" shirts and stickers, and I would never have stuck one or carried one. I was irked because he was jailed without trial for a long time, but I always thought he deserved a trial and jail time. But for Terry Childs, I feel very comfortable putting my name to this.