Saturday, 21 February 2009

JavaScript Collapsible Links

Coding in JavaScript used to be like loving a naughty child. OK, it’s not strongly typed, the debugging is terrible and the cross browser issues are pretty unpleasant but look at his cheeky face. Awwww – he’s so cute running round and setting fire to dogs and he makes my web pages look all clever and interactive.

Over the last few years the naughty JavaScript child has grown up a bit. The The prototype project has swept away a the cross browser unpleasantness, extended the DOM and made the entire thing a lot more like a proper grown up coding language. So in the spirit of playing with an adult I whipped up a collapsible link control using the prototype library.

I’ve published a demo of the collapsible links and the images are a plus and a minus and can be grabbed from the above link. The code uses divs to construct the tree

The code uses divs to construct the tree. Css is used to show and hide the div panels and swap the plus and minus images. Prototype enabled JavaScript is used to wire it together

<html>
<head>
<script src="scripts/prototype.js"></script>
<script>
function setupGrid()
{
arrLinks = $$('#JsGrid a');

for(var i=0;i<arrLinks.length;i++)
{
arrLinks[i].observe('click', togglePanel);
}
}

function togglePanel()
{
var clickedLink = Event.element(event);
var panel = clickedLink.up().next();

if(clickedLink.className == "linkOpen")
{
clickedLink.className = "linkClose"
}
else
{
clickedLink.className = "linkOpen"
}

if(panel.className == "panelClose")
{
panel.className = "panelOpen"
}
else
{
panel.className = "panelClose"
}

}
</script>
<style type="text/css" >
.panelOpen
{
padding: 0px 0px 0px 20px;
display:block;
}

.panelClose
{
padding: 0px 0px 0px 20px;
display:none;
}

.linkOpen
{
padding: 0px 0px 0px 20px;
background:url('images/minus.gif') no-repeat center left;
}

.linkClose
{
padding: 0px 0px 0px 20px;
background:url('images/plus.gif') no-repeat center left;
}

</style>
</head>
<body onload="setupGrid();">
<div id="JsGrid">
<div><a href="#" class="linkOpen">Test 1</a></div>
<div class="panelOpen" >Test content 1</div>
<div><a href="#" class="linkOpen">Test 2</a></div>
<div class="panelOpen">Test content 2</div>
<div><a href="#" class="linkOpen">Test 3</a></div>
<div class="panelOpen">Test content 3</div>
<div><a href="#" class="linkOpen">Test 4</a></div>
<div class="panelOpen">Test content 4</div>
</div>
</body>
</html>

The setupGrid method wires the togglePanel method to the click event of each link. The $$('#JsGrid a'); is prototype cleverness to pick up all the links under the JsGrid element. The togglePanel function does what it says on the tin – shows and hides the panel giving the collapsible tree structure its collapsibility. The only prototype sprinkle is clickedLink.up().next(); which shows off the prototype DOM navigation rather than the old document.getElementById unpleasantness.

All in all I was surprised how little code it took and how readable the code was. Mmmm, tasty and virtually calorie free.

Friday, 20 February 2009

70-431 Hints and Tips

I passed 70-431 (TS: Microsoft SQL Server 2005 - Implementation and Maintenance) a while ago and it’s shamefully taken months to get round to blogging the tips. As ever, the general tips are read a book, do some sample exams, fill the gaps from MSDN, do the exam and good luck. More specific tips are

The Book
As I’ve said before the Microsoft Press books are of an extremely variable quality. In this case the book is pretty good and covers the right stuff. You’ll still need to plug the gaps from MSDN.

The Simulation
This is the big tip. Unlike every other MS exam I’ve done this one has a simulation of some typical database tasks at the end. The simulation mocks up the Database Management console and asks you to click around to complete the different tasks. Make sure you can do the simple stuff such as
  1. Perform a full backup.
  2. Perform a differential backup.
  3. Perform a transaction log backup
  4. Restore a database
  5. Create a login and user for a database
  6. Access and run a profile

This list isn’t exhaustive but is the type of things that could be on the sim.

The Links
Below are the links that I used to supplement the Microsoft books. Some of these are pretty dry reading and again this isn’t exhaustive.

Installing and Configuring SQL Server 2005
Returning the login name associated with a security identification number (SID)
Ownership Chains

Maintaining Databases
Backup T-SQL
DBCC CHECKDB
Creating full DB backup
RESTORE T-SQL
Dedicated Administrator Connection

Creating and Implementing Database Objects
Creating Certificates
Rollup T-SQL
Xml Indexes
Auto Mode for Xml Queries
User Defined Types T-SQL
Indexed Views

Monitoring and Troubleshooting SQL Server Performance
Sp_addmessage

Supporting Data Consumers
SQL Server Browser Service
Server Broker Contract
Service Broker Endpoints
Service Broker Endpoints with Kerebos
Endpoint authentication

And of course best of luck if you’re taking the exam.

Wednesday, 18 February 2009

Geek Pin-ups

In the course of general office chit-chat it was asked “who was your favourite childhood pin-up?”. Being a bit of a geek I struggled for any kind of answers and muttered something vague and non-committal. As a mini-child geek I didn’t do pin ups of pop-stars and other such normal, healthy juvenile obsessions. I was too busy sticking paperclips in the back of my Commodore 64 just to see what it would do.

