Cool JS Shadow Library

light_and_shadow.png Light & Shadow is a ProtoType-based library for creating great looking drop shadows easily. Check out the HTML I used to generate the example image and see it yourself that it’s not rocket science!

All you have to do is to set up a light source with a few parameters (distance, intensity, size etc.) and add the class ‘shadowThrowing’ to your elements which should… well, throw shadows :-). I won’t go into details here, you can find the explanation and other details on the Light & Shadow project page.

(Found via Gedankenkonserve – thanks Bernhard ;-))

Today Midnight

I have been always uncertain about the exact expression denoting today midnight (or any day midnight, for that matter). Is 00:00 on e.g. April 24th the midnight between 23rd and 24th or 24th and 25th? If I want something to happen at today midnight, is that today’s date at 00:00? (for the impatient: no, it isn’t :-)).

Chronic to the rescue! (If you don’t know chronic, be sure to check it out – it’s a great natural language date/time parser). All I had to do is:

>> Chronic.parse('today midnight')
=> Fri Apr 25 00:00:00 +0200 2008

so actually it turns out it’s _tomorrow’s_ date at 00:00.

I couldn’t find time zone support though (I am not saying it’s not there, just that I couldn’t find it by looking at the API) – so what if I want to meet someone in Madrid today midnight? Why, I install the tzinfo gem and ask Ruby!

>> TzinfoTimezone["Madrid"].utc_to_local(Chronic.parse('today midnight').getutc)
=> Fri Apr 25 00:00:00 UTC 2008

Random Links from the Web, 21-04-2008

Live Validation – Easy Client-side Javascript Validation

live_validation.pngUpdate: Sergio, the author of the livevalidation rails plugin updated the plugin so you can disregard the finale of the article (validates_confirmation_of is working, as well as the newest version of livevalidation, 1.3 is used in the plugin – so no additional tweaking is needed, install and validate away ;-))

Surely I am not the only one who was a ‘bit nervous’ (that was a mild euphemism) when his carefully entered data disappeared after submitting a form to the server. Nowadays web applications are doing better than that – valid data is saved and only the problematic fields are pointed out.

Of course even that feels so 1990’s now. A contemporary (ehm… web 2.0?) web application is expected to validate the form on the client side already (WARNING! That doesn’t mean at all you shouldn’t validate on the server side though – client side validation is for the good guys but you should still look out for the script kiddies et al), pointing out the errors on the fly so there is no need to come back and change/edit those fields after submitting a form.

My library of choice is livevalidation, which has a Rails companion too – if you are using Rails form helpers and standard validation on your models, you don’t have to touch anything just install livevalidation (=drop it to your javascripts folder, it’s a single .js file). w00t!

The only major shortcoming (from my POV) of the Rails plugin is that validates_confirmation_of is not implemented. However, it’s easy to add it via standard javascript:

<input id="user_password" name="user[password]" size="30" type="password" />
<input id="user_password_confirmation" name="user[password_confirmation]" size="30"> 
<script type="text/javascript">
var validate = new LiveValidation('user_password_confirmation');
validate.add( Validate.Confirmation, { match: 'user_password' } );
</script>

That’s it!

One more note: the Rails plugin contains version 1.2 but there is a newer version, 1.3 so be sure to replace it.

Caffeine and Insomnia – Don’t Let Your Mac Fall Asleep

caffeine.png Long-time Mac users probably have different solutions for this problem, but as a newbie, the screen going dim after a certain period of time – without an intuitive way to switch this off – drove me crazy! I wanted to enjoy my slideshow, video, presentation, reading something etc. and suddenly it all went dark. Arggghhh.

So I was delighted when I found Caffeine, a super-light program sitting in your menu bar that prevents your Mac from going to sleep/starting screen savers.

Note that Caffeine doesn’t help if you close the lid – if you want your Mac to stay awake in this case, InsomniaX is your thing – it disables the sleep when closing the lid so you can listen to music/control your Mac with the remote etc.

Random Links from the Web, 10-04-2008

  • RubyFlow – Peter Cooper (of RubyInside fame) created “RubyInside’s sister site” – RubyFlow. Hope it takes off!
  • Thinking Sphinx Reborn – I thought a phoenix is the creature with the reborn ability – though that doesn’t mean a sphinx can’t do that! btw. “Sphinx is a very fast search engine that indexes data and provides flexible ways of searching it.”
  • Rails vs Merb – “The conclusion is simple, I recommended that my client go with Merb”.
  • RubyAMP – powerful looking Ruby TextMate bundle.

Compiling Firefox 3 beta 5 on OS X (with JSSH support)

Since I bought my Mac, Safari has been my primary browser of choice. I have been using Firefox sporadically too – you can’t do serious web development without FireBug! Safari is light, zippy and renders wonderfully looking OS X look’n’feel pages – however with the arrival of Firefox 3 I am really pondering to ditch it in favor of FF (still no OS X look in there, tho’ ;-)). Firefox 3 beta 5 is just phenomenal – fast, powerful, and it has all the stuff I am missing from Safari (FireBug, del.icio.us toolbar, DOM Inspector, ton of other extensions) so I am really thinking that I will remain a Safari user on my iPhone only.

