Archive for the ‘Scripting’ Category

wide wide world of characters

Tuesday, September 11th, 2007

I was getting a lot of “Wide character in print” errors from a perl script. A little googling led me to this page and the solution. In short, I was printing unicode characters to an I/O layer that did not support unicode, hence the error. Adding a call to binmode solved this.

example:

open(FILEHANDLE, “>$filename”);
binmode(FILEHANDLE, “:utf8″);
printf(FILEHANDLE, “Hello World!n”);

Postscript for Encoder Wheels

Thursday, May 17th, 2007

From ranchbots

%! Postscript utility for printing an encoder wheel
%
/inch {72 mul} def % #points/inch (don't change me)
/size 0.5 inch def % radius of encoder wheel
/segments 16 def % number of segments (black and white)
/angle 360 segments div def
/wedge
{ /radius exch def
/angle_s exch def
/angle_e exch def
newpath 0 0 moveto
0 0 radius angle_s angle_e arc
closepath
} def

gsave
1.0 inch 1.0 inch translate
0 1 segments {
360 segments div rotate
angle 0 size wedge
2 mod 0 eq {1} {0} ifelse
setgray fill
} for
grestore

showpage

Atmel AVR Fuse Settings

Saturday, September 30th, 2006

I’m lazy and don’t like reading datasheets. I do, however, enjoy writing in PHP. Here is a little web app I wrote to simplify deciding what fuse bits to program on my AVRs. I wrote it in a hurry, so there might be bugs. If you fry your AVR don’t come running to me. :)

AVR Fuse Settings

Perl GetOpt Not Working

Thursday, July 6th, 2006

I have run into this same problem a few times so I am documenting it here. When using GetOpt::Long and friends I would be mystified when the options were ignored. For example:

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
my $debug = 0;

my $result = GetOptions( "debug" => $debug );
print "Debug flag is $debug\\n";
wriley ~/bin> ./getopttest.pl
Debug flag is 0
wriley ~/bin> ./getopttest.pl --debug
Debug flag is 0
wriley ~/bin>

The options are completely ignored! A short time of googling later and I remembered the solution.

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;
my $debug = 0;

my $result = GetOptions( "debug" => \\$debug );
print "Debug flag is $debug\\n";
wriley ~/bin> ./getopttest.pl
Debug flag is 0
wriley ~/bin> ./getopttest.pl --debug
Debug flag is 1
wriley ~/bin>

The key is escaping the $ in the GetOptions() statement. If you don’t escapey, it don’t workey!