Categories
Development Geek food General Internet/Links

Dotnet Robots

After Eduard posted about Robocode, I remembered that there was a .Net “equivalent” (equivalent in concept, not in completeness) that I’d seen a while ago called IBots.  I did a quick search and also found DotBots which I got to via AIForge which has a list of over 1000 games where you get to program the logic of the “actors”.

They all kinda suck in comparisson to Robocode, but at least you won’t have to learn another language to build a bot. πŸ™‚

Categories
Development Geek food General

Feeling better…

I read Craig Paterson‘s post “I feel so much better…“, and checked out the link to “YOU ARE NOT INADEQUATE” by secretgeek.  Its really cool, and something I think a lot of us need reminding of.  I’m glad someone came out and just said it. πŸ™‚

Categories
.Net Stuff Development General

SA Developer has a new site!!!

I just saw the news that SA Developer .Net has a new look website, so I checked it out and its awesome! πŸ™‚

They’re using components from Telligent Systems’ Community Server Forums, which is really cool.  Check it out.

Categories
.Net Stuff Development Geek food General

Why .Net Rocks!

(And no, I’m not talking about the radio show with Carl and Rory – and for those who don’t know what radio show, its called “.Net rocks“)


For the last week or so I’ve been delving into C++ code… with some great joy (like having to read “Writing Secure Code (2nd Ed)“) and many many many trials.


If you’re still using C++, change to C# (assuming you have a choice to move).  I’d swap in a heartbeat based simply on the amount of “plumbing” work it would save me, but then I don’t have a choice here – I’m writing code to make some Extended stored procedures.


But seriously, remembering all the new’ed variables you’ve made so that you can delete them, and checking your arrays and pointers, and handles, and all that work to do simple operations like joining two strings, or using collections, or doing file IO, or doing pretty much anything becomes a nightmare when compared to the simplicity of C#.  That being said, there’s something geekishly cool about programming in C++ – maybe its the “thrill” of handling such an unwieldy weapon of mass destruction and actually managing to hit the pinprick of a target you’re aiming at without blowing off your own foot in the process.


But regardless of the geek thrill factor involved I’ll be happy when this part of our project is over and I can move back to C#… πŸ™‚

Categories
Development General Internet/Links

Pet peeves being addressed

A while ago I posted about one of my Pet Peeves (Microsoft announces CD’s that you can order online, but only after you go online do you find out that you can’t get them shipped to South Africa)… Shortly after that the South African version of the MSDN Flash they announced that you could order the CD’s that I was looking for, and they’d ship them to South Africa for a small (around R35?) fee which was great.


With XP SP2, I was wondering how the heck I would get my home PC updated since I’ve just moved and I don’t have a phone line in the new place yet (and it will probably take over a month to get one installed)… On Friday I was browsing Microsoft South Africa’s site and I noticed a press release entitled “Windows XP Service Pack 2: Fact Sheet” which kinda hides the exciting content a bits, which say “Microsoft South Africa would like to encourage users to order a free copy of the Windows XP SP2 CD from its local call centre (0860 2255 67) and from mid-September CDs can be collected from Makro; Incredible Connection; Game; Dion and CNA – free of charge”!


This morning I saw that Matt Hausmann blogged about it, so I thought I should too. πŸ™‚


And once I’ve put my PC back together I’ll be giving Microsoft a call.

Categories
.Net Stuff Development Geek food

Q: When is 1 not equal to 1?

A: When you’re using .Net and boxed value types.


“What?? No, you’re wrong.  Its not possible – you must be using the framework incorrectly.”


That’s what I would have said, but I’m not so sure after having to fix our little problem at work this morning.


We have a function that takes 2 object parameters:
public bool myFunction(object left, object right))
Which tries a whole bunch of things and if non of them works, it returns:
left.Equals(right);


The problem is as follows:


Int32 i32 = 1;
Int64 i64 = 1;
bool result = i32 == i64;
System.Diagnostics.Debug.WriteLine(result.ToString());
// outputs TRUE – expected
object o32 = i32;
object o64 = i64;
result = o32 == o64;
System.Diagnostics.Debug.WriteLine(result.ToString());
// outputs FALSE – expected
// This is expected since it would do a reference comparison BUT
result = i32.Equals(i64);
System.Diagnostics.Debug.WriteLine(result.ToString());
// outputs FALSE – not expected
// It does it because i64’s type is not the same as i32’s type
// The same goes for result = i64.Equals(i32).
// And also for result = o32.Equals(o64);

Now the question remains – how on earth do I get this code to work?  Currently I’ve written my own IsEqualTo(object left, object right) function which finds out which of the numeric types each object is and casts the left and right parameters to the most suitable types before it does the comparrison so that it works correctly… I’ll upload a ZIP with a sample solution in it that demonstrates the solution, but if you know of a better way to write the code (keeping in mind that it needs to be generic enough to handle any type variables that are passed in), please let me know…

Categories
.Net Stuff Development Geek food

Portals

Well, I’ve been busy over the past few days playing with DotNetNuke.  I downloaded v2.0.4 on Friday, installed it on my work pc, spent about 30 minutes copying and pasting stuff from my company’s website into DNN and wowed my boss with what it could do.  On Monday they released v2.1.1, so I got that down and installed it on my website.

