RSS 2.0 | Atom 1.0

Sign In


# Wednesday, November 03, 2004
Help out: Hold an intervention

OK, I hardly do any politics here, so here's my one shot, considering the US elections failed. What a bad omen for the new few years eh? Anyways, instead of just complaining, I think we (people of the Earth) should step in and help. A bunch of other countries should get together and hold and intervention for the USA. Just like a friend on cocaine (or something bad) -- you perhaps watch and warn the first time it's a problem, and after that you just get involved.

Other nations should just step in and say, “We're sorry. We love [some] of you. We can't let you continue to do this to yourselves.” And then we would put someone else more competent in charge. Maybe Tommy Chong. “It's only for your own good” is what we'd tell the states. Faced with a world-wide show of love and support they'd definately see their folly and agree, right? Maybe not, judging from the voting maps. If you look at the voting maps, Bush is very much skewed towards people with pitchforks and gun racks in their pickups, while non-Bush is skewed towards people with an IQ above 110. Then again, we'll probably see a few more soverign countries blown up anyways, so there's probably not much to lose.

OK, I'm done.

Humour | Personal
Wednesday, November 03, 2004 8:50:15 PM UTC  #    Comments [6]  |  Trackback

# Saturday, October 30, 2004

I wrote this quite some time ago, with the Whidbey Beta, I believe. I was gonna make it nice, but never got around to it, but somehow it came up today and I remembered it. So, I decided to post the code and the link.

Basically, it's an HTML Chat client using a ASP.NET in-process server. It's very, very lightweight -- it wouldn't work for tons of users (it uses a ReaderWriter lock!). I use web services to poll for new messages (or translate received messages, although that seems broken right now).

Now, since it relies on the soap client, it doesn't work on all browers. A easy way around this is to replace the web services with IFRAMEs. Also, if you wanted to scale this solution up (say, you're building a chat client for MSDN :)), I believe you should leave the HTTP connection that receives messages open for say, 60 seconds (or more). This reduces the hit of polling drastically, and works quite well (I tested it in a few browsers). The server only has to authenticate the client ONCE, and then it can just pump new content down the pipe as it seems fit. At any rate, it's a simple chat system that could give someone a head start if they lack a head.

Anyways, get the code (ASP.NET 2 required): SimpleChat.zip (25.33 KB) It's running here: http://www.atrevido.net/SimpleChat/

If there's enough interest, and if a 19th level wizard visits me and gives me a Wand of Time Stop, perhaps I'll write a production level version of this (that DOESN'T use SOAP).

Saturday, October 30, 2004 5:29:29 AM UTC  #    Comments [2]  |  Trackback

# Wednesday, October 27, 2004
Massive XML abuse

OK, I've had it. Ever since XML came out, certain people have been misusing it all over the place for no reason at all. *XML IS JUST A FORMAT.* It's not magic. It's not cool. Use if it makes sense. However, it is actually a REAL format; adding < and > to a document doesn't make it XML. LinkPoint needs to learn this.

LinkPoint (owned by First Data) is a rather large company to process credit cards. You would think they'd have people who actually have some clue as to what they are doing when it comes to their programmatic interface eh? Check this code sample out:

protected string ParseTag(string tag, string rsp)
  StringBuilder sb = new StringBuilder(256);
  int len = sb.Length;
  int idxSt=-1,idxEnd=-1;
  if( -1 == (idxSt = rsp.IndexOf(sb.ToString())))
return ""; }
  idxSt += len;
  if( -1 == (idxEnd = rsp.IndexOf(sb.ToString(),idxSt)))
return ""; }
  return rsp.Substring(idxSt,idxEnd-idxSt);

I'm not making this up. At first I started laughing. And continued. It's one way of processing XML, heh. I also love the use of a StringBuilder *for no reason*. They didn't even have the decency to think about Regular Expressions. (And what's up with that crazy formatting on the ifs??) Sigh.

The whole point of XML is to provide a standard way to process data on whatever platform you wish, eliminating the need for stupid code like that above. With XPath, all that junk comes down to about 3 lines of nice, neat code. So I continued to chuckle as I wrote my nice, elegant code.

Until it came to runtime. Apparently, some folks don't know that XML has *ONE ROOT ELEMENT*. Throwing a bunch of tags together doesn't make it a valid document. And invalid documents mean... yep, you guessed it: Errors from your XML parser. And without a working XML parser, you're back to manually handling it. So why even bother with “XML“ if you're not going to do it correctly? A simple name=value would work just fine...

