Archive for February, 2010
MySQL Workbench 5.2.16 Beta 6 has been released
by specialj on Feb.20, 2010, under Uncategorized
2 Comments more...Building SOAP service in Rails
by specialj on Feb.20, 2010, under Ruby On Rails
Looks like I may have to do it. I got started with some reading:
Hiding elements when javascript is enabled
by specialj on Feb.17, 2010, under Web Development
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 Show Initial Content, Depending On Whether JavaScript Support Is Available which was great reading on the subject. There were 3 methods that stood out in the article and comments.
- Use a javascript file sourced in the head section to include a css stylesheet file specifically for javascript enabled browsers. The downsides of this method are 2 extra requests on the initial visit and needing to keep all javascript css in a separate css file.
- A method detailed in The best way to hide content by JavaScript is to attach a class to the html element. This is a violation of the spec and therefore may not be cross browser compatible but seems to be used by a number of people without problem.
- By adding a 1 line script immediately after the body tag that sets the body class to “js” or something else indicating the presence of javascript. The chief objection to this is that setting the body class could trigger a re-rendering.
At the moment I’m trying option 3. My reasoning is that it is the most simple to implement and maintain. The concern that it could cause a re-rendering seems minimal to me. Presumably since the parser proceeds linearly through the html than this change should occur before much else and thus not lead to any visible flicker. However, real world testing may be the only way to discern if any of these methods are superior to the others.
Ruby Arrays and Hashes and Days of the Week.
by specialj on Feb.16, 2010, under Ruby On Rails
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], ["Wednesday", 3], ["Thursday", 4], ["Friday", 5], ["Saturday", 6]]
irb(main):004:0> Date::DAYNAMES.enum_with_index.to_a.map{|a| a.reverse}
=> [[0, "Sunday"], [1, "Monday"], [2, "Tuesday"], [3, "Wednesday"], [4, "Thursday"], [5, "Friday"], [6, "Saturday"]]
irb(main):005:0> Hash[*Date::DAYNAMES.enum_with_index.to_a.flatten]
=> {"Friday"=>5, "Wednesday"=>3, "Saturday"=>6, "Tuesday"=>2, "Monday"=>1, "Sunday"=>0, "Thursday"=>4}
irb(main):006:0> Hash[*Date::DAYNAMES.enum_with_index.to_a.flatten].invert
=> {5=>"Friday", 0=>"Sunday", 6=>"Saturday", 1=>"Monday", 2=>"Tuesday", 3=>"Wednesday", 4=>"Thursday"}
Blocking Spam with Javascript
by specialj on Feb.16, 2010, under Sysadmin
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 the web.
Update: I’m going to try the NoSpamNX plugin instead. It does not require cookies or javascript. We’ll see how it goes.
2 ways to use LIKE queries with wildcards safely in Rails finders
by specialj on Feb.11, 2010, under Ruby On Rails
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 2:
Author.find(:all, :conditions=>['first_name LIKE CONCAT("%", ?, "%")', first_name]