Tuesday, July 29, 2008

O/RM and templating

i have a problem. i'm sending text messages to people based on data in a table. but people being who they are, they want to change the message structure at will. and the structure is currently hardcoded. so if i want to make the structure dynamic, i need a template system. i also need to map specific table fields to those template variables, then make the template changeable at runtime. that requires O/RM, so i can map table fields (relational) to objects i create in my code, and all the SQL is generated on my behalf by the O/RM engine. so far, i'm going with ActiveRecord and NVelocity from the Castle Project. i've used NVelocity, so i hope i'll get the same level of success from ActiveRecord (so many dependencies though :)

IQ tests are warped

Warning: shameless plug coming up! i added the IQ test application in Facebook. later on, the Advanced IQ test was recommended, so i added it and took the test. when i completed it, i found out of 15 questions, i only answered 13 and only got 6 right. yet when my IQ was calculated, it was rated over 100 (no, i am not telling you my computed IQ), which is not bad. in fact, it was higher than what was calculated using the regular test. hence my think they are warped. oh, 70 is idiot territory, so i guess i'm okay

Saturday, July 26, 2008

Avatar is over!

finally, i've watched all the episodes of Avatar: The Last Airbender. i have to say that all in all, the series was good. yes, there were some parts that really could have been cut out (like Season 3 Episode 17, The Ember Island Players) or modified, in my opinion, but then that's just my two cents.

stepping into Subversion

i've been joined by two other developers at work, so i needed to give them access to the code i'd written. i saw it as a great opportunity to try out version control, so i gave one of them the task of learning Subversion. he hadn't gone very far with actual implementation, and then my boss put him on something else, so i thought to myself, "what the heck" and started reading about subversion myself tonight. i installed the Collab.Net Subversion server, then TortoiseSVN and began scanning through the book (what? you expect me to actually read it? maybe on your time, not mine. it's past 2am here, for crying out loud).

i set up a repository, checked out, added a new file, tried to commit, then boom! authorization error! now the subversion book didn't say anything about this. so i downloaded HydraIRC, connected to Freenode, and joined #svn and ##csharp and asked. after some time with no answer, i went googling and found that a default repository allows anonymous reads and no writes, especially if you're connecting using svnserve. later on, someone gave me the same answer i got while googling. also got some useful tips, from the channels and the TortoiseSVN manual. in short, if you're going to use Subversion using the svn:// protocol (using svnserve, that is), you're going to need to configure your repository correctly. since it's in the TortoiseSVN manual, i'll refer you Windows users to it. please read Chapter 3, Section 2: Svnserve Based Server. everyone else, please look here for a few tips on configuring your repository for read/write access.

Saturday, July 19, 2008

i didn't go with .NET configuration files...and would like your input

i've been working on an application that needs to get some configuration parameters at runtime. at first, i thought of using configuration files, but then i realized that i would need to create another application that would be used to change the config. usually, an application config file is "tied" to the specific executable that it is created for, so - not being comfortable with XML in .NET - and having a tight schedule, i looked into other options. one was the registry and another was a custom config file. right now, i'm using SQLite as my storage medium, with the advantage that i can use the relational model if i need it. obviously, it has some drawbacks, but so far, i've got used to it. let me know what you think - assuming you do think anything.

Rant: why is Opera taking a long time to open Blogger - with no activity whatsoever? it's happened twice already...

Friday, July 18, 2008

The past week in review

hiya. been almost a week since my last post here. ah well. just wanted to bring you up to date with what's going on here, "here" being my life. grrrr. my neighbours decided today to have a party (an all-nighter by the sound of it), meaning there's going to be quite a bit of noise around.

in case i didn't mention it, i was in school last week. saw a couple of the guys, stayed over at Biyi's place while i was there. he seems to be getting along with his final year project and other stuff in his life. i'm happy for him. anyway, while there, i got some anime and have started watching Black Lagoon and Katekyo Hitman Reborn. i've also started Monochrome Factor and almost completed Hayate The Combat Butler. however, the anime series that currently has occupied my time is Code Geass. i started on Saturday and have almost completed season 1. i don't think i'd want someone like Lelouch as my opponent. my current fantasy revolves around a showdown battle of wits between Light Yagami (of Death Note) and Lelouch Lamperouge. sadly, this just reminds me of just how far behind i am with anime. Bleach, Eyeshield 21 and D.Gray-Man are all examples of abandoned anime projects. maybe you now understand one of the reasons i hate my job.

Wednesday: some local government people came around the building where i work and started complaining about the environment. so i don't bore you, they locked me and some other people in the compound. i had to jump over the gate to get out. i heard they later opened the gate - which is good, since almost everyone left in is female. every time i look at my right arm i remember - because i got scratched getting out. fro crying out, it's over 10 years i last did something like that!