So I got to thinking - what would be the pin-ups of geeks. What should adorn the grey walls of our work pods?

ZX Spectrum
It’s every geek’s first love. Squishy keys, the size of a postage stamp and graphics that give migraines. Hours wasted with our Jet Set Willys. If you’ve every wondered why the average geek doesn’t have a girlfriend until they’re 25 then this probably goes a long way to explaining why.


Space Invaders
Big as a refrigerator, monochrome graphics and 10p a go to you, young fella my lad. If you have just floated your new Web 2.0 company for millions on the NASDAQ then you’ll have a whole room full of these kind of machines. For everyone else, it’s a poster on your cubicle wall and some warm, fuzzy memories of summers spent in darkened rooms playing this. Sunlight, pah, that’s not for geeks.



Mandelbrot Set
It’s like maths but it’s beautiful. It’s numbers with colours. It’s algebra with swirls. Pin it up and then spend hours explaining to colleagues the bizarre recursive mathematics that generates it. Everyone loves a maths whiz (possibly).

C-3P0
The golden translator droid of Star Wars surely deserves a place on every geek wall. The more rebellious geek may opt for the more edgy R2-D2 but I think everyone will agree that hours spend staring at C-3P0 in wonder are hours well spent.



Blog Hero
What geek wall would be complete without a picture of an IT blog hero doing his thing. Mmmmmm – a step to far maybe.

Friday, 13 February 2009

Web Development Tool Freebies

Even though I work day to day creating software I find it very hard to pay for it. I know that I should but when it comes to entering the credit card details I have an almost physical reaction then have to lie down for a while in a darkened room and sip some weak tea. It could be because I was born in Yorkshire (in the UK) and Yorkshire folk although fine and upstanding people are not known for their free spending ways. In any case I gravitate time and time again to freebies are here are my favourites for web development.

IE Developer Tool Bar
http://www.microsoft.com/downloadS/details.aspx?familyid=E59C3964-672D-4511-BB3E-2D5E1DB91038&displaylang=en
I’ve never subscribed to the Microsoft is evil school of thought so with that in mind this is one of my favourite freebies. Lots of extensions to ease the web development process. Particular favourites of mine include changing the screen size without messing found with the control bar and isolating html elements by click. And the price – well no money need change hands but Microsoft will obviously pump pro-Vista propaganda directly into your skull as soon as you press the download link. Aww – those guys!!!

NotePad++
http://notepad-plus.sourceforge.net/uk/site.htm
A must for all amateur developers. Lots of colouring coding for your code in formats from Ada to YAML with some macro stuff and a decent find and replace thrown in. What’s more it doesn’t take 4 days to install and 3 hours to load up like some other IDEs that will remain nameless (Visual Studio).

Regulator
http://sourceforge.net/projects/regulator/
Like most developers I’ve an ambivalent attitude to regular expressions. They are super useful but once you’re doing anything more complicated than finding a word then they might as well be written in hieroglyphics. So some kind of tool is essential. This one is a bit buggy on the last release I snaffled but still does the job. Lots of handy prompts and highlighting of your latest regex attempt. I think out of all of the recommends this would be the one that I would most consider spending some money on to upgrade to a more reliable product (probably Regexbuddy). Still it works well enough and it’s nought pounds and nought pence to buy. Great.

Filezilla
http://filezilla-project.org/
So once you’ve finished created you’re latest website of sheer brilliance then you’ll be wanting to get it straight up on the Internet so that all and sundry can marvel at your genius. No problem – Filezilla is the FTP client for you. Nice intuitive interface and does exact what’s needed - gets your files onto the server lucky enough to host your work of art. I was using SmartFTP for a while for this but it needed patch after patch and then churlishly they suddenly wanted to be paid for it. Can you believe it – developers wanting to be paid. I was quite frankly appalled.

Paint.Net
http://www.getpaint.net/download.html
This is something I thought I’d never see – a great image manipulation package for nothing at all. Wow! I’m sure that if I was a graphic designer and divided my time between snowboarding, wearing garish T-shirts and refusing to use PCs because Macs are sooo much better – then I might turn my nose up at this. But I’m thrilled if I can resize and image and do a fill with a gradient so this one is for me. My favourite out of all the recommends and the one that I would be most likely to donate money to if I wasn’t so mean.

Monday, 9 February 2009

Trivalent Logic

My two favourite posts on DailyWFT is the Brilliant Paula Bean and What is Truth. Whereas the Paula Bean post is just, well, brilliant the What is Truth post I’ve started to feel is a tad harsh.

The post describes the most bizarre enum – a custom Boolean with three values – True, False and FileNotFound. Hahahahaha – how dumb. However the Infragistics Excel component I’ve been using recently also has a three part Boolean

ExcelDefaultableBoolean.True
ExcelDefaultableBoolean.False
ExcelDefaultableBoolean.Default

Mmmm – less dumb. And it doesn’t take much to dream up circumstances that you may need more parts to your Boolean

True
False
Default
Unknown
Not Specified

We seem to expect that because computers work with 1s and 0s we should too and any attempt to extend Boolean logic is just wrong. However, while jamming file not found into a bool may well be a little odd, I’ll certainly be liberating my Booleans this week from the tryanny of binary logic. 10 part Booleans anyone. You know you want to.