Archive for category Geekiness

Google CTemplate

I just realized that I reinvented the wheel a month or so… I had a need for a nice templating language and although I did look for a solution that already existed, I didn’t look hard enough. Google CTemplate is exactly what I wanted. My solution was basically to create this from scratch while ignoring all the complexities that I thought I wouldn’t need. The result works (and may even be faster) but it feels clunky and it’s not very flexible. You learn something new every day. Maybe with Rev2 of our release I’ll start using this — it certainly would be easier and the API is already documented.

From their website:

Here is a simple template file:

Hello {{NAME}},
You have just won ${{VALUE}}!
{{#IN_CA}}Well, ${{TAXED_VALUE}}, after taxes.{{/IN_CA}}

Here is a C++ program to fill in the template, which we assume is stored in the file ‘example.tpl’:

#include <stdlib.h>
#include <string>
#include <iostream>  
#include <google/template.h>  
int main(int argc, char** argv) {
  google::TemplateDictionary dict("example");
  dict.SetValue("NAME", "John Smith");
  int winnings = rand() % 100000;
  dict.SetIntValue("VALUE", winnings);
  dict.SetFormattedValue("TAXED_VALUE", "%.2f", winnings * 0.83);
  // For now, assume everyone lives in CA.
  // (Try running the program with a 0 here instead!)
  if (1) {
  google::Template* tpl = google::Template::GetTemplate("example.tpl",
  std::string output;
  tpl->Expand(&output, &dict);
  std::cout << output;
  return 0;

No Comments

So Pretty

It’s truly amazing what beauty people can create. The Internet can be a fun place.

Wait for it to load and then move your cursor around and see what happens.

Via Dark Roasted Blend


1 Comment

Because Perl is Too Straightforward…

…someone created Perligata.

Here’s an example:

#! /usr/local/bin/perl -w
use Lingua::Romana::Perligata;
maximum inquementum tum biguttam egresso scribe.
meo maximo vestibulo perlegamentum da.
da duo tum maximum conscribementa meis listis.
dum listis decapitamentum damentum nexto
    fac sic
        nextum tum novumversum scribe egresso.
        lista sic hoc recidementum nextum cis vannementa da listis.

is equivalent to:

#! /usr/local/bin/perl -w
print STDOUT 'maximum:';                  
my $maxim = <STDIN>;                     
my (@list) = (2..$maxim);
while ($next = shift @list)             
        print STDOUT $next, "\n";
        @list = grep {$_ % $next} @list; 



No Way…

I think I actually got a snippet of Symbian code to work on the first attempt! This is a first… Maybe I’m actually getting the hang of this. I just find the whole “descriptor” concept very odd.

Anyway, all I was trying to do was replace all plus signs with spaces. I normally wrestle with descriptor nonsense for a while but this time, I got it on the first try!

_LIT(TestData, "THIS+IS+A+TEST");
HBufC* heapBuf = HBufC::NewLC(255);
*heapBuf = TestData;
TPtr pHeapBuf(heapBuf->Des());
while (heapBuf->Find(_L("+")) > 0)
pHeapBuf.Replace(heapBuf->Find(_L("+")), 1, _L(" "));
CleanupStack::PopAndDestroy(heapBuf); //Don't forget!

Bleh… stupid Symbian. Thank goodness I didn’t have to change the length of the descriptor…

, ,

No Comments


…not to be confused with mayonnaise (although both tend to ruin an otherwise tasty sandwich).

I’ve had a lot recently (again, malaise, not mayonnaise). There’s a lot going on and I empathize with Alice:

“Well, in our country,” said Alice, still panting a little, “you’d generally get to somewhere else — if you run very fast for a long time, as we’ve been doing.”

“A slow sort of country!” said the Queen. “Now, here, you see, it takes all the running you can do, to keep in the same place. If you want to get somewhere else, you must run at least twice as fast as that!”

Red QueenI’m way behind on reading, way behind on chores around the house (although I did finally wrap up my inspirational Plant Ledge Project). not keeping up with my supposedly rigorous exercise routine, behind on a huge bunch of personal geeky projects. Today I stayed home from work since I wasn’t feeling so hot. I feel like I’m in continual deadlock as I analyze new tasks that I feel may be higher priority than my current tasks. There’s no reason that I can’t accomplish what I have in front of me, I just keep thinking that among the continual stream of tasks flowing at me, there might be a more critical task that I should immediately stick at the front of my queue. The problem is that except for very small tasks, almost all of my time is spent analyzing the incoming tasks. So even if I do identify the critical tasks and properly prioritize them, it doesn’t really matter because unless a task can be done quickly, it will never actually have any opportunity to run despite its priority.

This causes feelings of guilt and malaise. Also, my cold doesn’t help.

1 Comment

O’Reilly Books

home_tarsier (Copyright O'Reilly Media)I love almost all the O’Reilly books that I’ve read. The content is great. The style is readable. The quality is excellent.

I’ve heard of Safari Books Online over the last year or two and I’ve been thinking about it more recently. Safari Books offers unlimited access for $42.99/month to all the O’Reilly books. At first blush, it seems expensive. Yes, it’s nice to be able to do a full-text search through a printed book that’s sitting in front of you — those “index” things in the back are so hard to use! 😉 but at the same time, I don’t typically enjoy reading things on the computer for extended periods if time.

…But I’m trying it anyway. My thought is that over the last 12 months I think I’ve spent at least $50/month on technical books. Most of them (all but 3 I think) have been O’Reilly.

oreilly_large (Copyright O'Reilly Media)

Anybody reading this used Safari Books? Any opinions? I’ll post my thoughts in the next week when I make the decision whether to keep the subscription or not.

Pictures used in this post are owned by O’Reilly.

, , , , ,


Variable Naming

Some in computer programming have insisted on using the prefix is for all boolean data types. I’ve been bumping against this lately. I think it’s silly. It’s a form of Hungarian notation which seems unnecessary considering that the compiler/interpreter in almost all cases will help us deal with type issues. For readabilities’ sake, wouldn’t it make sense to name something what it represents? For example, if the boolean variable represents the state of being done, I suppose isDone may be an OK name. But if it represents the state of something that may or may not have been done 3 years ago, a better name might be wasDone. What if we want special checking to take place if a flag is set? Should that flag be called isCheck? It seems silly — maybe shouldCheck would work. What if we’re talking about ownership or class relationship. isChild works as a name to indicate class relation, but hasChildren is a perfectly logical name to define the inverse relationship. I saw a few places that advocate the use of helping verbs (have, has, had, do, does, did, shall, should, will, would, may, might, can, could, and must) or verbs of being (am, is, are, was, were, be, being, and been) to prefix these names. This makes sense. However, we speak English and sometimes in English we drop helping verbs (think of did for example). Is something.didSucceed better or worse than something.succeeded? There are numerous similar examples.

I think in the end, naming variables to make them readable is much more important than following some convention. Or perhaps I should rephrase that: the convention we ought to follow is the convention of written English, not some tightly defined arbitrary subset.

, ,

1 Comment

Health Insurance

Stethescope by LadyheartThat’s right folks, you know where to come when you need only the finest steaming fresh folly! Just minutes ago, I saw a new post on the infamous Slashdot. Rather than comment on the site itself and have my comments lost in the masses, I figured I’d comment here and let them get them lost in this corner of the Internet.

So the idea of the article is that cheap and easy genetic testing is here now. This sort of testing can provide massive insight into potential health risks. There’s a lot of info that can be mined out of this that can help determine statistical likelihood for certain diseases, genetic defects, etc.

So it makes sense that health insurance companies would be interested in this.

But the line (posted in the Slashdot summary which is why it caught my eye particularly) that gets me is this: “Piecemeal insurance is not viable in a world in which insurers can cherry-pick the most risk-free customers“. I find this statement to be fascinating. Not because it’s so amazing and revealing of the future but because it’s so stupid.

Insurance is a way to manage risk. In all things in life, there’s risk. Even the sure things in life (that’s right: death and taxes) have spawned insurance products. The idea is that you pay a known amount of money now in order to prevent you from paying an unknown amount later. It’s considered equitable (at least when we’re talking about regular, private insurance). That is, both the insured (the entity mitigating risk) and the insurer (the entity shouldering the risk) are happy to be involved.

And this makes sense… If I have a large amount of cash, I can charge more than the statistical likelihood of the sum output of cash expected. Statistics can be wrong, but if I leave a large enough gap, I can make money as an insurer.

If I wanted to insure against the possibility that I would die on my next plane ride (I just wrote this out as “my next plane crash”… har!) , I could probably get some sort of policy that would insure me for this. I would pay some amount — let’s say $50 and if, in fact, I died in a plane crash, the insurer would pay out $500,000 to my next-of-kin. This makes sense — there’s an extremely small chance of me dying in a plane crash. Statistics are fairly readily available that show the likelihood of such a crash (they’re small — really Mom — it’s not dangerous to fly!)

This premium charge would be quite a bit higher if you were an experimental test pilot. (By the way, shouldn’t they call them “test pilots for experimental aircraft” to avoid adjective confusion? As in, “Hey man, I’m just experimenting with this ‘test pilot’ thing!”).

Hutt, Jabba theSo now the fun begins: people want health insurance. Health insurance has been getting more and more expensive and people in the U.S. are having more and more trouble even being qualified to receive it. This makes sense.

Most of us are fat and unhealthy (see picture). Our idea of a nutritious meal is one that has fried meat AND fried vegetables.

So of course costs are rising. Of course some people are deemed “uninsurable”. Who wants to cover someone who has an estimated 90% chance of developing a disease or condition that will cost on average $750,000 to treat? The answer is: someone willing to pay premiums that even at those estimated probabilities will still yield a profit (which is no one).

So insurance always has to be equitable — it always has to make sense for both parties or else it will not be “viable”.

I think the reason the statement was made is this: People don’t want insurance, they want to avoid problems. They don’t want health insurance, they want health. Insurance therefore is viewed not as a tool of the free market that helps manage and mitigate risk, but a social institution that promotes the general well-being of people.

Yummy! (but expensive)!One could say that the statistical ties between tobacco usage and cancer/death, resulting in increased premiums for folks using tobacco, has put pressure on healthy behavior. Previously, an individual could choose to simply ignore this but would have to suffer the consequences of their actions (in expensive treatment or in simply shuffling off this mortal coil earlier rather than later). Now, when applying for life insurance, you see a dramatic difference between the two rates based on that sole attribute: Do You Smoke? The result (at least might be) a decrease in smoking rates since people drive down the price they pay by changing their lifestyle. This is great! At least as long the statistical likelihood is actually accurate.

OK — people don’t seem to  have a problem with this. But with genetics they do… The reason is that someone genetically predisposed to some potentially expensive condition has no ability to alter their circumstances. Essentially, there is no socially reforming affect upon this person. They simply must pay more to mitigate their risk.

From the market’s standpoint, this seems to make good sense: With increased ability to predict risk (at least in theory), there’s less waste as premiums be can fine-tuned to more accurate levels. Competing insurance companies can make tiny profit margins on policies with a highly predictable amount of risk (which saves consumers money).

But it doesn’t “provide for the general well-being”. So, oddly, government provided health care is essentially the same as a private insurance company that knows only statistic: Some people die, some don’t. And the government will also up the premiums a little bit more for everyone who can afford to pay them because there are some who can’t afford to pay anything at all — even a low premium.

This is the concept. I suppose it’s better than forced sterilization or elimination of Lebensunwertes Leben. That’s another way to care for society.

CommunismSo, after all this, it comes down to the purpose of government. Can we provide a system where we can all be happy, from each according to his ability, to each according to his need? How well has that worked…? Should we try the other way to create a perfect, genetically pure society where equality becomes irrelevant?

I think the answer is neither. Life is tough. People die. Babies are born with horrible conditions. Some people are more likely than others to get fat, get cancer, get drunk. Can we ever really change that? Are disabled people the same as non-disabled people because we have a telephone-book-sized stack of laws that give them in equality in all things? Of course not. Life simply isn’t fair.

Capitalism isn’t the answer either. The thing that makes sense about capitalism is that it works with regards to motivating production. Production and effectiveness is a good thing for any civilization that wishes to remain one. However, capitalism provides no way of making life fair. Let’s not try to coerce it and massage it into something it can never be.

So what about those people? The people who are born with horrible conditions or who are likely to develop them? Neither capitalism nor socialism can help them. We as people can. Instead of saying “Someone should do something about this inequality!” be the someone and stop passing the buck. We may not be able to make their lives longer or less painful — even with unlimited medicine this is probably impossible. But we can make a difference in their life by developing relationships with them and loving them. I think the hardest of hearts out there can understand how much more a real, genuine friendship means to someone than extending a life of misery and depression yet another day.

So that’s it! Your economic lesson for the day:  Love people and don’t become commies!

, , ,



I’ve been hitting this wall a lot recently. Just think about writing a document… Let’s start with a simple document — I just need section headers and simple wrapped paragraphs of text. No images, no tables, nothing complicated. I can do this in any simple text editor (Notepad, TextMate, SciTE, whatever). This works great at first. I can keep some notes in this format easily enough. It’s easy to use — nothing special to fiddle with.

Then something changes and I need some “special” formatting. Maybe some graphics, tables, more focus on things like margins, etc. We have a million options now. Convert it to Word? To Pages? (that’s Apple’s word processor for those unfamiliar) How about simply converting to HTML? I despise Word documents (especially because of the oddities associated with their formatting). Pages is nicer in a way (it doesn’t get in your way while you’re writing documents) but has many of the same problems. HTML is too loosely defined to display the same universally (on Firefox it will look great but something will inevitably go wrong on Safari/IE).

In the last couple years, I’ve started to use simple, consistent markup languages like WikiText, reStructuredText, etc. These have mostly been implemented on Wiki sites (like MediaWiki) but in theory, you could write a local application that used the same notation. These intermediate markup languages provide things like header formatting, table layouts, graphic alignment, etc. but don’t tend to focus on the “page” related details like margins, headers/footers on printed output, and other details. They translate the result into a fairly rigorously tested standards-oriented HTML. This works fine for anything I don’t intend to print into a glossy handout. Notes to myself, development and design comments, and many other daily working documents work well here.

Stack of Paper by cohdraBut then, after several weeks of tweaking a design doc, the PHB decides that he wants to see a copy of my design. He wants it printed. Printing the wiki-based version and handing it to him results in the comment “this isn’t using standard headers/footers on each page is it?” So now I’m stuck. I paste the output into Word and spend far too long formatting it for his consumption. He marks up the Word copy and I had to merge my changes back into the wiki.

What a pain.

At work, I’m mostly stuck with Microsoft tools so I tend to use Word if I have to use anything complex. However, elsewhere I typically take an additional step: converting my Word/Pages output to Adobe PDF. It’s sort of the universal printable format and it works for most things.

Wiki’s have definitely answered my need for most documents. The only link that’s missing is how to enable Wiki’s and other screen-displayed documents to be able to be easily converted to printable documents (with  header/footers, page numbers, etc.). Ideally, there could be some meta-tags that did this sort of thing. The problem currently is that while a slightly varied HTML rendering is acceptable when viewing on a screen, the printable layout MUST conform to a strict standard. Maybe someone will (or already has) put together a plugin or something that will let this happen easily. I eagerly await the day…

Update: I will mention here that under the leading of a certain Coder, I was able to help build at least a partial tool that did this exact thing for my last position. It parsed MediaWiki content and converted to Word format. This was nice but it was a little limited. I’d like to see a more generic solution in place — especially one that would allow output from the browser without having to have Word at all.

, ,

1 Comment


git-logo_3I’m really excited about Git — a newish revision control system. I’ve seen it growing in popularity over the last few years but hadn’t used it until just recently.

Unlike Subversion which I’ve really enjoyed using, it’s decentralized, meaning that each “local” copy is in fact a full repository with all changes. There are quite a few advantages with regards to merging and branching and some of the concepts seem to have been well-thought-out rather than simply inherited from earlier revision control system designs. It’s written my Linus Torvalds — Mr. Linux himself. There are still some issues with it and the biggest issue is that it’s simply not as well supported yet with regards to tools. I hope that soon we’ll see better support on Windows (a necessary evil) and some slicker/easier Gui front-ends.

For now, I’m considering moving over to this for personal use and maybe sneaking it in at work. If you haven’t used it yet, I encourage you to check it out. Here‘s a transcript of a talk from Linus talking about Git, Subversion, and revision control systems in general and here‘s the Wikipedia page on Git. I think that it very much depends on your situation whether a decentralized or centralized repository is the way to go, but I think that often, Git will be a good solution.

Update: Here’s a video of the talk.

, , ,

1 Comment