Results tagged “Programming” from Kazza the Blank One

So there's this system at work that's been annoying me for literally *years*.  I've begged various people to fix it over the years, but to no avail.  So this week I thought screw it, I'll just do it myself.  I started to write my own script, but very quickly realised that was a silly idea, when chances are there'd be plenty of scripts out there on the internet to do what I wanted to do.  And sure enough there were.  So downloaded one, hacked it a bit, and by this afternoon had something that will work.  It's possibly not the most elegant solution, but it's certainly better than what we have, and that's got to be a win!

SQL

| | Comments (0)
I was actually online to have a look at an old script and bit of SQL code which stopped working when I transferred my hosting off Godzilla a couple of years ago.  I took a while to remember the sql password and figure out what I needed to change to access MySQL on the new host.  Finally got the address book scripts to work, but the birthday script wasn't ordering correctly - it was ordering by item key, not what I'd said to order by.  Figured it out tonight - it had some extra ' characters that it didn't need.

Check this out:

  $SQL="select id, firstname, lastname, birthday, month(birthday), monthname(birthday), year(birthday), dayofmonth(birthday), ceiling((TO_DAYS(NOW())-TO_DAYS(birthday))/365.25) AS agenext from addressbook where ceiling((TO_DAYS(NOW())-TO_DAYS(birthday))/365.25) is not null order by month(birthday), dayofmonth(birthday);";

So it pulls out a bunch of data from a database including the person's name and their birthday day/month/year.  Then it figures out the age they are turning next by looking at the date now and the date of their birthday and dividing by the number of days in the year.  The .25 on the end is important, as MySQL uses this for years, and the calculations could be out by a day on the day of the person's birthday if it's wrong.  Then it orders it chronologically.  Perl is used to put it all together into a neat table which has the person, their birthday, and their age next birthday in a table, ordered correctly, on the fly.  

I'm sure there's probably better, less hacky ways of doing it, but I was pretty impressed with it at the time (feel free to put down how you'd do it in the comments :) )

VBScript

| | Comments (2)
Since I probably should have been home today I didn't feel as guilty about having a play with some vbscript.  That, and I didn't feel up to doing any *real* work! ;)

Not that I was very successful.  I've never learnt any vbscript, so I didn't really come close to achieving what I wanted to.  Not sure how much time I can get away with playing with it for before I revert back to some sort of hacky dos batch file.
Kazza's "Boring Life Of a Geek" aka BLOG

IT geek, originally from Sydney, moved to Canberra in 2007. Married to "the sweetie", aka Stu. Prolific photographer, Lego junkie and tropical fish keeper.

Kazza the Blank One home