Hiding elements when javascript is enabled

I was cleaning up some javascript notifications for a website and came across this common question: what is the best way for elements to be visible when a user does not have javascript enabled but hidden when they do (often to be revealed by javascript? I cam across an article titled How To Hide And …

Continue reading ‘Hiding elements when javascript is enabled’ »

Ruby Arrays and Hashes and Days of the Week.

I was playing around with different ways to represent the days of the week and their index from 0 to 6 as hashes and arrays.  Here’s what I cam up with: irb(main):001:0> require ‘date’ => true irb(main):002:0> Date::DAYNAMES => [“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”] irb(main):003:0> Date::DAYNAMES.enum_with_index.to_a => [[“Sunday”, 0], [“Monday”, 1], [“Tuesday”, 2], …

Continue reading ‘Ruby Arrays and Hashes and Days of the Week.’ »

Blocking Spam with Javascript

So I am trying the WP-SpamFree Anti-Spam plugin for WordPress.  It uses javascript to prevent spam.  I’m really hesitant because I prefer websites which do not require javascipt for their basic functionality.  Perhaps I will use another spam blocker.  Or perhaps I will just resign myself to accepting that functional javascript is requirement from browsing …

Continue reading ‘Blocking Spam with Javascript’ »

2 ways to use LIKE queries with wildcards safely in Rails finders

It is important to sanitize variables that may come from users to prevent SQL injection attacks.  Rails makes this easy by default: Author.find(:all, :conditions=>[‘first_name = ?’, first_name] However this will not work: Author.find(:all, :conditions=>[‘first_name LIKE “%?%”‘, first_name] This will work but is  insecure: Author.find(:all, :conditions=>”first_name LIKE ‘%#{first_name}%'” Solution 1: Author.find(:all, :conditions=>[‘first_name LIKE ?’, “%#{first_name}%”] Solution …

Continue reading ‘2 ways to use LIKE queries with wildcards safely in Rails finders’ »