Monthly Archives: October 2011

A Day in the Life of the KAOS Lab Thought Process

In which a simple “Do you know an easy way to convert an integer into a string of (character) digits?” turned into an expedition into ancient UNIX codebases. The process went something like this:

Labmate: Do you know an easy way to convert an integer into a string of digits?
< both of us type it in to google>
Looks like sprintf() is best, there must be a simple efficent algorithm.
How does printf() do it?
Let’s look in libc!
< grep through the various toolchain sources on my system >
Well, here’s the uClibc implementation… which is a terrifying mess of ambigously named function calls and preprocessor directives.
I wish I had some old UNIX sources to look at, that would be simple.
< a bit of googling later>
Holy crap, this is amazing! Full root images for a bunch of early UNIXes, many of them from dmr himself!
< download v5, grep /usr/source judiciously to find /usr/source/s4/printf.s>
Well crap, it’s in PDP-11 assembly, maybe a later version.
< download v7, grep /usr/src judiciously to find /usr/src/libc/stdio/doprnt.s>
Damn, still in PDP-11 assembly, but this is a fancier algorithm.
Hmm… the most understandable UNIX I’ve ever looked at was old MINIX
< spin up BasiliskII, in ‘030 mode, use this workaround to make MacMinix run>
< more grepping for justice>
Eventually, we found the printk() from MacMinix 1.5, in all its awful K&R/ANSI transitional C glory

...
#define NO_FLOAT

#ifdef NO_FLOAT
#define MAXDIG 11 /*32 bits in radix 8*/
#else
#define MAXDIG 128 /* this must be enough */
#endif

_PROTOTYPE(void putc, (int ch)); /*user-supplied, should be putk */

PRIVATE _PROTOTYPE( char *_itoa, (char *p, unsigned num, int radix));
#ifndef NO_LONGD
PRIVATE _PROTOTYPE( char *_itoa, (char *p, unsigned long num, int radix));
#endif

PRIVATE char *_iota(p, num, radix)
register char *p;
register unsigned num;
register radix;
{
register i;
register char *q;
q = p + MAXDIG;
do {
i = (int) (num % radix);
i += '0';
if (i > '9') i += 'A' - '0' - 10;
*--q = i;
} while (num = num / radix);
i = p + MAXDIG - q;
do
*p++ = *q++;
while(--i);
return(p);
}
...

Which is, of course, a digit at a time in one of the most straightforward ways imaginable. Minix’s kernel is designed for systems so resource constrained it has a separate prints() that can only handle char and char* to save overhead, so I can’t imagine it uses a sub-optimal technique.
This kind of thing really makes me wish I had learned OSes in the old death-march through the UNIX sources (or at least the old Tenenbaum book with MINIX) way; things are too complicated and opaque now. There always seems to me to be a golden age from around 1970 into the early 1990s where the modern computing abstractions were in place, but the complexity of production hardware and software hadn’t yet grown out of control.
In a related note, as a tool writer, looking at the earliest versions of cc is AMAZING. Most decent programmers should be able to work through the cc from v5 UNIX (574 lines of C for cc proper, 6454 more lines of C and 1606 of PDP-11 assembly in called parts) in a couple hours, and fairly fully understand how it all works. Sadly, (pre-3) MINIX came with a (binary only) CC made with ACK, which is fancy and portable and way, way, way harder to understand. dmr’s simple genius was just that.

Posted in Computers, Entertainment, General, School | Tagged , , | Leave a comment

Poached Eggs and Scones

Poached Eggs and Scones
Failed to work up requisite give-a-fuck this morning, had no pressing obligations until the early afternoon. Result: breakfast of poached eggs with fresh scones and a latte. In a related note, I need a better scone recipe.

Posted in FoodBlogging, Navel Gazing | Leave a comment

Gendered Costumes

I was eyeballing my bookshelf for a quick-n-dirty costume, because I putzed on doing anything interesting for Halloween, and might find myself in need of one. I came to a disturbing realization about the relative distinctiveness of male and female major characters in media I’m fond of.

Some examples:

Millennium Trilogy:
Lisbeth Salander: Black clothes, black wig/temp dye, and some costume punk jewelry. Best with a couple sheets of inkjet temporary tatoo stock for wasp and dragon. Recognizable to anyone who knows the character.
Mikael Blomkvist: No matter how hard you try, just a dude in a suit.

