add snippets

Recursively add files to ClearCase

Tagged recursive, script, clearcase, add, ruby  Languages ruby

This script adds all files in the current directory to ClearCase.

Save the following script as add_recursively.rb in the directory you want to add to ClearCase:

%x{cleartool ls -view_only -r -s . > view_private_files.txt}

lines ='view_private_files.txt').readlines.collect{|line| %Q{"#{line.chomp}"} }

# Work around command line length limit in Windows
while lines.size > 0
  %x{cleardlg /addtosrc #{lines.slice!(0..100).join(' ')}}

Next open a command line window and execute the script:

cd clearcase_vob
ruby add_recursively.rb

ClearCase sucks, use Mercurial or git instead...

How to add and remove validation rules (jQuery validate plugin)

Tagged remove, jquery, plugin, validation, add  Languages javascript

This snippet shows how to change the jQuery validation plugin's validation rules dynamically:

$(document).ready(function() { 
  // Setup the default validation rules
  var validator = $('form').validate({ 
    rules: { 
      username: { 
        required: true, 
        minlength: 2

  // Drop-down selection changes validation rules
  $('#account-type').change(function () {
    // Get the jQuery validation plugin's settings
    var settings = $('form').validate().settings;

    // Modify validation settings
    $.extend(true, settings, {
       rules: {
           // Add validation of year
           "year": {
               required: true,
               min: 2010,
               max: 2020,
               number: true
           // Remove validation of username
           "username": {} 

You can also use CSS classes to achieve the same:

$('#channel-title').addClass("{required:true,messages:{required:'required field'}}")
$('#channel-title').removeClass("{required:true,messages:{required:'required field'}}")