Monday, 5 December 2005

HP Printer Hacking

Looking at http://odetocode.com/Humor/68.aspx I saw a cool .net hack for displaying custom messages on an HP printer LCD.

I’m a bit of a .net fan from a distances, which is to say I’m an ex-delphi afficionado, having done some cool hacks like 16 bit multithreading and form inheritance in Delphi, and I’m waiting for .net to be the cross platform “delphi” that Kylix never became (if only they used wxWidgets, but who was to know then, eh?)

Well anyway, .net seemed a bit of overkill for HP printer LCD hacking so I replaced it with a small shell script instead

#! /bin/sh

printer="$1"
shift

message() {
printf "x1B%%-12345X@PJL RDYMSG DISPLAY = "%s"rnx1B%%-12345Xrn" "$*"
}

# try to use bash tcp redirection if enabled
if exec 9> "/dev/tcp/$printer/9100"
then message "$@" >&9
else message "$@" | netcat -q 2 "$printer" 9100 >/dev/null
fi


Invoke thus:

./hpmsg my.printer.name.or.ip.address hello joe wassup

of course, this is hardly just a small shell script as it relies on all of bash, and possibly netcat. (My ubuntu bash doesn’t seem to have build-in tcp redirection, boo!)

Saturday, 3 December 2005

When ASDA don’t stock

ASDA have been really annoying lately being out of stock of various items; mainly organic milk which costs about 5p more per 6 pints and tastes smoother and less harsh, and perhaps less dodgy hormones in it (here’s hoping).

They seem to have sorted out the Organic Milk problem by changing the colours of the bottle tops from blue or green, to white - which presumably stops them from getting mixed up in the warehouse, thus they can always find it and deliver it; so far so good. I’ll forgive then from being short of suet 2 consecutive visits because it is Christmas pudding season.

This time it was maternity towels. I don’t know why ASDA stopped selling maternity towels, but a nice man named S____ is going to find out and phone me back on Monday or Tuesday.

The point is; and I made this very clear; if I have to go to Morrisons to get maternity towels, I may as well get all my shopping there; “..don’t you think?” I asked S_____. He wisely refrained from answering. I suggested that I might even prefer Morrissons if I tried it; but S_____ would not be drawn.

Maternity towels aren’t something a person needs very often, and it looks like someone at ASDA foolishly thinks thats the point. The point is this: they had better be darned sure I’m not going to prefer Morrissons before driving me in that direction.

I may never come back; and as maternity towels indicate a new family member thats a lifetime of shopping they could be missing out on.

On small moments…

Tuesday, 29 November 2005

Mile high : Mile deep menus

MACOS GUI sucks.

MAC fans think it looks nice, and thats a nice opinion but it doesn’t compare to windows for usability.

The only good thing I have heard said about the MAC GUI is the famed Mile High Menu. And thats a good thing if you don’t plan on learning to use a mouse well.

Does anybody seriously claim that all these MAC users can’t position a mouse in 16 pixels vertically but can position it in 16 pixels horizontally? How do they ever manage to click on buttons, or hyperlinks? How do they manage to drag their clipart about?

When you have one mile high menu, you gain something tiny for those who can’t use a mouse. What do you lose? You lose the mile-deep menu.

With GNOME or windows I can see the menu bars multiple windows at the same time, and even click directly on the menu bar of a non-focused window! MAC uses would have to first select the NOT-mile-high title bar and then move to the mile high menu bar. I get just one click.

Maybe MAC GUI has something to recommend it besides the dubiously and only slightly helpful mile high menu?

Monday, 28 November 2005

do { break; } while (0);

I just came up with this C construc, using break to jump out of a block;

do {
  if (! seems_suitable(a,b)) break;
  c=check_even_harder(a,b,);
  if (! c) break;
    be_tricky();
  return;
  } while (0);

do_it_the_old_way(a,b);


I was adding a code block before an existing block whose purpose was to filter out certain conditions to handle especially, and trying to avoid lots of nested if/else blocks. Without this foul trick the code would read:

if (seems_suitable(a,b)) {
  c=check_even_harder(a,b,);
  if (c) {
    be_tricky();
    return;
  }
}

do_it_the_old_way(a,b);


it works for me anyway .

Friday, 25 November 2005

Stem cell hoo-hah

Based on The Register’s report I don’t understand why Professor Hwang Woo-Suk resigned.

As I read it two students donated ova under and assumed name without his knowledge and not in breach of contemporary law or ethical guidelines.

So what's the real reason he had to resign?

Perhaps I’ve missed something but that's how it reads to me.

Thursday, 24 November 2005

Flash hangs in firefox

Since upgrading from Hoary, firefox hangs badly on pages that contain flash.

Google reveals that lots of users are having this trouble; many of them relate it to sound access.

Well, I think I pinned it down to an ALSA problem.

Strangely sending a SIGSTOP and SIGCONT recovers it briefly. Hope fully I submitted enough debugging for it to be fixed now.

Apart from the above bug, I do wish Ubuntu would do ASLA device sharing out of the box and configure everything to use ALSA, and do ESD sharing out of the box and configure everything else to use ESD, and ESD to use ALSA.

Here is my config to do that:

/etc/asound.conf - this lets multiple ALSA clients use the audio device at once

# Example /etc/asound.conf or ~/.asoundrc file showing how
# to configure ALSA so that a dmix plugin is used by default
#
# The writing of alsa-lib configuration files is explained in
# /usr/share/doc/libasound2-doc/html/index.html, provided by the
# libasound2-doc package.
#
# Make ALSA apps default to using dmix plugin instead of hw plugin
# (Exclamation point is needed in order to override the assignment to
# pcm.default in /usr/share/alsa/alsa.conf.)

pcm.!default {
  type plug
  slave.pcm "dmix"
}

#
# Make OSS apps default to using dmix plugin too

pcm.dsp0 {
  type plug
  slave.pcm "dmix"
}

#

ctl.mixer0 {
  type hw
  card 0
}


/etc/esound/esd.conf - (I use libesd-alsa0)

I use tcp mode because my family have multiple console logins at the same time, and that way they can each use each-others esd if it is running, or start one if needed.


[esd]
auto_spawn=1
spawn_options=-terminate -nobeeps -as 1
spawn_wait_ms=100

# default options are used in spawned and non-spawned mode
default_options=-as 5 -tcp

Installing SUN Java on Ununtu

One of the uses of a blog is to make notes for myself to follow later. I often ending up doing the job multiple times and forgetting how I did it.

From these notes I install SUN Java on Ubuntu Breezy Badger.

sudo apt-get install fakeroot java-package java-common

fakeroot make-jpkg --full-name "My Name" --email "me@example.com" jdk-1_5_0_05-linux-i586.bin

sudo dpkg -i sun-j2sdk1.5_1.5.0+update05_i386.deb

sudo update-alternatives --config java