Saturday, March 21, 2009

Refactored code...which is better?

this morning, i was editing some code, and Resharper warned me about a possible System.NullReferenceException. i'd been bitten before by this in the same code, but that was because i didn't understand how XmlReader worked then. here is the original code:


MessageDatabase messageDatabase = null;
MessageTable messageTable = null;

while (configReader.Read())
{
  if (configReader.NodeType == XmlNodeType.Element)
  {
    // ...
    if (configReader.Name == "messagedatabase")
    {
      messageDatabase = new MessageDatabase();
      messageDatabase.Name = 
        configReader.GetAttribute("name");
      MessageDatabases.Add(messageDatabase);
    }
    if (configReader.Name == "messagetable")
    {
       messageTable = new MessageTable();
       messageTable.Name =
        configReader.GetAttribute("name");
       messageDatabase.MessageTables.Add(messageTable);
    }
    if (configReader.Name == "identityfield")
      messageTable.IdentityFieldName =
        configReader.ReadElementString();
    // ...

as you can probably tell, it's supposed to parse an XML file and convert it into a bunch of objects. nothing wrong with that. it takes into account the structure of the XML and makes an assumption based on that, namely, the <messagedatabase> element is always processed before the <messagetable> element, so messageDatabase will be set to an existing MessageDatabase object before any MessageTable instance is created.

a more explicit version of the code is shown below:


while (configReader.Read())
{
  if (configReader.NodeType != XmlNodeType.Element) continue;
  // ...
  if (configReader.Name == "messagedatabase")
  {
    var messageDatabase = new MessageDatabase
    {
      Name = configReader.GetAttribute("name")
    };
    MessageDatabases.Add(messageDatabase);
  }
  if (configReader.Name == "messagetable")
  {
    var index = MessageDatabases.Count - 1;
    var messageTable = new MessageTable
    {
      Name = configReader.GetAttribute("name")
    };
    var currentDb = MessageDatabases[index];
    currentDb.MessageTables.Add(messageTable);
  }
  if (configReader.Name == "identitfyfield")
  {
    var dbIndex = MessageDatabases.Count - 1;
    var currentDb = MessageDatabases[dbIndex];
    var tblIndex = currentDb.MessageTables.Count - 1;
    var currTbl = currentDb.MessageTables[tblIndex];
    currTbl.IdentityField =
      configReader.ReadElementString();
  }

while this is more explicit, the code is simply more. for each property of the MessageTable, i must get the index of the last database and the last table in it, and then set the values accordingly. that plain sucks.

there was one good thing about writing this post: i finally thought about where i could optimize the loop that advances configReader, and added continue statements where they wouldn't cause exceptions. :D

Sunday, March 08, 2009

Done in very cleanly by Opera Mini

i had an emergency, and needed to send someone an email. i'd just installed Opera Mini, and decided to acutally use it instead of my phone's default browser. i logged into GMail, opened the mail i wanted to forward, and began forwarding it. i had to attach a file, so i copied it to my phone's memory card and attached it with no hassles. the problem was that every time i clicked 'Send', GMail would belch up an error concerning an invalid email address, which came to something like “/tmp/<gobbledygook>”. i resent this email thrice, to the same effect. Opera Mini is a great mobile browser. but i'm really shaken, as this is my first time using it, and i had this problem. ah well. since my main internet came up, i no longer needed to send the mail (which incidentally, was saved in my 'Drafts' folder).

Saturday, February 28, 2009

How I use Python

i love Python. i find it one of the most expressive programming languages i know. It's saved my bacon quite a number of times. for instance, when i generate test data for other applications i write, i generally generate the data (and usually the SQL to insert it into a database) with Python. also, when it comes to sorting data, it's much faster to write scripts to do basic data sorting (as an example, sorting out CDRs from Asterisk) in Python than it is in most languages. today was no exception. i had loads of numbers to send text messages to and i needed to weed out invalid destinations. for the first 50 or so, it was easy enough (but tiresome) to do by hand. when i started to look at just how many, i decided to write a script to help me sort out the numbers. abut 10 minutes later (mostly spent trying to create regular expressions that would do just what i wanted), i was done. and most of the program worked beautifully (well, there were some hiccups. i'm not perfect!)

Friday, February 20, 2009

The value of multiple cores

my laptop uses an AMD Turion 64 processor that clocks in about 1.8GHz. i've always thouht it was a pretty good one — at least until this morning. i've never been faced with the value of multiple-core processors personally as today. what happened is i was trying to get back into design & 3D, so i decided to model & render items i could find around me. so i started modeling this: after modeling and setting up the scene in Blender to render with Indigo, i started a render. almost six and a half hours into the render, it looks like this: then i take the scene to the office and try rendering on a Pentium Dual Core 2.0Ghz. about four and a half hours later, it look like this: obviously the second render is better. and it ran for a shorter time. i'm officially jealous! i want a multiple-core system now! :D

Wednesday, February 18, 2009

Accessing SQL Server (2005+) databases in .NET Windows services

just a simple quickie here. i completed my application (somewhat...do we ever really complete applications?) - and the service it was meant to configure — then found out that while it ran beautifully in console mode, it just sat there after connecting to the SMPP server. i kept wondering what the problem was. much later i realized that the service was created to run using the local Service account, which is a low-privileged account. as such, it cannot connect using Windows authentication to SQL Server versions that support it. in reality, this is the second time i've faced this issue. at any rate, all i needed to do was change the service to run under the local System account (a highly privileged account) and the problem was solved. another solution would probably be to use SQL Server authentication, which Microsoft doesn't recommend. yet running a service using the local system account is also seen as a bad idea. i guess you'll need to make a tradeoff to solve this problem.

by the way, this is the app i was complaining about. . many thanks to Component Factory for the excellent (and free) Krypton Toolkit.

Tuesday, February 17, 2009

Weird issue in Visual Studio

i was working on the config application for a service i wrote...but i ran into something really strange:

Thursday, January 29, 2009

The Matador

Just now I was having dinner, and the TV was on. We're subscribed to DStv, and while I usually don't watch TV, my computer was busy in the room, so I had to manage until I was done with dinner. M-Net Movies was showing The Matador, and I just happened to watch the scene where Bean (Hope Davis) wakes up and meets Danny (Greg Kinnear) having breakfast. They start kissing and then it gets heavier; Bean asks Danny if he has enough time, Danny already strips to his shorts when he shouts, "Tree!" — and a tree crashes into their kitchen. I could hardly stop laughing. I don't care how hard your hard-on is—a tree crashing where you want to have sex will put a stop to that quickly. No, I didn't stick around to watch the rest of the movie (it's still running now). Oddly enough, while reading about the movie, I found out that Danny asks Bean if she's still horny after the tree crashes. Is he an idiot or what?. Now if I were God...

Baby steps with Mono

Mono is definitely some great software. I downloaded and built Mono on our Asterisk server because it seemed I'd have to develop the application to handle the automated calling on Linux. Not wanting to hurt myself with PHP, Ruby or Python (time frame), I decided to continue using C# and .NET, since I knew enough about Mono to know it is cross-platform. What I wasn't prepared for is just how cross-platform it (and .NET) is. After downloading and building it, I created a "Hello, World" application in it and ran it on the Linux server. I then moved the compiled assembly to my Windows desktop and it ran with the Microsoft .NET framework! After I got home, I built one of my old programs, which had a reference to the excellent FileHelpers library. The library was probably built with Microsoft's tools, but I was able to build (and run) the application using Mono (for Windows).

That's pretty amazing, but the last part is even more amazing. I just tested the Devshock SMPP component (which was definitely built on Windows, using VB.NET), in a program I wrote using Mono on Linux. There's a text on my phone now that proves that .NET is an awesome platform, and Mono is a great cross-platform implementation of that platform. Mono rocks. Period.

Monday, January 26, 2009

Using the Asterisk Manager Interface (AMI) to make calls in C#

for some reasons, i've been interested in using Asterisk.NET (mostly because code completion in a GUI beats grokking code in a command line). one problem i'd always had, though, was making calls. for some reason, i'd just get the message 'Originate failed' returned to me. today i was working on my sample program again, when i got the same error. i then started looking through the Asterisk.NET code to find out what i could be doing wrong. i also dug out my trusty copy of .NET Reflector to analyze the assembly.

the main source of aggravation was that i could use call files, and they'd work. but with Asterisk.NET, at most i'd get a missed call. my code went something like this:

var myManagerConn = new ManagerConnection();
myManagerConn.Hostname = "asterisk-server";
myManagerConn.Username = "admin";
myManagerConn.Password = "god";
myManagerConn.Port = 5038;
var action = new OriginateAction();
action.Channel = "SIP/3595009";
action.CallerId = "3595009";
action.Context = "robocall";
action.Exten = "10";
action.Priority = 1;

myManagerConn.Login();

myManagerConn.SendAction(action);

myManagerConn.Logoff();
after some sniffing around in Reflector, i found the Timeout property for the OriginateAction class. i went looking in the code, and found that Asterisk would set it to a specific value (30000 milliseconds) if it wasn't set. knowing .NET initialization, however, i guessed that the underlying field was probably set to 0, and set the property explicitly to 30000. i ran the program again, and the call came in, the phone kept ringing (yay!) — but the program generating the call threw an exception complaining about a timeout. i increased the timeout to one minute to no avail. i then decided to set the timeout parameter for the SendAction() method of the Asterisk.NET.Manager.ManagerConnection. the resulting call was like this:
myManagerConn.SendAction(action, 30000);
. and the program worked. like that. so i guess i may just be able to get this automated call thing done without using a terminal to the Asterisk server.

Tuesday, January 20, 2009

Installing PEAR on Windows

i wanted to install PEAR on my Windows machine as a prelude to installing symfony. i'd installed PEAR before on Windows, no biee. but when i tried using the batch file to install PEAR today, i was greeted with a list of 12 options after deciding to install a system-wide copy. the last option specified C:\\. as the PHP executable path. every time i changed it to C:\\php.exe, i couldn't continue to install PEAR. i had to leave it as-is, install PEAR, then edit the pear.ini file to specify a correct path. ideas, anyone?

Monday, January 19, 2009

Shallow Relationships

as an example of just how shallow my relationships are, i just told my neighbour "Happy New Year". on the 19th. my neighbour. we live in the same building. and have lived every single day of this year in said building. pretty pathetic, don't you think?

Sunday, January 18, 2009

where's the cotton-pickin' "Undo" command in real life?

quite a bit has happened since i was here last. for one thing, it's now over 5 years since my mum passed on. and it seems that my dad is "officially moving on" — whatever that means in English. monday i was going home from work, and i saw this really hot (translate: hawt) chick getting out at Obalende. great body, pretty as a flower and had this really nice musical voice (i have no idea what that means either, but it sounds good ;)…and i started thinking about my life.

an ache i hadn't felt in a while came up (though i did the sensible thing and went looking for my next bus instead of gawking), an ache to have someone to hold, to talk to (don't act like you never felt it before! guys really want to have a beaty to rescue!)…and all that. there is no such person in my life. and in the last couple of months, i've been asked (subtly and non-too-subtly) quite a number of times about my "relationshipital" status. no, there's no one either here or on the horizon. so if i really want to hug someone, i'd better grab my pillow. and maybe weep into it. except i'm not that lame. or so i'd like to think. or maybe not. either way, it doesn't really matter since what i do with my pillow doesn't affect the price at which i buy fish in the market.

it's not like i've lacked opportunity to dig trenches and build bridges. at least i'm not in the "women are irritating" phase right now (on the contrary, they're currently interesting — but shall this soon come to pass also? i'm unhurried :D) it's just that for the most part — i get bored (ladies, seriously, it's got nothing to do with you. i easily get "bored" normally. so don't show up at my house with pitchforks, ok? ;), for lack of a better description. maybe they piss me off. maybe i piss them off. i dunno. rare has been the woman who held my attention for 6 weeks or more. i think i broke something. though i can't tell. few and far between are the friends with whom i share my secrets. that's another thing i realized. i've so many shallow relationships, i may just be scared of a real relationship. it's really easy to say, hi, bye. hey sweetie, you're looking good and all that crap, but…i need real relationships. not plastic people with vinyl smiles that are cracked and faded. i'm not even sure where this is coming from. despair? regret? but then, where exactly did i miss it? dunno. maybe this is just a random rant coming from a testosterone overload, but it doesn't matter. since it really doesn't affect the price of fish, anyway.

all said and done, i'll was over it in a couple of hours, then wonder why in the world i posted this anyway. since i wasn't the one who killed Jesus, and i'm not the third leg in humanity. just for fun, i wonder what kind of person would lose sleep thinking about me (ladies, here's an itty bitty cheat sheet: guys want to know you're thinking of them too. really. even though they act tough. guys like me, anyway. unless of course, i'm right and i'm in the minority ;). anyway, enough ranting. off to bed to start what i believe will be a glorious week. why? we two oddballs are going to be spending more time together. and it won't matter that there is no trench in progress. who's the other oddball? naisho da. have a great week!

PS: last year, i needed to do a head scan. i was somewhat excited about it because i believed that i would finally find out what nuts and whatnots were not in place in my head. the result came back…normal. seriously. i had a regular brain like everyone else. not a clockwork one. or an electronic one (might have fried a few circuits). it felt like a letdown. yet another proof that despite my best efforts, ore wa tada no ningen. ah well.

Saturday, January 10, 2009

2009!

still here. yep, opened this year rather late, but it's no biggie. 2008 was a great year, and i have high expectations of myself this year. nothing works until you make it work by finding how it should work then putting that knowledge into practice. so go out and make it a great year for yourself. and one more thing: new year resolutions suck. don't bother. just make normal decisions and live by them.

Monday, December 29, 2008

ends and rants

been meaning to mention it for a while now: Hellsing is over. bit of a letdown, that ending. ah well. guess one can't have everything. no, i'm not telling you! go read it yourself. also, watched the last episode of Ga-Rei Zero last night. awesome ending. hope we get to see an anime series released soon. yes, i know i wondered what trashy anime was released when i watched the first two episodes. if it wasn't for someone else, i'd not have bothered watching anymore. boy, am i glad i did complete it.

on a not-so-light note, Chromium lacks print preview - and i'm not the only one missing it. what are the developers thinking? what good is a browser with no print preview (quite a bit, but i'm trying to stress a point here)?

i was thinking recently of the fact that Opera 10 alpha passes the Acid 3 test. great news for web developers and designers, but does that mean Opera will get a larger market share? and how does that translate into cash for Opera? passing the Acid 3 test does not mean that more users — a demographic much larger than the demographic of web designers or developers — will use Opera 10. yet, the fact that Opera 10 passes a test that the more popular browsers fail is a good thing - if you ask me

Saturday, December 27, 2008

Kindergarten

Thanks, Dayo for sending this to me

A mom was concerned about her kindergarten son walking to school. He didn't want his mother to walk with him. She wanted to give him the feeling that he had some independence but yet know that he was safe. So she had an idea of how to handle it. She asked a neighbor if she would please follow him to school in the mornings, staying at a distance, so he probably wouldn't notice her.

She said that since she was up early with her toddler anyway, it would be a good way for them to get some exercise as well, so she agreed. The next school day, the neighbor and her little girl set out following behind Timmy as he walked to school with another neighbor girl he knew. She did this for the whole week. As the two walked and chatted, kicking stones and twigs, Timmy's little friend noticed the same lady was following them as she seemed to do every day all week. Finally she said to Timmy, 'Have you noticed that lady following us to school all week? Do you know her?'

Timmy nonchalantly replied, 'Yeah, I know who she is.' The little girl said, 'Well, who is she?' 'That's just Shirley Goodnest,' Timmy replied, 'and her daughter Marcy.' 'Shirley Goodnest? Who the heck is she and why is she following us?' 'Well,' Timmy explained, 'every night my Mom makes me say the 23rd Psalm with my prayers, 'cuz she worries about me so much. And in the Psalm, it says, 'Shirley Goodnest and Marcy shall follow me all the days of my life', so I guess I'll just have to get used to it!'

The Lord bless you and keep you; the Lord make His face to shine upon you, and be gracious unto you; the Lord lift His countenance upon you, and give you peace.

May Shirley Goodnest and Marcy be with you today and always. I'm sure you smiled! I sure did.

You know your internet sucks…

…when it isn't worth it logging in to Megaupload to download a file for free to cut the waiting time from 45 to 25 seconds. condiments of the seasoning to all.

Thursday, December 11, 2008

Updates, updates...

i'm supposed to have moved my focus from the SMS part of my employer's business to IVR. i've had to deal with a flowchart-based development environment i find very annoying. plus, since i had no prior experience with telephony systems, quite a bit is lost on me. i've mostly been fumbling around in the dark.

this morning, my boss called me and asked me if i could develop a voice broadcast application using that environment. since i'd been having problems with it, i said i'd try. since then, i have failed in trying to get the application to make outbound calls. the alternative was to call in a consultant who's very good with Asterisk. i called him, but not after i discovered Asterisk.NET. before long, i had learned a little about the Asterisk Manager Interface and AGI, both of which i never knew existed before today, even though i've played around with Asterisk as part of my job. i also found the Sipek VoIP projects site. hopefully, i'll be able to build the application needed either by using Asterisk.NET or the Sipek SDK. either way, things should work out now.

Python 3.0 is out (i'm a couple days late on this one), and it isn't backward compatible with the 2.X series. looks like they really gave some thought as to where Python should go. i guess that means development of the 2.X series will basically be mostly bugfixes from now on. still, there seems to be a lot to like about the new Python, even though it's slower than 2.6 on the pystone benchmark (i cannot believe they actually took a line from Basic and added the <> operator in Python. thank goodness it's been removed in 3.0!). let's see how things go, especially with open-source projects that use Python. i'm personally wondering where IronPython goes (yes, they did it - got me sold on .NET. doesn't mean i now despise C++ though. i still plan on using it from time to time).

and thanks to Segun who gave me a ride yesterday when i forgot my wallet at home. you're the best, bro!

Wednesday, December 03, 2008

Looking for a .NET SMPP implementation - Part 2

seems my previous post was somewhat more popular than usual, judging from the two comments i got on it. so, i'm writing this more or less in response to those comments.

my answer is: it depends on a number of factors. what do you want to do? create a client or server? is working with unmanaged code a requirement? what kind of timeline do you have? is reading through code and class diagrams your way of learning, or is it one step above swallowing broken glass? must you absolutely have commercial support? what about licensing? when you look at all these, your mileage will definitely vary. at any rate, below i give some of the things i've picked up about these components. hope it helps!

IP*Works

  • You have to pay for it beyond the trial period.
  • You get commercial support.
  • Since it's a sold product in it's 8th major version, it should have been well-tested in production environments and suited for handling large volumes of SMPP traffic (note the emphasis. it may not have).
  • You get other components (well, check out the website yourself).
  • You probably don't get licensing issues (note the emphasis again).
  • There's an SSL version if you need it.
  • They have more than .NET if you need it (but those - except for Java - seem to have stopped in version 6).
  • i haven't used it, so i can't tell that you can use the component to develop a server.
  • website

RoaminSMPP

  • it's licensed under the GNU Library General Public License. as far as i know, that allows you use it in commercial, closed-source applications, but i may be wrong. also, you may not want to use LGPL components. then again, using opensource software may make you feel warm and fuzzy inside.
  • the developer says he's stopped development. any bug fixes may have to come from you.
  • documentation is in the source code. literally. there's no other source of documentation short of looking up the binary in a tool such as Red Gate .NET Reflector.
  • it's free.
  • having access to the source may just be the thing for you to tweak it.
  • SourceForge project page

Devshock

  • it's free.
  • it comes with example code. in VB.NET, no less :(
  • one of the sample projects seems to be an SMPP server.
  • the site was supposed to come up two months ago (in other words, unless someone mirrors the component, you're out of luck! as it stands, i've uploaded a copy here. someone please tell me if it's illegal with proof, and i'll remove the files).
  • since the site is down, i cannot state the license (it's not in the downloaded file). you may have licensing issues here too.
  • the assembly is not obfuscated in any way, so you can look it up in Reflector and figure out how it was built.
  • website (under construction)

ALT.SMS.SmppClient

  • it's free. you can purchase the source code, and get commercial support, free updates, and whatnot.
  • quite a bit of the assembly is obfuscated (i guess they should really add something in it like, "buy the source, you cheapskate!"). good luck poking around with Reflector.
  • there's a forum, so you and everyone else who uses it can decide to discuss it. don't compare that to paid support, though.
  • no visible license. that may be a problem.
  • website

SMPPLIB

  • written in unmanaged code. has a COM library too, so it can easily be used from .NET.
  • another item with no explicit license. sigh.
  • it's written in C++ and is MFC dependent.
  • you only get the source.
  • frozen since 2003.
  • website

EasySMPP

  • no explict license.
  • frozen since 2006.
  • looks simple enough to use, but i couldn't get it to work :(
  • example program included. there's a gateway using it (and as far as i know, it's the only gateway/simulator that seems to work with it).
  • free. opensource.
  • in case you missed it, it can be used for servers
  • SourceForge project page

BasheerG asked if i tested for performance & high load. no i didn't - i didn't have the space to, since i was (mostly) moved from the SMS arm of my employer's concerns. to answer your other question, if i could afford it, i'd go for the IP*Works first, then RoaminSMPP, then Devshock. i've no idea where i'd place the ALT.SMS.SmppClient. maybe lurking around the forum might help me decide. i'd hate to use the SMPPLIB component because of COM issues. and since EasySmpp didn't work effectively for me, i'd not use it. i hope this helps you and Sandip.

Monday, November 17, 2008

my weekend was an ass...wait, that's not right!

phew! what a weekend! Dad was out of town, so it was just my brother& i at home till last night. man, this was the illest weekend so far - as regards tiredness. i can't believe Friday & Saturday i was retiring before 10pm. dude, i really need some downtime - but i'm afraid that may not be till next month.

spent some time designing a website. unfortunately, it seems sticky-footer layouts are mutually exclusive with centered layouts. i can either allow the content pane be centered in browser window, or i can make the footer stick to the bottom of the browser window. so far, i haven't managed to let it do both.

i usually dislike the mass mail i sometimes get, but this one's got something in it so i'll reprduce it here:

One day a farmer's donkey fell down into a well. The animal cried piteously for hours as the farmer tried to figure out what to do. Finally, he decided the animal was old, and the well needed to be covered up anyway; it just wasn't worth it to retrieve the donkey. He invited all his neighbors to come over and help him. They all grabbed a shovel and began to shovel dirt into the well. At first, the donkey realized what was happening and cried horribly. Then, to everyone's amazement he quieted down. A few shovel loads later, the farmer finally looked down the well. He was astonished at what he saw. With each shovel of dirt that hit his back, the donkey was doing something amazing. He would shake it off and take a step up. As the farmer's neighbors continued to shovel dirt on top of the animal, he would shake it off and take a step up. Pretty soon, everyone was amazed as the donkey stepped up over the edge of the well and happily trotted off!

Moral

Life is going to shovel dirt on you, all kinds of dirt.The trick to getting out of the well is to shake it off and take a step up. Each of our troubles is a stepping stone. We can get out of the deepest wells just by not stopping, never giving up! Shake it off and take a step up.

see y'all some other time

Blogged with the Flock Browser

Thursday, November 13, 2008

Rhymin' on Facebook chat

was just wording with Legzitano on Facebook chat, and for some crazy reason, the conversation went like this:

Legzie: tryna stash cash
me: in a flash, smoking brown hash, flipping the ash
Legzie: brown hash is trash
cos you may crash
me: word bro...just tryna make that rhyme
Legzie: lol
me: maybe we should dash? grab some mash? what a bash!
Legzie: good, bro!
you sing like Nash
me: omo, battery don dey run down
Legzie: no vex!
ryhming no easy

i'm almost tempted to agree with the guy who said, "Of all the things i lost, it's my mind i miss the most". almost. but not quite.