Tuesday: i found that Visual Studio's debugger is superior to SharpDevelop's in one respect: if you're debugging applications within the environment, SharpDevelop's only catches uncaught exceptions. So if you're using System.Timers.Timer.Elapsed (for example), you'll never catch any exceptions. Visual Studio's, however, has no such compunctions, and will show exceptions even though the Elapsed event handler suppresses all exceptions. i can tell you that that's what saved my bacon on the current project i'm handling.

Monday: this project is my first experience with Oracle (even though i've had the express edition for almost a year), and if there's one thing i've learnt: always use 4-digit date literals in Oracle, especially if (like me) you're from a MySQL (or other database) background! i spent the whole weekend plus the greater part of Monday wondering what bug in Oracle i uncovered, only to find it wasn't a bug, just an Oracle quirk.

i've a custom class in my application that stores database connection parameters (previously in individual variables) - server, port, username, password and whatnot. since i'm moving to deploying the application solely on SQL Server 2005 Express (maybe PostgreSQL when i have the time to learn it) for now (no thanks to the many quirks of Sybase), i'm now simply hosting a SqlConnectionStringBuilder in the class. you really can't beat KISS.

while i'm still a newbie at regular expressions, i can definitely say they're great when they're used rightly. if i had to write custom code to validate phone numbers, i'd probably have a minimum of 20 lines of code, plus new if clauses (or similar) to write if the networks change. thanks to regexes, i can validate Nigerian GSM numbers - with or without country code - with about 3-4 lines - including creating the System.Text.RegularExpressions.Regex objects i want to use. and if i need a new case, i'll just have to change the pattern string. a pity more Nigerian developers don't seem to know about regexes - unless i'm wrong.

i need sleep! 'nuff said.

Saturday, July 12, 2008

Working with malware

hi. it's been a long time since i was last here. one month, eh? that's pretty bad. anyway, the point of this post is that i was recently in school, and came across some malware - one of which isn't picked up by any antivirus program i know as at now. this worms spread via USB storage (flash drives, external hard disks and so on). each copies itself to a clean device and also creates an autorun.inf entry in the device if it does not already exist (i can't tell what happens if it already exists). the one detected by AVG 8 Free has an executable named asp.net, and the one that isn't detected as at now has an executable named EXPLORER.EXE.

when i got to school, i had the 'privilege' of cleaning out two of my friends' computers. one was infected by the EXPLORER.EXE worm - which is easier to deal with if you don't have any antivirus installed - and the other was infected with the asp.net worm (if you have an antivirus that detects this, this is much easier to clean than without any antivirus, or one that doesn't detect it). let's start with the first.

EXPLORER.EXE worm in Process Monitor normally, a Windows machine has a process called explorer.exe. this process usually serves both as the shell (the program you use to launch applications) and the file manager. the executable for this is located in C:\Windows, has version information that comes from Microsoft, has the 'My Computer' icon and is about 1MB on a Windows XP machine. this worm is about 36kB, has no icon, has the same version information as the legal explorer.exe and runs from C:\Windows\system32. to get rid of this worm, you'll need a couple of applications from Windows Sysinternals, specifically Autoruns and Process Explorer (you can also download the entire suite if you want - it contains both). launch Process Explorer (an excellent task manager for Windows), accept the license agreement if you need to, and kill the EXPLORER.EXE process that doesn't have the My Computer icon and is running from C:\Windows\system32. next, launch Autoruns, allow it finish scanning, then delete the entries containing C:\Windows\system32\EXPLORER.EXE (use Ctrl-F) if you need to search). lastly, get rid of the worm executable itself. open a command prompt, and run attrib -h -r -s C:\Windows\system32\EXPLORER.EXE; del C:\Windows\system32\EXPLORER.EXE. this gets rid of the executable in its default location. your mileage will vary if Windows isn't installed on C:. EXPLORER.EXE worm in Autoruns

