Bash hack of the day

Here's a good bash hack for linux 2.6. If there are less jobs in the current shell than cores in the box, then it will background the job. Otherwise it will block.


_count() {
  echo $#
}

_num_cpus() {
  [ -d /sys/devices/system/cpu/ ] && echo $(_count /sys/devices/system/cpu/*) || echo 1
}

sat() {
  local go=0

  if [ $(jobs -l | wc -l) -ge $(_num_cpus) ] ; then
    while trap '((go++))' SIGCHLD ; sleep 1 ; ((go--)) ; [ $go -eq 0 ] ; do : ; done
  fi

  $@ &

  trap SIGCHLD
}


And here's how I use it.


    for i in a b c d ; do sat lzma $i ; done 


jack | posted Mon Jun 2 16:33:46 2008 | #
category: Debris

Well, it is April 1st.

[jack@needle:~]$ mtn crash N
mtn: misuse: There is no spoon.


jack | posted Sun Apr 1 11:04:25 2007 | #
category: debris

Opeth in 5 words

I was listening to Beneath the Mire from Ghost Reveries, and it struck me that the lyrics concisely summed the pathos infused music:

Beneath the mire
drowned desire


jack | posted Tue Mar 27 08:32:53 2007 | updated Tue Mar 27 08:46:12 2007 | #
category: debris

Replacing the microdrive in a Sharp Zaurus

I have a Sharp SL-C3100 clamshell Zaurus (also known as a spitz), which has a 4GB Hitachi Microdrive in it.

Although I think Microdrives are nifty, they have problems:

So I replaced the 4GiB Microdrive with an 8GiB NAND flash card.

Issues that I ran into

Here's the patch

*** linux-2.6.16/drivers/ide/legacy/ide-cs.c.orig       Thu Jan  4 21:10:30 2007
--- linux-2.6.16/drivers/ide/legacy/ide-cs.c    Thu Jan  4 21:16:59 2007
***************
*** 413,418 ****
--- 413,419 ----
  static struct pcmcia_device_id ide_ids[] = {
        PCMCIA_DEVICE_FUNC_ID(4),
        PCMCIA_DEVICE_MANF_CARD(0x0007, 0x0000),        /* Hitachi */
+       PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000),        /* Unknown */
        PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
        PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401),
        PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000),        /* Toshiba */

jack | posted Mon Jan 8 08:33:48 2007 | updated Tue Mar 27 08:45:43 2007 | #
category: debris

Telus moving into the US wireless data market?

Telus is extending their EVDO network into the US .

I wonder how they are going to sell their rate plans, when the competition is selling a better service (unlimited instead of 250MiB cap) for about half the price .

Maybe they'll be competitive, and Canadian subscribers will have a lever for getting data service for a reasonable price.


jack | posted Thu Dec 7 13:56:45 2006 | #
category: debris

Converting a sRGB PDF to a bunch of CMYK TIFFS

This year, we're getting clubcard to print our annual calendars. However, living in the world of reflected light they accept artwork in CMYK colour space, and not RGB .

This opened up the can of worms that we had mostly been ignorant of before -- colour management. There are lots of resources on the web for how to set up a workflow for colour management.

However, I needed to stitch a pages from different sRGB sources, and convert them to CMYK.

The best way I found to do this was:

* rasterize the images to TIFF in RGB space. I used ghostscript
* get sRGB and CMYK colour profiles from Adobe
* use LCMS (Little Color Management System) to project the images from RGB to CMYK
* compress the resultant tiffs and hand them off

Although ghostscript can rasterize directly to CMYK TIFFs, I was unable to find how to apply a colour profile to the process, and the results were poor.

In the future, I'll just use Scrubus to generate the whole thing directly in CMYK.


jack | posted Wed Dec 6 13:55:12 2006 | #
category: debris

Whee! Snow.

Snow in Vancouver. A very good reason to be far away from a road.


jack | posted Mon Nov 27 09:15:02 2006 | updated Wed Jan 10 21:14:19 2007 | #
category: debris

On the futility of calling tech support.

Sometime last week I stopped getting internet connectivity through my cell provider.

I made the mistake of calling them. Between navigating their voice menu system, and talking to first tier help, waiting while they talked to second tier help, I only lost about 30 minutes of my time.

However, they told me that the problem was the bluetooth connection to my phone.

The problem really was that pppd was looking for an IP address in the 10.x.x.x range, and my provider had stopped NATing those. This took me about 20 minutes to fix.

Although I probably didn't have to do this, I created a new GPRS CID (Connection IDentifier) on my phone from the data provided by Opera . This site will spit out the APN, username, and password settings you need to set to establish a GPRS connection with a wide variety of international providers.

There are a million different gprs configurations for linux pppd out there. Here is another.

Here is the "peers" file:


/dev/rfcomm0
115200
defaultroute
usepeerdns
nodetach
crtscts
lock
noauth
local
debug

lcp-echo-failure 4
lcp-echo-interval 65535

connect    "/usr/sbin/chat -v -f /etc/ppp/chat_scripts/gprs-connect-chat"
disconnect "/usr/sbin/chat -v -f /etc/ppp/chat_scripts/gprs-disconnect-chat"

Here is the connect script.


TIMEOUT		10
ECHO 		ON
ABORT		'BUSY'
ABORT		'ERROR'
ABORT		'NO ANSWER'

SAY		"Resetting phone...\n"
""		'ATZ'
OK		'ATE1V1'

ABORT		'NO CARRIER'
OK		'ATD*99***4#'
		    # the '2' is for CID 2 on the phone
SAY		"Waiting for connect...\n"
CONNECT		""

And here is the disconnect script


""		"\K"
""		"+++ATH"
SAY		"GPRS disconnected"


jack | posted Tue Nov 21 17:49:23 2006 | updated Sun Jan 7 22:47:53 2007 | #
category: debris

Wading through wifi...

Today was a beautiful fall day in Vancouver, so I thought I'd go take some pictures .

While I was wandering around, and since I would have the zaurus and the gps running, I decided to run kismet in scanning mode.

When I got to the public library 60 minutes later, kismet had discovered 601 wifi access points.

I wasn't walking very fast, either.


jack | posted Mon Oct 30 19:11:00 2006 | updated Mon Oct 30 22:36:29 2006 | #
category: debris

The wonders of technology..

Oooh. Greenland.

This picture was taken from the window of Airbus A380-600 while we were flying from Frankfurt to Vancouver. I uploaded the picture via the aircraft's
Boeing Connexion 802.11b access point.


jack | posted Mon Oct 9 09:13:33 2006 | updated Thu Oct 12 08:59:40 2006 | #
category: debris

A weblog by Jack Cummings