SZC’s Agglomeration

{an agglomeration of laconic notes in relation to anything that sparks my interest}

Archive for July, 2008

cheat sheets

Posted by Stefan Camilleri on {2008.July.30}

/** All developers are polyglots, but we are not gods */

That’s when cheat sheets come in handy {

My Portuguese friend João posted this very handy link on his blog, and I thought it worthy of sharing

Cheat Sheets

Cheat Sheets

}

Posted in dev, shortcuts | Tagged: , | 2 Comments »

date validation regular expression

Posted by Stefan Camilleri on {2008.July.30}

/** Here is some handy regex to validate a date using british locale (dd/mm/yy or dd/mm/yyyy) */

Note, this allows / \ . or – as delimiters {

^(?:(?:0?[1-9])|(?:[1-2]\d)|(?:3[0-1]))[-.\\/](?:(?:0?[1-9])|(?:1[0-2]))[-.\\/](?:(?:\d{3}[1-9])|(?:\d{2}[1-9]\d)|(?:\d[1-9]\d{2})|(?:[1-9]\d{3})|(?:\d{2}))$

}

p.s. this regex has now been superseded with an improved version here

Posted in dev, regex | Tagged: | 2 Comments »

force browser to download a file

Posted by Stefan Camilleri on {2008.July.30}

/** A common problem which I have come across multiple times in the past is that of forcing a browser (any browser) to download a file rather than try to open it. */

There’s a myriad of solutions out there on the web discussing this very issue, and I never gave much thought to it until yesterday. {

I came across an excrept of code at my client which was trying to send a csv file to the client (i.e. the client pc), yet the browser (all flavours) insisted on trying to render it, rather than download it.

The solution turned out to be particularly simple; something we all learnt how to do very well when we wanted some sweets as kids… i.e. LIE (to the browser this time)

All you have to do is set the content type to application/binary and the browser will simply not bother trying to do anything with it.

Here’s the magic expression in Java, yet of course this also applies to any other lingo (and if you have a problem, ask me, tell me your language, and if I can, I’ll show you how).

response.setContentType("application/binary");

NOTE: IE works slightly different from other browsers (what's new?), in that if you cancel the download, it will close the socket throwing an exception on the server. You of course will need to cater for this.

}

Posted in dev, java | Tagged: | 1 Comment »

ridiculous()

Posted by Stefan Camilleri on {2008.July.16}

/** When I just realise that no matter what, I can never cease to be amazed */

I’m working on some code right now, fixing up some system changes, and I have come across lots of crap, but this one tops it all IMHO {

400 lines of undocumented code in one method!

Go figure… and here I was thinking I was a crappy programmer when I was 20 since I used to commonly put around 50 to a 100 lines of code in my methods.

}

Oh well… just one of those nuisances you know.

Posted in aesthetics, architecture, dev | Leave a Comment »

posting code in wordpress

Posted by Stefan Camilleri on {2008.July.13}

/** Cruising the sea of blogs by the coding monkeys here on WordPress, I cannot fail to realise that there is a good bunch of people out there who have not yet discovered how to use the wordpress way of pasting code into their blogs */

So, in the hope that some will actually read this and take advantage of it, here goes {

Well, it is no rocket science really.  All you need to do is to enclose your code in a set of

put your code here

where ‘lingo’ can be any one of {

  • cpp
  • csharp
  • css
  • delphi
  • html
  • java
  • jscript
  • php
  • python
  • ruby
  • sql
  • vb
  • xml

}

}

Hope that helps :)

<h2>Happy blogging</h2>

Posted in aesthetics, blog | 2 Comments »

programmingFonts()

Posted by Stefan Camilleri on {2008.July.12}

/** So, the never-ending debate as to which is the best typeface to use for programming has also started brewing in my brain. */

I found tons of posts on-line debating what was the best font, and for one, I always felt that Microsoft’s Consolas was by far the best programming font around (and technically it is almost, but not quite, entirely like the best coding font around).

