|
|
|
|
 Thursday, November 04, 2004
|
Do you use .NET? If so, the BCL design guidelines are in dire need of your support! According to Krzysztof Cwalina, the BCL is now going to start using long names for parameterized types. Forget Dictionary<K, V> and clean, concise, code. Nope. Apparently some people couldn't figure out what the heck a List<T> was, and really needed List<TypeOfTheItemInTheDamnList>.
And the BCL team, in an effort to save some work in tools I imagine, decided not to add documentation/descriptions thru metadata (i.e., add an attribute to say <T> in List means *the type of the item in the list*).
Here's the details: http://blogs.msdn.com/kcwalina/archive/2004/11/03/251722.aspx
So, do you want to write/maintain/use/and in general just look at horribly verbose code? If not, get you say in here: http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=3cee09d8-3b82-4c5f-83a4-be52ba9b9e98
Vote against this ugly excersice in verbosity today!
|
|
Code
|
Thursday, November 04, 2004 3:34:45 PM UTC
|
Trackback
|
|
As I mentioned a few posts ago, I have a makefile project in MSVC++ 8 (2005) setup. Part of my solution builds with GCC on Linux, part on Windows with CSC. By using plink (command-line version of Putty), I'm able to ssh over to my Linux machine and build. The errors show up in the error list in VS2005. Except for one slight problem: Visual Studio does not read the error line information correctly, resulting in an error if I try to click and goto that line.
GCC outputs errors so: my.c:123: error: you suck. VS expects them as my.c(1) : error you suck. So, I decided to write a filter for the output. But, since it was around 2 AM, I decided to check and see if GCC supports out in the style that VS expects. As far as I can tell, it doesn't. But, I found a link to a page that has a program that accomplishes just this (GNU2MSDEV): http://www.xs4all.nl/~borkhuis/vxworks/vxw_pt1.html#1.13
Yey, I'm done, right? Well, not quite. GNU2MSDEV reads from stdin. GCC puts the errors on stderr. So, the parser only gets part of the output, missing the critical parts. Ouch. Now, since it's past my bedtime, I spent a while trying to figure out what was going on, thinking perhaps the program was broken. Got the source, uncommented some debugging stuff, and finally, I realised that I'd need to get stderr send over stdin, as the easiest course of action.
I'm not sure how you redirect stderr in the NT command shell. One page I read said this was impossible from the command line, and you need to use a different shell (they suggested running Linux), or write a program to do it for you. I decided to just add this to my linux commands. Now, my VS build command line looks like this:
plink 192.168.0.123 -ssh -l myUser -pw myPassword "cd /usr/src/something;make clean; make install 2>&1;" | gnu2msdev
Presto. Now it works just perfectly, and I can double click the error list and go right to the file/line where the error is. Of course, now it's 3AM for some reason, and instead of writing some code to record phone calls, I'm instead going to go to sleep.
|
|
ast_mono | Code
|
Thursday, November 04, 2004 9:02:41 AM UTC
|
Trackback
|
|
Windows decided not to load 2 of my hard disks (yes, I'm buying a RAID 1 setup tomorrow -- yikes!), so I wasn't able to access my music collection. I can't work at all without some sound. So I found a shared folder from KCeasy and lo and behold, it had a few interesting things in it, so I queue'd them up.
Well, one track was by Ayumi Hamasaki, and I quite liked it. So I thought, hey, I'll go buy the CD. $28, not that bad. Oh wait, what's this?
Shopping Note: · This CD is copyright-protected. The tracks on the CD can be played on PC running Windows operation system, but cannot be copied onto any PC nor can they be played on Macintosh operation system.
Can be played on a PC, but can't be copied? Huh? That means they do Some Very Evil Stuff. If a CD can't be copied, then something seriously wrong is going on. Now, the only thing I've heard of is it that lame technology that puts a driver on your system to screw things up and then gives you access to WMA only. I think it comes from a company that has the word “Sun” in their name. The one that you can bypass by disabling Autoload.
Well, I don't play CDs, period. My playlists are huge, I'm using my DVD drive for other things, and I hate the idea of passing physical media around for no reason. I also despise any company that tries to covertly install drivers to destroy my computer.
So, what's the outcome here? Well, I'm not gonna buy the CD. The artist loses $3? Oh no. I'll still get the music (gonna queue it up right now), and if I like it, I'll be a fan and if I happen to be around where a concert is, perhaps I'll go. But as far as paying for locked down media? Screw 'em. In fact, if I'm going to PAY for the media, I'd like them to ship a professionaly encoded set of WMA tracks at 256Kbps along with the CD audio. Actually, heck, just send me the WMA files. I don't need CD-audio. Send me higher quality WMA files (higher sampling, higher bit depth, WMA Pro codec, lossless compression). Oh yea, and get rid of the lame attempt to use DRM. Then I'll buy.
|
|
Misc. Technology | Security
|
Thursday, November 04, 2004 4:25:20 AM UTC
|
Trackback
|
 Wednesday, November 03, 2004
|
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
|
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).
|
|
Code
|
Saturday, October 30, 2004 5:29:29 AM UTC
|
Trackback
|
 Wednesday, October 27, 2004
|
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); sb.AppendFormat("<{0}>",tag); int len = sb.Length; int idxSt=-1,idxEnd=-1; if( -1 == (idxSt = rsp.IndexOf(sb.ToString()))) { return ""; } idxSt += len; sb.Remove(0,len); sb.AppendFormat("{0}>",tag); 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
|
Trackback
|
 Tuesday, October 26, 2004
|
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.
|
|
ast_mono
|
Tuesday, October 26, 2004 7:20:26 AM UTC
|
Trackback
|
|
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.
|
|
Code
|
Tuesday, October 26, 2004 3:55:49 AM UTC
|
Trackback
|
|
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 :).
|
|
ast_mono
|
Tuesday, October 26, 2004 3:50:43 AM UTC
|
Trackback
|
 Monday, October 25, 2004
|
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
|
Trackback
|
 Monday, October 18, 2004
|
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
|
Trackback
|
 Sunday, October 17, 2004
|
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).
|
|
ast_mono
|
Sunday, October 17, 2004 12:41:52 AM UTC
|
Trackback
|
 Friday, October 15, 2004
|
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.
|
|
Guatemala
|
Friday, October 15, 2004 9:17:41 PM UTC
|
Trackback
|
|
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
|
Trackback
|
|
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
|
Trackback
|
|
|