the other one is much harder to deal with because it creates a 'non-existent' process, according to Process Explorer. in fact, the process won't even be displayed in the processes list. i had to search for it manually. going through the console to use taskkill with the process id won't work either. so we're going to do it in the reverse flow. first, run Autoruns. search for appearances of asp.net autorunning, and disable, don't delete them. that's because if the worm is still running, it will simply recreate those entries. once you've disabled the entries, you can note the locations of the worm and reboot so you can delete it from all its hiding places (for me it was C:\Windows\system32 and C:\Program Files\Common Files\Microsoft Shared\MSInfo. again, this worm is hidden and probably has a system attribute set, so you need to remove those flags first. i'd personally recommend getting a recent (and decent) virus removal tool to remove this particular nasty, as it not only infects removable drives, but also fixed drives on your computer.

well, hope this is of some use to someone. have fun!

UPDATE: After a couple of days carrying around the EXPLORER.EXE worm on my external hard drive, i found that McAfee picks it up when i connected it to a colleague's computer. as at that time, neither AVG 8 Free nor PC Tools Antivirus was detecting it as a worm.

Wednesday, June 11, 2008

Windows power schemes

you really can learn something new every day. i recently formatted my laptop a couple of times for a number of reasons - one of them being that i found that my processor was constantly operating at its maximum speed and this was running down its battery seriously. after a new install, i noticed once again that the processor had starting running at its maximum speed again without stepping. i'd just installed WiX, and thought that might be the cause - but WiX doesn't update any system components, so i dismissed the idea (also, i'd installed WiX before and the processor was still stepping then). i'd gotten tired of formatting by then, so i just decided to keep using the laptop and its internal "oven".

this morning, i decided to google power schemes. i then found that for a laptop, power schemes really do matter beyond timing for switching on/off hardware like the monitor and hard disks. get this: they also affect the way the operating system uses the processor. for instance, the difference between "Minimal Power Management" and "Max Battery" is only the timing for turning off the monitor, hard disks, and going into standby - but under the hood, the CPU is allowed to toggle its speed based on demand. there's no difference between "Home/Office Desk" and "Minimal Power Management" when the laptop is on battery. for more information, please look up this article on Orthogonal Thought.

Blogged with the Flock Browser

Sunday, June 08, 2008

finally...finished Shounen Onmyouji!

Shounen Onmyouji is an awesome series, in my opinion. the opening song, Egao no Wake is wonderful (here it goes on my phone!), the story was great and flowed very well, and the end is awesome...(mostly). i was wondering what was going to happen in episode 26 when Masahiro kills Touda before the episode goes halfway. somehow, the end is rescued, and we get a believable ending...but why is the ending hinted at? if you - like me - rarely watch the end of an anime episode, you'd never find out that Akiko & Masahiro do go out to see the fireflies. ah well. in all, great series. pity i can't say if there'll be another great season.

Blogged with the Flock Browser

My phones and purpose

as i mentioned, i recently changed phones. i got a Nokia 7500 Prism to replace my 2600. One of the headaches of changing phones is migrating numbers. my SIM was full, and almost the same number of contacts were stored on my 2600. so i looked through my 2600, checking if the number was stored on the phone or on the SIM card, and then recording it in a text file - so i could transfer all my contacts to the new phone. i spent roughly an hour and a half doing this.

i can almost hear you say: fine, but what's this got to do with purpose? please bear with me - i can be a little long-winded when i'm trying to make a point. so i did that, then i put the SIM into my new phone and started using it - but the numbers stored on my old phone were still not on the new one. i went about for a day or so without having access to newer contacts. i then looked through my contacts (after finding out i wanted to contact someone, then seeing i didn't have their contact info), and found my 7500 had a function to move contacts from the SIM to phone memory. i did that, and emptied the SIM. i then checked the 2600 and found it could copy contacts from the phone to the SIM. so i did that too, and then moved all the contacts from the SIM to the 7500. if i'd only read the manual, i'd have saved myself about an hour and a half of typng out names and numbers.

i hope you get my point. some people might have spent another one and a half hours - or more - keying in the numbers into the new phone. but i decided that there was a better way. fortunately for me, i'm not as technically challenged as some folks, so i kind of figured out where to look pretty quickly.

let's imagine the time spent migrating contacts was your life. would you want to spend your life doing unnecessary things just to find out it was all unnecessary at - or after - its end? wouldn't you want your life to count for something? some people spend their whole lives doing things that won't count. there's Someone Who knows - much better than you - what you're meant to be doing. sadly, we usually think we - or worse off, other people - know exactly what we're meant to do. the person who best knows how my 2600 should have been used is its designer. God knows best what you're meant to do with your life. don't waste your life guessing what you're meant to do. ask Him! (James 1:5,6, New Living Translation, paraphrased: If you don't know what God wants you to do, ask Him, and He'll gladly tell you...). i pray you walk this path. life isn't meant to be guesswork.

Thursday, June 05, 2008

i got me a new phone, praise God!

i have no idea how it happened, so don't ask me, but this is what happened: i rarely change phones. i'm a strong believer in KISS, so if it can send/receive calls and text messages, it's a phone. even when MTN was giving out free MMS messages, i just had a faint feeling of loss. you know, the kind you get when you "miss" someone you never really knew. so i use my phones. and i rarely replace them. each phone replacement i've got was because the old one was faulty, got stolen or missing, except for the second. i have no idea why, but my parents decided to get myself and my sister new phones then. even the first phone i got was a hand-me-down (which i eventually handed off to someone else).

anyway, after being through about 5 phones in about as many years, my faithful Nokia 2600 developed a quirk. from time to time, it would stop ringing out (even in General mode), until ringing out at all became a very rare occurrence. i merely complained about the phone and didn't try changing it (i'm sure my pocket also had a great deal to do with this :). i was really shocked one morning when Dad, a friend and i were going out, and my dad asked why i didn't pick up his call. i mentioned my phone didn't ring out (dude, forget vibrating - i rarely notice that when i'm about). he gave me some cash to buy a phone. for maybe 2 weeks or so i kept stalling over the phone, which made no sense, because phones are sold less than 30 meters from my office. yesterday, after having a very interesting day, i just got mad and went to buy the phone. i didn't see something i liked in the display case, so i went to the price list. i saw something costing exactly what my dad gave me (no, it's not that much - but it's a sizable chunk of my monthly salary). i don't know why i felt good about the phone. i requested for it, paid for it without knowing jack about it, and went to test it. when the guy who tested it was closing the box, i asked where the USB cable was. He said it wasn't included and it would cost me an additional NGN 2500. i had that much on me, but i wouldn't be able to get home without visiting the cash machine, so i decided not to buy it. after buying the phone, i began feeling guilty, but i shook off the feeling and went home. getting home, i found i really like the new phone, plus, it uses the same cable as my MP3 player, so i really feel blessed! later!

Blogged with the Flock Browser

Sunday, June 01, 2008

Blender 2.46 out!

it's coming late, but Blender 2.46 is out, and the Big Buck Bunny movie is also out. personally, i downloaded Blender about a week back, but i haven't really don anything with it, since i'm doing a lot more programming than most anything else. and with the new release returns an old problem: i can't render with YafRay (no, not Yaf(a)Ray) as a plugin in the render window without Blender crashing. ah well. so i had to figure out workarounds - render into the 3d window, use YafRay from XML, or not use YafRay at all;)

Thursday, May 22, 2008

So Man Utd finally won...

now maybe i will get some peace! blooming soccer fans! i have no idea what makes soccer so captivating. it really does dey logic. my borther - who's a Man Utd fan - didn't eat until the match was finally over. i guess he realized that whatever happened, the players still don't realize his existence. and that's my problem with Nigerian supporters of foreign teams. don't they realize that for the most part, the players don't know they exist, nor care if they are cheered on by some people they'll never meet? and yet the madness continues. men who are never alive as far as their families are concerned suddenly come alive when there's a meet between "their team" and "the enemy". ridiculous. that's why i insist that football is demonic. the Bank PHB ad about La Liga really puts it in context.

Blogged with the Flock Browser

Java vs Ruby? Ruby wins...

if for no other reason than the fact that there are much fewer books to confuse you. and here's why

Blogged with the Flock Browser

Monday, May 19, 2008

Creating a Windows service in .NET

much as i would like to, this isn't a real tutorial about creating a Windows service in .NET. there are lots of excellent tutorials in that regard. this is just to highlight some problems i had recently when i created a service. usually, the service sits in the background, waiting for "something to happen", maybe a client connects, a timeout goes off, and all that. my service is a time-based service that performs certain actions when a timer goes off.

to get my service doing some "real" work, i used the System.Timers.Timer class, which has the Elapsed event, which calls a callback method when the timer fires. here's a caveat: the callback for the Elapsed event suppresses all exceptions in .Net 2.0 and lower (i can't categorically say that the behaviour isn't the same in higher versions). forget processing unexpected exceptions in your callback - they'll get supressed. and you may end up like me: after putting in a full day at work, spending the night there, and putting in another full day, you're at the client's and the service runs but doesn't do anything.

my fix? in my callback, i start a separate thread. the thread takes responsibility for doing the processing that was in my callback, and i once again can see what exceptions occur in my processing. by the way, design your tables so none of your fields are allowed the NULL value in .Net. use sensible defaults instead of NULL, becaue you never know when you'll get a System.DBNull object that isn't automatically converted to null. later, then!

Edit: when services run - irrespective of where the executable actually is - the working directory is always C:\WINDOWS\System32. that can be a problem if you access to files residing in the same location as the executable, especially if you don't know where the service executable is (if you think that is strange, think again: you - or someone else - could create an installer that allows the user customize the location of the install). if you need to get access to the executable's location, you can do:

string basepath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
System.IO.Path.GetDirectoryName(basepath);
this will retrieve the path in a format such as file:///C:/..., so you'll need to trim off the beginning of the string returned.

i used SharpDevelop for creating my service, as creating the service from scratch (Visual C# 2008 Express) or tusing an application template (Visual Studio 2008) gave me problems when trying to install the service using installutil. SharpDevelop integrates with FxCop, a code analysis tool developed by Microsoft. running FxCop on my executable showed me some things i'd never really noticed before, such as using string.IsNullOrEmpty(variable) instead of if ((variable == string.Empty) || (variable == null)) to check if a string was empty or null.

Blogged with the Flock Browser

Fun and nonsense in Freenode's ##csharp

from time to time i hang out in ##csharp on Freenode. the guys there are great (mostly) - they've helped me out with quite a number of problems. and it's just plain fun to hang out with them. here's a excerpt from the conversation there this morning:

[11:39] <scruz> i don't ever want to be you - link managed and unmanaged code
[11:40] *** Mathius joined
[11:40] * scruz shivers at the thought of interop_madness' pain
[11:40] <Mathius> hi
[11:40] <interop_madness> you you don't want to be on the same planet as me
[11:40] <scruz> what planet is that?
[11:41] <+smellyhippy> Mathius: ello
[11:41] *** SDragon quit (Read error: 104 (Connection reset by peer))
[11:41] *** SDr joined
[11:41] <interop_madness> dunno, but it certainly has no sun shining
[11:41] <scruz> yello Mathius
[11:41] <Mathius> O_o
[11:41] <Mathius> hey hey
[11:41] <scruz> from Earth import Sun
[11:42] <Mathius> >_>
[11:42] <scruz> Sun.shine()
[11:42] <Mathius> public sealed class Earth : INoLight
[11:42] *** gregzx joined
[11:42] <scruz> lol
[11:42] <pandzilla> haha
[11:43] <Mathius> CSC Error: You cannot look for light in an instance of type 'Earth'.

Blogged with the Flock Browser

Sunday, May 18, 2008

Multiple IEs on your WinXP machine

if you're like me, you like to use the latest software. that includes browsers. unfortunately, the latest browsers are a really bad idea if you're into web design - specifically standards-based design. because you need to workaround features not supported in older browsers. i made a really big mistake when designing a client's website - i designed it using the latest Firefox, Opera and IE7. it was okay in those browsers. imagine my shock when i viewed it in IE6 and it was fugly. and that was after deployment.

to avoid my mistake, you want to design using IE6. unfortunately, even i don't encourage you to use IE6. so how can you get IE6 for testing your web pages? well, i originally thought of using VirtualBox to create a WinXP disc image on my system - but that's a waste of about 2GB just to test web sites. so i went googling. and i came up with Multiple IEs. at first i thought it was just snake oil, especially when i ran IE6 and went to Help -> About. however, when i tested it, i got IE6's signature crappy rendering - and it was different from IE7's, so i'm quite happy advertising it. thanks to the guys over at TredoSoft!

Cleaning out my C:(loset)

i'm not sure why, but more and more, software installations tend to assume you have just one partition on your machine - that, or you absolutely don't mind it getting filled up with things you don't really know.

lost? let me explain: i'm in the habit of breaking up my harddisk into partitions. i used to leave 5GB on C: for OS files, taking into account that some software will always install some things on C: even if you tell the setup wizard to install on some other partition. that was enough about 4 years back. i upped it to 7.5GB sometime back, and finally to 10GB. now it seems even that isn't enough. i installed Visual Studio 2008 recently, and my free space on C: has plummeted down to less than 2.5GB - without enabling hibernate. i dread what would happen if i installed Adobe products - at least another 400MB would go should i install CS3 Design. yet i have over 14 GB lying fallow on a partition i reserved for installing application software. even with CCleaner installed, i can't free up any space. granted, a heavier-duty application can help with that, but i don't have much hope in that direction.

darn shame what they do to my disk space.

Friday, May 16, 2008

What happened to the Adobe-Yahoo collabo?

i just downloaded Shockwave Player 11 to install on my computer (yes, right now it seems nobody uses Shockwave anymore - Flash seems to have effectively killed Director) and i was surprised - no, shocked - to find the installer prompted me to install the Google toolbar. Google? what happened to Yahoo-integrated search in Adobe Reader? must be because i'm so tired...i'll check again when i do not feel so sleepy ;)

Blogged with the Flock Browser

Thursday, May 15, 2008

long time!

haven't been here in a long time. stuff's happening, and sometimes it seems hazy, but i'm sure i'll win. things are looking up now, so i'll be here more often. later!