Wednesday, December 16, 2009

Beautiful Design


Sometimes you run across an amazingly genius piece of design. I think this is one of them.

Monday, June 2, 2008

Drupal and The Future of News - O'Reilly XML Blog

Drupal and The Future of News - O'Reilly XML Blog: "stochastic taxonomic analyzers"

I was reading this article about Drupal (linked above), and came across the idea of a stochastic taxonomic analyzer. Basically, the idea is that you have a predefined taxonomy based on some example corpus of stuff and you use Bayesian analysis to work out the proper taxonomic categorization of another, previously uncategorized article.

I think this idea is interesting, because it sort of mimics what a human would do in learning how to categorize things. You start out with a "representative subsample", develop some sort of taxonomic relationship, and then apply that to other things. Eventually, though, the taxonomic system will probably break (like classifying a Duckbill Platypus), which is an interesting problem.

I was thinking about this in the context of the Semantic Web. Cory Doctorow's famous "Metacrap" missive gives some compelling reasons why the average person can't be trusted to semantically mark up everything they produce. But it seems to me that the problem isn't with our inability to determine the proper semantic information, but our inability to deal with the boring, meticulous manner in which a computer must be fed this info.

For example, take DocBook. DocBook has lots of fun semantic tags like and <title> and
and what not. Semantic information. But what happens to these when you use the XSL for print output? This semantic information gets translated into "formatting" information. The kind of information that is supposed to somehow separate from semantics. But why do we bother with this formatting? Precisely because it is the formatting that gives humans the visual cues necessary to derive the very same DocBook tags in the first place. So in the case of DocBook, one could imagine an OCR system that scans a book or magazine article does a fairly decent job at doing the markup based purely on the formatting.

I mean isn't semantics why humans invented grammar in the first place? It seems like if we could teach computers to recognize titles and diagram sentences, then they many be able to derive semantic information from "unstructured" documents. Obviously, this isn't easy, or the field of natural language processing would have nothing left to do.... but it is an interesting line of thought.

Friday, May 30, 2008

Long Now: Views: Essays

Long Now: Views: Essays: "Every great man that I have known has had a certain time and place in their life that they use as a reference point; a time when things worked as they were supposed to and great things were accomplished. For Richard, that time was at Los Alamos during the Manhattan Project. Whenever things got 'cockeyed,' Richard would look back and try to understand how now was different than then."

The Richard in question here is Richard Feynman. I wonder how you know you've found that reference point? Does the lack of such a reference point limit one's "greatness"?

Bob Sutton: Strong Opinions, Weakly Held

Bob Sutton: Strong Opinions, Weakly Held

Pure genius. I think this is really what the scientific method is all about -- the ability to be both confident and questioning at the same time. I need to work on the former.

Friday, April 4, 2008

Google NewsBot Humor


Sometimes I think that the Google bot that assembles the news page has a sense of humor when it chooses the image to show. I think this is an example.

Friday, March 28, 2008

Progress

Ecology, Art, and Technology | Environmental Risk Assessment Rover - AT Version 1.0: "Why has modernity, which was supposed to create a sense of security, produced more anxiety and threats than ever? Can scientific data and research help us understand the “riskiness” of contemporary life?"

Good question. I bet old Ned Ludd would have a theory on it.

Friday, March 7, 2008

Computer Jokes

Const-Correctness in C: "In C, you merely shoot yourself in the foot.

In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, 'That's me, over there.'"

Haha.. I thought that was funny. I'm a nerd.

Generating N contiguous bits

So say you want to generate a bitmap that is N contiguous bits, without using some kind
of crazy inefficient for loop. Here's a way that I figured out how to do that (not to say I invented it or anything, but I couldn't find it when I searched for it).
Obviously this has compiler and machine dependencies, and probably doesn't work on the Ides of March, so use at your own risk.

In this example, I want to generate 6 bits of 1's (so 0b111111):

#include <stdio.h>
main(){
unsigned short a;
short b;
int n = 6;
b = 1 << n;
a = (unsigned short) -b; // extend the left bits
printf("a is %hx\n", a);
printf("~a is %hx\n", ~a);
a = ~a; // now b should be 0b111111
}


That's probably like 4 or 5 operations, so for 6 bits it probably sucks. But if you use 64 bit long longs and want to generate 47 one's then it will save some cycles.

Isn't playing with bits fun?

Wednesday, October 24, 2007

TigerDirect, UPS, and Hawaiian Shipping

I hate it when companies only use one shipping option. Because I live in Hawaii, certain shippers, such as UPS are absolutely outrageous because the only option is 2 day air. Unfortunately, many web businesses such as TigerDirect only ship via UPS, and this means that for a $50 RAM chip, shipping is $40. Clearly this really bites it.

Sometimes, a web business will hear our plight and agree to ship via the USPS or FedEx, both of which have much more reasonable shipping rates to Hawaii. Other times, as in the case of TigerDirect, they really don't give a shit about us out here in the middle of the Pacific. Wah.

I guess my ire should really be directed at UPS as well...

Dear Amoss,