To summarize what sparks the requirement of such a font, it basically boils down to {

  1. Programmers like fonts that look good at SMALL point sizes.  Not because we are masochists (well some of us probably are), but because we want to see as much code as possible on one screen.  Which would also explain the phenomenon of why all programmers push their graphics cards to the highest resolutions possible (oh yes, and it also looks gorgeous on a hi-def lcd).
  2. We spend hours on end reading funny words that make sense solely to us and to lexical analyzers, so we need the font to be VERY legible, and to distinguish clearly among similar characters like 0,O,o, ilL1… among others (oh yes, and the myth is true, most developers, after a full day of code, go home to see…more…code!)
  3. We use words like ’sexy’, ‘perfect’ and ‘elegant’ to describe an algorithm, so we should also be able to use such terms to describe the font we use to write such algorithms in.

}

So, to cut it short, here are the contestants {

  1. Proggy Tiny 10pt

    Proggy Tiny 10pt

  2. ProFont 7pt

    ProFont 7pt

  3. Envy Code R 7pt

    Envy Code R 7pt

  4. Droid Sans Mono 7pt

    Droid Sans Mono 7pt

  5. Courier New 8pt

    Courier New 8pt

  6. Consolas 8pt

    Consolas 8pt

  7. Bit Stream Vera Sans Mono 8pt

    Bit Stream Vera Sans Mono 8pt

  8. Anonymous 7pt

}

And that is it really.  I have concluded that for now, after testing all these fonts, Consolas remains the one of choice for me.  ProFont was terribly inviting, yet the boldness of the font is just way too heavy in comparison to the normal formatting.

Now I’m just hoping to find a font which looks as good as Consolas does in 8pt, but at 7pt, since 8 is just a bit too big for my likes.

Posted in aesthetics | Tagged: | 12 Comments »

reBirth()

Posted by Stefan Camilleri on {2008.July.12}

/** This is the re-birth of my blog.  Supposedly this would be the fifth or sixth time that I am creating a blog, so I am just curious as to how long this one will last! */

Reasons I’ve had a blog in the past are as follows {

  1. Livejournal.com :: the reason for this blog was simply because my then girlfriend had one and I wanted to experience what she felt when writing in her blog.  This didn’t work and I ended up spamming my own blog with random quizzes and stuff :: Return -> False
  2. Greatestjournal.com :: also was born during my ‘blogging-girlfriend’ stint.  I wanted to feel like I was ‘contributing’ to her blogging life, so I recommended that everyone (all friends etc…) move to this blog.  Everyone – to my surprise – DID actually move to this blog, but I soon lost interest and I ended up spamming my own blog with random quizzes and stuff :: Return -> False
  3. Blogger.com :: I don’t totally recall why I even had this blog.  It was probably more of a ‘tracking news’ blog than anything private about my life; as were supposedly the previous two.  Likewise, a few months in, and I ended up spamming my own blog with random quizzes and stuff :: Return -> False
  4. WordPress.com :: this was possibly my most successful blog to date.  I persistently tracked news and hand-picked interesting stuff.  It was so successful, that once a journalist friend of mine even got prompted by one of my posts and published an article based on it via the public news.  Then again, this blog was born whilst I was studying at university, which would account for why it lasted the longest.  In the end, I ended up spamming my own blog with random quizzes and stuff :: Return -> False
  5. Livejournal.com :: back to livejournal.com it was.  This time, I wanted an anonymous blog, where I would track things of interest that I learnt during the day and any targets that I had set for myself.  Unfortunately, my ex figured out who I was based on my style of writing and general interests.  Wow, kudos to her for knowing me so well!  Ultimately though, I almost ended up spamming my own blog with random quizzes and stuff (but I didn’t :Þ) :: Return -> False
  6. This would be the sixth attempt.  Hopefully this one will last.  Over here I plan to track all my private projects and am keeping this blog specifically for development purposes.  Eventually I’ll create my own blog and transfer everything to it, I have some cool ideas (at least I think they’re cool), though until now this will have to suffice :: Return -> Variant

}

…and well that is it!

Posted in ramblings | Tagged: | Leave a Comment »