Now I just need to learn how to make a custom component(desktop module), and how to skin it.  I HATE “making pretty”.  Ok, maybe HATE is a strong word… My graphical abilities are definately not my strongest skill, and for me to spend 5 hours making something that a more skilled person could do better in 5 minutes seems pointless.  I know there are some sites out there with “premade” skins, and skins for sale… I went to one last night (DNNSkins) but that’s not only running DNN v1.0.10, but it also seemed to have no skins in its store. (its like its database is blank)… I tried looking at SnowCovered, but its UI kinda sucks, so I haven’t really found much.  DIYWebsite (which seems to be an alternative front for Salaro) has a much nicer UI – you actually get to see samples of the site quite quickly so instead of choosing between 5 descriptions, you can choose between 5 looks.  I’d love to use TemplateMonster (cool UI and plenty of skins), but they don’t do DNN templates. πŸ™

Anyway, I’m gonna keep on looking for sites with cool skins – if anyone knows of any, let me know.

Categories
Development

Cool SQL code, with an international flaire

In a previous blog, I mentioned that a friend in the UK had a problem with getting some SQL code to do what he wanted.  Over MSN, he sent me a script to build the 3 tables involved, an “ERD” type diagram, and a description of the problem.


It went like this… He had 3 tables: Events, Users and Bookings.


Events has an EventID, and Name
Users has a UserID, a Name, and a Gender (bit field – 0 = female, 1=male)
Bookings has an EventID, and a UserID


He needed to be able to, in one statement, get a count of how many males, and how many females were attending all of the events.  He’d tried to use “Group By” and “Having” to get the right information, but the solution I gave him was as follows:


SELECT
Events.EventID,
SUM(CASE Users.Gender WHEN 0 THEN 0 WHEN 1 THEN 1 END) AS ‘NumMales’,
SUM(CASE Users.Gender WHEN 0 THEN 1 WHEN 1 THEN 0 END) AS ‘NumFemales’
FROM Bookings
LEFT JOIN Users ON Bookings.UserID = Users.UserID
INNER JOIN Events ON Bookings.EventID = Events.EventID
GROUP BY Events.EventID


The basic idea is as follows. Join all the tables, group by the event id, and then aggregate the fields we need to add.  The twist is to select the “Gender” column twice, so we can use one to count males and the other to count females.  Now if we just “SUM” each of the columns, it will show us how many men are in attendance in both columns… so we need to do a sneaky swap around on the Gender column that’s totalling the number of females so that females are represented by 1, and males by 0… that way when we do a “SUM” of each column, we will get to correct values.  Thank’s to the “CASE” statement we can do this easily. 


I know that I didn’t have to use the CASE statement for the count of the number of males, but I either had to do a CASE, a CAST or a CONVERT because BIT fields can’t be summed. So I just stuck with a CASE.  It was a “random” choice, had nothing to do with performance, and was mainly done because I just it simply involved me doing a copy and paste from the line below.


Anyway, the point of this – remember the useful CASE statement in SQL.  Its not often spoken about and probably not often used, but its very useful indeed.  If you have another way of solving this, let me know… πŸ™‚

Categories
.Net Stuff Development Geek food Humour

Code access security…

Jim Blizzard makes some interesting comments about code access security in .Net relating it to the “superbowl half time event ‘scandal'” where Justin Timberlake & Janet Jackson did a duet, but part way through the event Janet’s topΒ “malfunctioned” (i.e. thats aparently how she described it… but in every day terms her top “fell” off)

Anyway, Jim was making a comment on how in life when people want to do something wrong, they’re not going to ask permission before they do it.Β  In the same way, in computers a malicious program isn’t going to ask you if it can please erase your entire hard drive before it does it.Β  But with the .Net framework’s code access security, the programs are only allowed to do what they’re explicitly given permissions to do.Β  So you don’t have to worry (unless you give all code full trust on your machine)

Check out his blog entryΒ “Breasts and code access security…” for more info.

Categories
Development Humour

Buying Nothing

A while ago I had a complaint with an SMS service offered by IDWS… I sent myself a sample sms, and for some reason, som proxy server between me and them kept hitting the “form submission page” with my cookies, but with no querystring, or form data.


The net effect of this was that their system charged me for 83 odd blank sms’s were sent to nobody (it stopped “sending” them when my account ran out of money).  When I say “nobody”, I don’t mean “some random person”.  I mean, literallly they were sent to nobody… The same as if I had just not typed anything into the “To” field.


Anyway, they charged me for them (because aparently they get charged for it), and claimed that it was my fault for not enabling javascript on my browser – their only means of validation before sending any message is a Javascript function, which naturally the Proxy server was not really bothered with executing.  This is just really bad coding.


What made it worse was that they didn’t seem to care too much about fixing this “bug”, and they insisted on charging me for all 83 sms’s… And they had the gall to think that I’d keep using their service.  After a good number of e-mails explaining to them the stupidity of their coding practices, and why I would not be using their service again unless they fixed it (because who knows when next this will happen, and what if I had 2000 sms’s available in my account that time?) they gave me back 1/2 my sms’s and promised to see if they could fix it in the next realease of their software, and that they would e-mail me when it was released.  (That was 2 months ago and I’ve still had no e-mail)


Anyway… on the thought of “buying nothing”, I saw a blog entitled “Apple selling DRM’ed silence at $0.99 a pop”, on BoingBoing.  Its a bit different and far more excusable… but basically the gist of it is that when an artist happens to have a silent track on their album, you still pay $0.99 for it… and they still ensure that you can only listen to your silence subject to the DRM requirements.  So not only are you paying for silence, but you can’t even share it with anyone else… πŸ™‚ 


Its a small side effect of artists doing odd things on their albums, an unfortunate one, but fairly un-avoidable, and quite understandable.  I’d love to see what their response to it is…