That is indeed unfortunate for customers in Hawaii. I am sorry that
you do not value our business. I will be shopping at a competitor
with more reasonable shipping policies to Hawaii.

Thank you for your response.

Aloha,
David Donovan
- Hide quoted text -



On 10/24/07, TD Sales Leads wrote:
> Dear Valued Customer:
> We can only ship via UPS.
> Thank you for visiting our website. We at Tiger Direct appreciate your
> business. If you have further inquiries and reply to this email, please make
> sure to include your entire message, so we can address it appropriately.
>
> Sincerely,
> Amoss
> TigerDirect.com Web Response
>
>
> How are we doing? We would like to hear from you. Please give us your
> feedback at
> http://www.tigerdirect.com/sectors/custsurvey/service.asp .
>
>
>
> -----Original Message-----
> From: donovand@gmail.com (donovand@gmail.com)
> Sent: Oct 24, 2007 6:42:35 AM
> Subject: Pre-Sales Inquiries / Product Information
>
> **
> ** Message Sent from: TigerDirect.com website
> ** Please Respond with a tigerdirect.com email address.
> **
> Name : David Donovan
>
> E-Mail : donovand@gmail.com
>
> Phone : ()-
>
> Subject : Pre-Sales Inquiries / Product Information
>
> Message :
> I am interested in buying some memory from your company. Specifically, I am
> interested in a 1GB DDR RAM chip, which costs $51. Unfortunately, I live in
> Hawaii, and UPS ground is not an option for shipping, therefore the shipping
> costs for the item (which must be 2 day air) is approximately $40. I would
> really like to order from you, however the shipping is prohibitively
> expensive for me in Hawaii. Is it possible to ship via the US Post Office?
> This would be a much more reasonable option for me.
>
> Thank you for your attention to this matter.
>
> Sincerely,
> David Donovan
> http://questev.tigerdirect.net:7630/console/showSequence.do?sequenceid=28607304200710240607566420317232
>
>
>
>
>

Thursday, October 11, 2007

Bit Twiddling

Okay, so I have this problem... I want to do something like:

if(a == 0){
a = b;
}

where a is a positive integer.

But without using an "if" (branching code really sucks). I found this crazy page and adopted it to my needs.

Here's my solution:

#include <stdio.h>

int main(){
unsigned int a = 0;
unsigned int test_msb = -a;
unsigned int mask = (unsigned int) (((int) test_msb)>>31);
unsigned int c = 2;

int result = (int) (a & mask)|(c & ~mask);
printf("%x %d\n", mask, result);
return 1;
}