BTW, this is the second vendor this week I've seen using invalid XML documents.

Quick update: The easiest solution in this case is to just do: theirXml = “<root>” + theirXml + “</root>”; // works like a charm.
Code | Humour
Wednesday, October 27, 2004 5:22:11 AM UTC  #    Comments [2]  |  Trackback

# Tuesday, October 26, 2004
Ok, maybe I'll take a small SWiG

As I was designing exactly how I was going to generate all the C# prototypes and basic C implementations for my ast_mono internalcalls, I realised it'd be a bit more work than I feel like doing, especially where there's already work done. I'm not looking for a completely automated way to create code files that can be updated on-the-fly. I think there will be a lot of customization going into each generated file, and I'm comfortable with that.

So what I really want is a simple way to have some of my C# code emit some definitions and code into two files (the C# prototype file and the C internalcall file). I don't really care to actually process C header files all -- all I want is access to the type definitions, even in a limited form. In taking a deeper look at SWiG, I found that, lo-and-behold, it also emits its parse trees as XML if I so desire. Sweet. Now I'll have a nicely packaged way to get at the type info of all the header files for Asterisk.

Tuesday, October 26, 2004 7:20:26 AM UTC  #    Comments [0]  |  Trackback

Cross-platform development bliss

Visual Studio 2005 is just beautiful. I'm currently writing ast_mono, which has 2 C projects (that build on Linux), and 1 C# project (that builds with Whidbey). Everything gets deployed on Linux. However, I have my entire dev process available right from VS. The C projects are Makefile projects, and allow a command-line to be specified. Enter Plink, and I'm set. Plink is an Win32 command line SSH client. I just pass in the commands (cd /usr/src/ast_mono/runtime; make clean; make install;) and away it goes. In fact, VS detects when there's an error and shows the errors (from GCC) in the VS task pane.

Only two things I want: file/line info from GCC into VS. GCC outputs errors differently than VS is expecting and thus I can't go right to the file/line of the error. And debugging. I've got no idea how to do cross-platform debugging, let alone with VS integration. I highly doubt this is even possible.

Meanwhile, I'm enjoying my single-step build/deploy process very much.

Tuesday, October 26, 2004 3:55:49 AM UTC  #    Comments [1]  |  Trackback

ast_mono - Phase 01 - Structures

Asterisk depends on quite a few structures, obviously :). One of my goals for ast_mono is to make the API seem as .NET-friendly and standard as possible. This includes creating a real object oriented API, rather than the C way (where you pass the structure in as the first parameter). At runtime it'll be nearly the same thing, but it really changes the whole of the API.

Before I can do any real function calls or library work, I need to have the base classes defined: channels, files, etc. My first approach was the “nicest”. My idea was to prototype the structures in C#, allowing direct access from the .NET runtime to the structure, using C# unsafe code (i.e., ast_channel *myPtr; myPtr->language). I'd rolle the unsafe code inside the class, so to an end-user, it'd appear as a normal property.