However, FF3 is missing some functionality I am depending on – most notably jssh support – DOM inspector was removed too, but can be installed as an add-on, and since beta 4 FireBug is working, so no major hurdles there. However, jssh, as usually was a harder nut to crack.

Fortunately Angrez, FireWatir‘s author pointed me to the right direction – which was in this case compiling Firefox 3 with jssh support! Here’s how:

Sit back, enjoy your coffee and in a few minutes you’ll have your own, new hot FF build with jssh support!

By the way, FireWatir 1.1 hit the streets just today! Grab it and let the testing commence!

Downloading a File Behind http-basic-auth

There is a great number of possibilities to do this in Ruby (just to mention a few: standard net/http, curb, mechanize, rio etc.). I have chosen a semi-standard way (=no need to learn new syntax, but definitely simpler than net/http): open-uri.

require 'open-uri'

open('target.file','w') {|f| f.write open("my.url.com/source.file", :http_basic_authentication=>['ueser', 'pass']) }

I am using Ruby for more than 2 years already but it’s succinctness still keeps me amazed!

Random Links from the Web, 04-04-2008

EuRuKo 2008 – Favorite Quotes

EuRuKo 2008
Quite a few blogs covered EuRuKo talks (for example here, here, here or here) so I am not going to do an n+1-th writeup. Instead I collected a few quotes I found interesting and/or funny. Without further ado, here we go:

Matz: Ruby – Past, Present and Future (Keynote)

  • Chad Fowler wrote a book ‘My Job Went to India’ – and yesterday my luggage went to Oslo!
  • Ruby was a hobby that came from not having a job after end of Japan’s bubble economy
  • I consider myself as no great programmer!
  • Then we have this nasty snake language here… (sampling through different languages starting from COBOL)
  • Python people love to be organized and have one true way. Ruby people don’t care.
  • (after going through a ton of different languages and finally arriving at Ruby) Ruby is not perfect either… but it’s close!
  • We will need to keep Ruby alive when Rails will be gone… Hopefully Ruby will be around in 15 years, but Rails… hmm…khm… never mind.
  • 10 years ago – Ruby? What’s That? Language? See This Cool Java!
  • 5 years ago – Ruby? I’ve Heard of It. But I haven’t Used It YET.
  • 2 years ago – Ruby! I Know! It’s for Rails, Right?

Koichi: Merging YARV is not a goal but a start

  • (Running around in a t-shirt ‘No Ruby No Life’) My version: No Ruby no Job!
  • 1st slide: [some completely different slide than his real topic title] – this is just a joke, the presentation is not on this
  • I don’t speak English so I wrote down everything on the slides… unfortunately most of the slides are in Japanese! (LOL)
  • Please ask questions in Japanese/C/Ruby! … or use slow/short English
  • I have a lot of slides (hm, like 50) of different optimization techniques but it’s just too much so I won’t show you here 😉
  • My PhD thesis is in Japanese (Efficient implementation of Ruby VM), so please learn Japanese if you’d like to read it 🙂
  • NT means not Windows NT but Native Thread
  • Ruby thread and native thread: (shows a brutally complicated slide, fully in Japanese) and I would like to point out this part (clicks a button, and a red frame appears around a portion of fully Japanese text)
  • This is complex so I skip it (after the 10th incomprehensible slide)
  • I can’t program in Ruby!
  • Come to Japan/Enter my Lab (please teach me English) – Unfortunately I can’t employ you because there is not enough money, so please bring your own $
  • (response to a question about YARV’s memory need:) Yes, YARV also needs memory to start the VM! (considers the question answered. When asked for further details:) How much? hmm… you need to measure yourself 😉

Charlie Nutter, Tom Enebo: JRuby – Ready for Action

  • Java != a dirty word!
  • Did you see this demo already? No? Good. Everybody has seen this 100 times in the US so they are really sick of it!
  • See? new is on the right side of the class name!
  • I love swing (after listing 9342923 looooong fuctions of the Button class)
  • this would take 6-7 lines of Java (after adding a listener to a button in 1 lines of Ruby syntax)
  • This is the weirdest error I have ever seen during a demo! I guess Mac OS X is not ready for this stuff yet (after not being able to kill off a process which slowed down his machine)
  • Kill that bird!!!! (after thunderbird jumping around for like 5 minutes after OSX bootup)
  • ColdFusion is not a fine example for anything (Charlie, after a guy proposing CouldFusion as an example of… I don’t remember what but it doesn’t matter)

Disclaimer: Please take the above with a grain of salt – it might seem based on the above sentences (which were taken out of context and possibly squeezed/lost in translation) that Koichi’s topic was to pursue people to learn Japanese (not true, his talk was very interesting and deep) or Matz was making fun of/mocking Python (not true, he was just joking all the time) etc. If you have some more, drop me a comment!

My EuRuKo 2008 Photos

EuRuKo 2008 is over… I have had a really great time, both as an organizer and an attendee, and can’t wait for next year’s conference!

Until that gets sorted out (currently Spain (Madrid) and Poland (Warsaw vs Krakow) are competing) here are some photos we made with Marianna… They were usually made in a hurry and/or dark so don’t expect too much (I guess I should invest in a better objective and flash :-))

You can check out all the (correctly tagged) EuRuKo 2008 photos here.

Please post your photos to flickr or whatever service you are using, and leave a comment here with the address… Cheers!