Lolita:
Dolores Haze: White top, white skirt, $2 heart-shaped sunglasses. Done. Plaid skirt and white button down with said glasses would work too. (Fun fact: those glasses are from the Kubrick movie, not the book.)
Humbert Humbert: Dude in a suit. (Unless you do something creative and likely to end in a public indecency charge)

Various William Gibson Pieces:
Cayce Pollard (Pattern Recognition): Black tube skirt, black bomber jacket, clunky boots. Recognizable to anyone who knows the character – Hell, major plots are based on her taste. (sidenote: you can now get a black MA-1 lookalike for less than $50, instead of $600 for the Buzz Rickson’s in the book. Rothco even makes them in long to get around the “bomber jackets look like halter tops on my frame” issue.)
Molly Millions (Neuromancer) – Silvered dollar-store sunglass lenses adhered to your eye-sockets, unpainted aluminum-can nail extensions. Done.
Henry Dorsett Case (Neuromancer): Not even a memorable physical description.
Hubertus Bigend (most recent three novels): Granted, he’s recognizable, but an International Klein Blue suit isn’t exactly easy to come by, even as fabric stock.

Ready Player One:
[Redacted for thpoilerth]

Note that this isn’t total lack of ideas: there are some excellent costumes I can think of, especially from old video games, but not many fall into the “Less than $20 in readily available parts” range that my level of give a fuck supports. It doesn’t help that Female-As-Male-Character costumes are, as a rule, cute, and Male-As-Female-Character costumes are, as a rule, creepy. When we were kids we made jokes about Halloween parties always degenerating to girls in costumes and guys in indistinct black outfits. It’s true because it’s our culture.

Pretty sure if I end up needing a costume, my laser printer, a piece of elastic, and some poster stock will be making a rage comics face happen at the last moment.

Posted in Entertainment, General | 1 Comment

RIP Dennis Richie

It’s been a bad week for computing pioneers. Steve Jobs on October 5th, and, more quietly, Dennis Richie died October 9th. We’re hearing all about Steve Jobs in the news, because he was a salesman and a showboat. We’re not hearing about Dennis Richie because he did his very best to avoid attention while he did interesting things.
He developed the C programming language, in which virtually all low level programming has been done for the last twenty some years, and from which most widely used modern languages inherit their syntactic structure. He was a major player in the development of UNIX, an operating system which has become so universal that both the vast majority of smartphones and the vast majority of supercomputers run one of it’s derivatives or descendants.
His contributions are so fundamental that they shape the nomenclature and notation we use to discuss computing, and in essence created the world I live in.

I have a copy of K&R in the home directory of all my computers, and always hoped to meet him. His wisdom and knowledge will be sorely missed, but he long ago discovered the secret to immortality: he didn’t just make things, he made things that make things, and as such he will live on through the tools he designed – tools so elegant that we’ll all, mostly unknowingly, be using them every day on every computer for as long as computers remain recognizable.
exit 0;

Posted in Computers, General | Leave a comment

Arduino Promotion Behavior

I was pulling up an old project (A little Simon game which has apparently fallen off the ‘net when I moved my site- will have to repost) to use as a classroom demonstration, and discovered that sometime in the last couple years, the int->unsigned long promotion in Ardino/Processing broke/changed without comment.

The code uses using primitive nested counters and delays to generate sounds and control difficulty, which means rather large numbers (100-microsecond scale delays running for seconds) are being thrown about. To isolate the change, I wrote the following test:
Continue reading

Posted in Computers, DIY, Electronics, General, Objects | Tagged , | Leave a comment

X11


Dear AMD,
Randall Munroe has correctly pointed out that you are adversely affecting my quality of life. Please fix your shit.
Hate,
PAPPP

Posted in Computers, DIY, Entertainment, General | Leave a comment

Ready Player One