However, I don't trust that all the structures in Asterisk will stay the same all the time. If a field was added or moved around, I'd have to declare a whole different prototype. To make things worse, I think it's entirely possible that there could be some #defines that people change per-platform, and that there could be multiple valid prototypes that I'd need to support (as part of the C# build process). My goal is to ship a runtime that can be built on the target machine, but the C# API should be able to be distributed in binary form without any issues. One main goal of this is that building ast_mono won't require a C# compiler. The IL binaries should be fully portable by themselves.

So, despite the advantages and elegancy of being able to access the structures with pure managed code, it's not going to happen. I checked out SWiG, and it's quite powerful. SWiG allows you to take C/C++ headers and turn them into definitions for C#, Java, Perl, and a slew of others. I might possibly be able to use this tool as a basis for my app.

For C#, SWiG creates a class that takes a pointer to the unmanaged structure. Then it generates properties in C# that call P/Invoke methods on a C class it generates. So to access the language field of ast_channel, the get property accessor P/Invokes to ast_channel_get_language. This is OK. However, I believe it can be done better using internalcalls.

Mono allows a runtime host to register internalcalls. Internalcalls run as part of the runtime, and have access to the native .NET types. This removes the need for marshalling to those calls: a big plus. Obviously there will still be some marshalling needed for some types (i.e. taking a null-terminated ANSI string and creating a .NET string), but it'll be easier to work with. For the performance and flexibility of doing things this way, I think it's worth the bit of extra work to write a small program to generate some of the wrapper code for me instead of using SWiG. (I also am not very fond of the code generated by SWiG.) Also, I should be able to grab the comments from the headers and generate some basic XML docs.

Methods are quite a bit simpler, with the same basic principles applying. I'll extend my code to emit some basic definitions (C# prototypes + basic C Mono implementations) and that should get me going.

On a side note, although right now I'm sticking to the ISO spec of C#, Mono 1.2 has support for many of Whidbey's features. This means I get to use generics soon. Also, I am going to be compiling with the Whidbey C# compiler, so compile-time only features, such as partial classes, are available too. Yum :).

Tuesday, October 26, 2004 3:50:43 AM UTC  #    Comments [0]  |  Trackback

# Monday, October 25, 2004
Missing the point: 1,064-bit encryption
If you don't get Crypto-Gram, or don't subscribe to Bruce Schneier's blog, do so. Today he posted a little gem about a county buying voting machines, who is detailing their decision to use a certain vendor. One great reason: “Uses 1,064 bit encryption, not 128 which is less secure.” People actually trust these people to run their elections? On another note, they mention they can put the machines in junior high to encourage voting. From what I remember of the u.s. education system, isn't that up to about 8th or 9th grade? If you're 18 and still in junior high, there's probably more pressing issues than voting... or maybe those people who grow up and select voting machine vendors?
Humour | Security
Monday, October 25, 2004 3:33:42 PM UTC  #    Comments [0]  |  Trackback

# Monday, October 18, 2004
Why pasting HTML is so slow

One thing that constantly annoys me is pasting or using HTML content inside Word/Outlook. For instance, replying to an email that has complex HTML formatting and linked CSS files and images takes forever. I've got a 3GHz P4c and 1.5GB of RAM, so the issue isn't local. Ditto for pasting text from a web page into Word (I'm constructing a Word document from some data I have on a page somewhere). It takes up to 20 seconds for the text to appear! When I have a bunch of small snippets, that's obviously unacceptable.

My theory was that it must be hitting the webserver to get the styles. A few minutes with Ethereal and I found out that yes, that's exactly what it's doing. Sigh. I understand the reasoning, but I'd like it to be easy to disable. My connection sucks right now (plus I'm downloading Fedora Core 2), so even loading a simple style page takes a while. I'd like the HTML copying to be able to embed the style info there for other apps to use... or something. I know that by default, the alternatives might be worse (users would lose their styles after pasting and be very confused). But this scenario just isn't working for me either (I have to paste to notepad first :().

A funny thing is, Word always does this, even when editing an email in “plain text” mode. I'm guessing the style lookup is handled at a much lower level, where there's no knowledge of plain text existing. (You can also see odd behavior when pasting formatted text into Outlook Express in plain text mode: The plain text is simply not honored (well, when it's sent it is, but not while viewing the message).

Just one of those things that never fails to annoy me.

Misc. Technology
Monday, October 18, 2004 10:10:56 PM UTC  #    Comments [0]  |  Trackback

# Sunday, October 17, 2004
ast_mono_loader -- Embedding Mono into Asterisk - Phase 00

Asterisk (www.asterisk.org), is a piece of extremely powerful VoIP/PBX software. It can bridge just about any codec (u/aLaw, G.729, G.xxx, GSM) and protocol (SIP, SCCP, H323, and it's own IAX). Plus it's got a ton of cool features and is extensible. The only downside is that for maximum power, you must use the C API. For some people, this means low productivity. For others, it means forgetting about having great flexibility and power.

I like C#, and I want to write most of my code in C#. But, I'm also going to be writing a lot of code for Asterisk. So, I'm doing the only sensible thing: Embed Mono (www.go-mono.com) into Asterisk and load my .NET assemblies from there, while exposing the complete Asterisk C API to my .NET applications. (In other words, much more than just spawning a new process and passing args and reading stdout).

Well, after spending 2 days trying to get Mono to work and my code to link to it, I finally got things working (without formatting and laying down Fedora Core 2!). Nothing much yet, but I got a sample program to be loaded into the Asterisk process, and I executed by dialing an extension. Now I just need to complete the API, enhance the loader, and do everything else, and I'll have a very solid project.

If you use Asterisk and would like to write with C#, contact me (mgg @ this domain .com). I'm also in #asterisk on irc.freenode.org as AgiNamu.

Or, if you like Microsoft and .NET, but want to get into VoIP, drop me a line. I haven't seen any real solutions that compete against Asterisk for Win32 (or Win64).

Sunday, October 17, 2004 12:41:52 AM UTC  #    Comments [1]  |  Trackback

# Friday, October 15, 2004
Note to Guatemala: It's not Christmas yet

It's what, mid-October? Already (and for the past two weeks I think) there are Christmas items for sale at stores, and Christmas jingles playing on the radio down here. October, November, December. That's 3 months out of the year. 3/12 -- One QUARTER of the entire year is devoted to Christmas-related marketing. And the countdowns. They do countdowns. First, the number of days until December “the nicest month of the year”. Then the countdown to Christmas itself. What drives this lunacy? Seems like something that goes on for a quarter of the year would loose its feeling of specialness.

Friday, October 15, 2004 9:17:41 PM UTC  #    Comments [0]  |  Trackback

MySQL is really secure... or bad.

I chose MySQL to use as my database, since I was writing on Linux, in C, and it just seemed like the easiest path. Can someone please say “you were so wrong”? MySQL has to the worst DB engine out there. It doesn't (ok, just added) even have support for SUBQUERIES! Barely has support for multiple charsets. And... binary(20) is NOT a binary field 20 bytes long. It's a char(20). You can't execute multiple commands in a single query. It's embarrassing to open source really. I don't know who could argue that MySQL is competition for SQL Server or Oracle and keep a straight face. Check this list out: http://sql-info.de/mysql/gotchas.html (I really love the part about date handling.)

On the other hand, it's very secure. www.kalea.com.gt <-- No checking of user input whatsoever. (BTW, my little article about Kalea made me a top search result for Kalea Guatemala -- while their site doesn't even show up.)  They take your querystring, concat it to their query, and off it goes. But guess what? Good luck trying to hack it. MySQL is so poor, doing SQL injection and achieving anything fun is nearly impossible. So much for adding prices to their site :). Oh wait, you can do a DoS by using the BENCHMARK expression and then encode/Sha1/etc.

So what am I going to do? Switch to SQL Server as soon as I get a release candidate done. I'm going to load Mono into my C app, and then transition into managed code and use some nice TDS libraries and have a good day with a database that actually works well. Had I done that to begin with, I'd be a few hours ahead of schedule instead of behind schedule...

Code | Humour | Misc. Technology | Security
Friday, October 15, 2004 4:18:53 AM UTC  #    Comments [2]  |  Trackback

Visual Web Developer is so nice

I've been working a bit on the web-side of my VoIP application, obviously in ASP.NET (hey, just because Asterisk runs on Linux doesn't mean I'm completely converting!). I'm finally getting to use VS2005 full-time. The Web.NET has done an awesome job of fixing up the editor. Pretty much everything that really bothered me and sucked about editing pages in VS has been fixed. Selecting elements is so easy. Navigating the HTML is simple (and doesn't loose formatting!). The built-in webserver (and no IIS requirement!) rocks for debugging. I'm just quite surprised at how good everything is. I saw all the cool features a year ago, so I knew it was supposed to be nice, but just using it drives the point home.

Code | Misc. Technology
Friday, October 15, 2004 3:03:58 AM UTC  #    Comments [0]  |  Trackback

Relax: Product teams know what they're doing?

I take Visual Studio very seriously. I spent more time in Visual Studio than in anything else, so potentially any problem in there can easily ripple out to the rest of my life. Thus, when things break for me (i.e., removal of database diagrams, ASP.NET compilation model mess up, etc.), I really, really worry.

What I'm slowly accepting is that as much as Visual Studio/.NET/etc. matters to me, it matters to the respective product teams even more. So I should be able to lay back, relax and enjoy my time 'till my eyes roll back and the next version ships, right?

It's sort of like the Year 2000 issue. I knew a lot of end users (say, people owning electrical devices), who were moving to the mountains, stocking up on supplies, preparing for The End, etc. , while saying stuff like “the power grid has microchips that can't handle the year 2000”. These people also wouldn't know what a power grid was if one landed on their head. Did they really think that the electric companies (or any company) wasn't at least as concerned as they were? As if having their grandma spouting nonsense was going to get the attention of the CTO of the local power company?

That said, I'm of the strong opinion that I'm not an idiot, and at least somewhat clued in as to what to expect from certain products :). A few things have gotten me hyper during the last year, but I believe the product teams have handled or are in the process of handling most of them. So I have to wonder if somehow me + n other people “overreacting” is what drove these changes, or the product teams just woke up one morning and said “hey, this sucks”. At least with Ladybug, ahem, the MSDN Product Feedback Center, we should be able to get a bit more insight on what really goes on with certain issues. What I'd really like to see is a bit of explanation with each resolution -- if something's a Won't Fix, knowing the reasoning behind it can go a long way in soothing users.

Misc. Technology
Friday, October 15, 2004 2:55:41 AM UTC  #    Comments [0]  |  Trackback

# Thursday, October 14, 2004
Dell Axim 50v -- this is a handheld!

I really want to get a Tablet PC, but I just haven't seen a model that's right yet. However, I have found a handheld that's just awesome: The Dell Axim 50v. Check out these specs:

* 3.7” Screen
* 640x480 resolution @ 16bpp // YES, that's full VGA resolution
* 624 MHz Intel Xscale PXA270 processor
* 128 MB Flash ROM and 64 MB SDRAM memory with XMB (cross media bar) on-screen navigation to access memory
* Integrated 802.11b Wi-Fi and Bluetooth 1.2
* Intel 2700G multimedia accelerator with 16 MB of video memory, providing DVD-quality video playback and supporting dual display capability for professional presentations
* VGA-Out (extra)
* Integrated CompactFlash Type II and Secure Digital / SDIO Now! / MMC card slots
* Headset / headphone jack (cell phone replacement anyone?)
* Full duplex 16-bit 44.1 Khz audio

Now THAT's a lot of handheld for $500.

Misc. Technology
Thursday, October 14, 2004 5:08:13 PM UTC  #    Comments [0]  |  Trackback

# Tuesday, October 12, 2004
Why do we lose the ASP.NET 1.x compilation model in ASP.NET 2?

Writing the Turing ASIX brought me back to a really sore spot in ASP.NET 2: Lack of a good compilation model. In ASP.NET 1.x, you could compile all your code (*.cs) into an assembly, and you were set. Here's why I hate the new “code-beside” and “dynamic compilation” models as they are implemented in VS 2005:

--Deployment/content editing nightmare
Before, I could drop the DLL on the server, *have no source code* on the server, and allow someone else (i.e., my client), to edit the ASPX/ASCX content. In a few cases where I wanted to expose code to him, I could make a virtual method in the base class, and allow him to override it via C# code in a <SCRIPT> block. With the new VS 2005 model, my scenario is blown away and destroyed.

--Access to code means huge, ugly, hackish workarounds
Before, if I made a page/class/control/whatever in any part of my app, I could reference this from any other part. For instance, my Turing image generator. I have two statics on it that any page can call. I want that code to be in Turing.asix.cs (or in the .asix). But I can't! I am required to put it in the /Code directory for no reason at all. Maybe this was done because of the “web programmers” who think HTML is a programming language. Maybe it was to act as a ward to scare of people who are afraid of code. I can't figure it out. All I know is that it pisses me off. This problem is more serious than just my annoyance about moving one file.

Suppose I'm working on a larger site, and to keep things in line, I organize the site into various folders. Now say I'm in something like /TheSite/SomeArea/HierarchialViews. I have a few ASCX controls there, but they all share some common code (some enums, and some pure code classes that help with the sorting or organization for the views (say, something that generates a generic tree to be consumed). Where do I put the code? Well, with this new model, I've got to put it in /TheSite/CODE/SomeArea/HierarchialViews. In other words, I'm required to duplicate my entire site organization inside the Code directory, just because... um, well, I haven't found a decent reason yet.

The ASP.NET/VWD/whatever team should NOT be making these kinds of decisions for developers. Visual Studio should be a tool that we can use to write apps how we want to write them. This model worked fine for 1.x. Why has it become so hideous that they needed to REMOVE it from 2.0? With all the huge advances ASP.NET 2 and VS2005 take, why must they take this big jump backwards? Couldn't they just leave it in and say “You can do this, but we really recommend using a Code folder so you don't lose track of your .cs files.”??

The only *partial* reason for this behaviour that I can tell is the move to partial classes. Since it's a partial class, it needs the rest of the code generated from the ASP.NET runtime to compile. *I* was quite happy with the inheritance model used before. While partial classes are nice, *I* don't see any personal benefit in using them if it's going to introduce problems like this. At any rate, that still doesn't explain why I can't have a Foo.cs inside any directory (not just the /Code directory) and be able to use it.

Code | Misc. Technology
Tuesday, October 12, 2004 1:38:46 PM UTC  #    Comments [2]  |  Trackback