If I change a to another positive integer, a is printed. When a is 0 (as is hardcoded above -- kids, don't try this at home), c (i.e., 2) is printed. Wee-hoo.

Wednesday, August 29, 2007

Linking to C++/CLI Static Libraries

So I had this weird problem where I was building a C++/CLI static library that included managed and unmanaged code. I had an unmanaged class that called static functions from a managed class (this is known as mixed mode) and was compiling the whole thing with /clr. When I was building another mixed mode .dll that called the mixed static library, I was getting linker errors to the functions in the static lib's managed classes. I found this on microsoft.public.dotnet.general newsgroup:


Hi all,

I have a .NET solution with several projects in it. One project is a "utilities" project that is compiled into a static library. It contains managed and unmanaged C++ in several files. So I am compiling using managed extensions. This project compiles successfully.

Another project in the solution, BrassControls, is dependent on the Utilities project. It uses several of the classes in Utilities. However, it fails at linking. I get the following error when building the BrassControls project [ -- the class BrassVersion is in the Utilities project]:

LINK : error LNK2020: unresolved token (06000050) Brass.BrassVersion::.ctor
LINK : error LNK2020: unresolved token (06000051) Brass.BrassVersion::.ctor
LINK : error LNK2020: unresolved token (06000052) Brass.BrassVersion::Finalize
LINK : error LNK2020: unresolved token (06000053) Brass.BrassVersion::ToString

These relate to the functions in the Brass::BrassVersion class. This is the only class in the Utilities project that is a __gc class.

I have verified that the project dependencies are set so that BrassControls is dependent on Utilities. But for some reason it can't "see" the tokens associated with BrassVersion.

Both projects are compiled using managed extensions. Both are using the same run-time library.

Can anyone help me figure this out?
Thanks,
Matt.


Ah-ha! This was exactly my problem. Unfortunately, the newsgroup didn't have an answer and it took me a few more hours to find it. The answer is easy... on the .dll that includes the static library, make sure the Linker option for the .dll "Use Dependency Inputs" is set to "Yes". I guess for unmanaged classes it would include them, but for managed classes it wouldn't, so I was getting a linker error (LNK2020) for unresolved tokens. It took me forever to figure this out and really pissed me off. I found the answer here.

Tuesday, August 14, 2007

Making C#, C++/CLI, and C++ play nicely together

One of my favorite pastimes is to get different computer languages to interoperate. Can't we all just get along?

So one thing I wanted to do was use C# windows forms (and other stuff) with C++ code. The first thing I needed to find out was how to debug such a monstrosity in Visual Studio. Here's how you set up your project to step from C# into C++ land seamlessly:
Debugging in Visual Studio .NET

So the other weird thing I ran into was linker errors. I was trying to reference a mixed code .dll (compiled with /clr) from another native code .dll. Doing Properties->Linker->Input->Additional Dependencies for the project and adding the .dll causes a linker error: LNK1302. Apparently you have two options: compile the .dll with /clr:safe OR include every stupid .obj file for every .cpp file that you have in the .dll you want to include. Another option that I found was to give up on the .dll thing, and just make a statically linked library (change the configuration to produce a .lib instead) for the mixed-code library and then include this in the other native code .dll. Then, I can include the Additional Dependency without difficulty. My project compiles and works as expected for now, though I read somewhere you can get weird initialization problems sometimes when you have mixed-mode libraries. I'll be on the lookout for that gotcha, but for now using .lib's seems to work for me.

In summary, I have C#->C++/CLI .dll -> C++ & C++/CLI .lib
I say C++ & C++/CLI .lib because in some .cpp files I use .NET types (declared as a public ref class), and in others I do not (these are declared as public class).

C++/CLI is very weird... it's sort of like a computer version of Esperanto.

Anyway, this pdf file has some useful general info on C++/CLI etc:
link It's from a book, Expert C++/CLI

Tuesday, August 7, 2007

Link Port booting the TigerSharc with the EZ-Lite Kit

So, I was using the example that came with VisualDSP++ to do link port booting of one TigerSharc processor on the EZ-Lite Kit eval board using the other one. (Found in C:\Program Files\Analog Devices\VisualDSP 4.5\TS\Examples\ADSP-TS201 EZ-Kit Lite\Link Boot.) I was able to run the Master code (which DMA transfers the user code to the 2nd processor) and initialize the memory in the 2nd processor, however the code didn't work (i.e., I got no output).

Turns out that the boot loader in the example (TS201_link.asm) is out of date, and you have to copy the new one (in C:\Program Files\Analog Devices\VisualDSP 4.5\TS\ldr\TS201_link\TS201_link.asm) to the example directory, change the "#define LINK 3" to "#define LINK 2" (since link port 2 is joined between the 2 processors), and recompile the boot loader. Then, you can follow the readme and actually get the IIR code to work.

Analog drives me nuts with this crap.... their examples seem to be out of date a lot of the time.

Tuesday, July 31, 2007

Arrays of Function Pointers in C++

So imagine you have a function called test_function_ref in a class called DLMAP. In another function in the same class, you want to have an array of function pointers that includes test_function_ref, and then you want to call it using the array of function pointers. This is how you would do that:

void (DLMAP::*fptr[2])(BitStream &theBits);
// set up an array of functions that return void and take a reference
// to a BitStream object as an argument
fptr[1] = &DLMAP::test_function_ref;
// assign the 1'th element of the function pointer array to the address of the function
(*this.*fptr[1])(theBits);
// now, actually call the function using the this pointer


Wasn't that fun? I got the info here.

Friday, July 20, 2007

XPath, C#, .NET, and namespaces.

So I was trying to use XPath to search this XML document I'm working with using System.Xml in C#/.Net. The obvious thing to use for me was the method SelectSingleNode(). I had read around that you had to be very careful with default namespaces using XPath 1.0 in .Net. In summary, all namespaces must have a prefix, even the default one. You just have to make a prefix up for the default namespace. I chose the imaginative "default" prefix.

Anyway, these were the first couple lines of my XML doc:


<?xml version="1.0" encoding="utf-8"?>
<Specification Standard="802.16e Cor2, 2007" VersionDate="2007-06-21" Company="Sanjole Inc." Author="Min Xu" xmlns="http://sanjole.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xsi:schemaLocation="http://sanjole.com/ Sanjole.xsd">


So I have a default namespace. I used the following code, which didn't work:

XmlDocument xmlSpecDoc = new XmlDocument();
xmlSpecDoc.Load(xmlSpecFileName);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlSpecDoc.NameTable);
nsmgr.AddNamespace("default", "http://sanjole.com");
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
nsmgr.AddNamespace("msxsl", "urn:schemas-microsoft-com:xslt");
XmlElement root = xmlSpecDoc.DocumentElement;
XmlNode messageNode = root.SelectSingleNode("/default:Specification", nsmgr);


This returned a messageNode of null, even though it's obviously in the document.

Can you find the bug? Me neither, but my colleague found it... look closely at the default namespace. Give up? It should have been:

nsmgr.AddNamespace("default", "http://sanjole.com/");


That's right... watch your trailing "/"'s. I'm won't reveal how long I was messing with this. Let's just say it was in the range of "hours".

Monday, July 16, 2007

Tales of Irony


Recently, I purchased a pair of fabric scissors. They came in a blister pack.

I sent the company an email:


Dear Sir or Madam,

I recently purchased a pair of Helping Hand Fabric Scissors. Ironically, these scissors are packaged in a "blister pack", which to open, you actually need a pair of scissors. I would like to suggest that you find an alternative means of packaging scissors that don't require scissors to open.

Thank you for your attention to this matter.

Sincerely,
David A. Donovan


I really hope they listen.