Plans for the evening: Write some code I don’t really care for.
Actual activity for the evening: Binge the latter half of Ernest Cline‘s Ready Player One.
As literature, it isn’t exactly stunning – the writing is standard mass market light reading fare (think Dan Brown, and that isn’t exactly complimentary) – but it is possibly the most glorious wallow through geek culture I’ve ever experienced. Geeky Movies. Geeky TV. Old video games. New video games. Geek issues. The Internet. All of it is, through a contrived but delightful plot device, the entire topic of the book. It picks up a huge amount of influence from predecessors in the style, especially Vernor Vinge’s True Names (One of my favorite novellas) and Cory Doctorow’s YA fiction (Little Brother is worth reading no matter how old you are) and makes self-aware references as nods to the things it borrows. The whole thing is extraordinarily masturbatory, to the point of occasionally damaging the storytelling and conception to reach through the forth wall, shake you and ask “Aren’t you excited too?!” but it is totally unashamed, and it is so much fun to just go with it (Enchantment of just going with it vs. disenchantment of thinking about it visible in the contrast of the review and comments here)

It’s also a little bit heartbreaking, because much of the promise the plot hinges on has been eroding away. It presumes that the copyrights on all the pop culture ephemera of the 1980s will have expired in 2044. Thanks to the concerted efforts of entities like Disney, that isn’t likely. Likewise, in an early chapter, it notes “People rarely used their real names online. Anonymity was one of the major perks of …” and goes on as though the “Avatars first, real identities (with physical baggage) for those you choose” model of the internet hasn’t been eroded is a matter of course, and hinges the bulk of the plot on that premise. It even accepts that various things online will need your real name and identity, but, like all such stories, posits that users will chose to go by their handle, and only use real names online where necessary. I grew up in that ‘net. My imagination is set in that ‘net. I want that ‘net back. But it just isn’t the way things are happening (this shame ray is pointed at Facebook and Google).

All that is to say, it isn’t high literature, it isn’t a worldview changer, but holy crap is it fun.

Posted in Entertainment, General, Literature | Leave a comment

Power Factor Corrector

We’ve been tracking down the failure mode of power supplies in the clusters on campus, and picked up a plug-in “Power Saver” power factor corrector box for around $5 to look at in our experiments. Prices on these things range from about $5 (less than the cost of the components in small quantities… and in a nice wallwart case – this is what we paid) to over $70 (fleecing the morons).
This particular device is a “PowerSaver PowerStar CHT” (or some similar random string, the model is “CHT-001A”), about which a variety of bemusingly improbable claims are made.


Upon opening it up, it contains a large (5uF,450V) capacitor, two LEDs, three quarter-watt resistors, and a single-sided PCB with “Comment” all over the silkscreen where fields were not filled in. As best I can make out, the resistors are a very high impedance voltage divider to step down the 120V/60Hz from the wall to a level the LEDs can handle, and the LEDs are acting as their own rectifier. The capacitor is at least connected across the outlet. Curiously, only about half the board is populated, and I can’t figure out what some of the missing components would do – they appear to be a second independent indicator LED circuit rotated 90 degrees from the populated one.
Under a very limited set of circumstances (linear inductive load, like an AC motor) these things could actually help the power factor, but since most residential power billing is net, with no power factor penalty, it wouldn’t actually reduce bills. In the case of non-linear loads, like say, computer power supplies, it will do nothing useful. Experiment complete, although it may still be plugged in while instrumented for funsises.

Posted in Computers, DIY, Electronics, Entertainment, General, Objects, School | Tagged , , | Leave a comment

Dumplings!

It’s been a while since I had a “I made this food. Look at it” foodblogging post, but this makes a good one. One batch of Bison Momo, based roughly on this recipe, and one batch of pork jiaozi, based roughly on this recipe.

Momo filling - Way more photogenic before the meat sludge phase


Both came out pretty well. The jiaozi taste pretty much exactly like the ones from a typical Americanized Chinese restaurant, and the momo are significantly more complex…although they would definitely benefit from some sort of sauce, like they are traditionally served.

The momo are the darker box-folded ones, the jiaozi are the lighter colored crimped half-moons.


I have a fair amount of left over filling from each, due largely to lack of patience and finesse for suitably pressing out the springy dough (In retrospect: breaking out the rolling pin would have helped), which will probably be wrapped in napa cabbage leaves and steamed later, or used for another batch of dumplings. With a bottle of Gewürztraminer and some friends, an evening well spent.

Posted in FoodBlogging | Leave a comment