Tuesday, August 5, 2008

Ant and yuicompressor

http://www.julienlecomte.net/blog/2007/09/16/
read this on more information on how to configure your ant script to work with yuicompressor

Friday, August 1, 2008

Compressed webpages... Smarty and JS

http://joseph.randomnetworks.com/archives/2006/07/13/compressed-javascript/

I was trying to figure out how to get my apache server to serve gziped css and js files... after a few hours of wrestling, i gave up and googled :) And the above link did the trick. Actually, a comment at that blog. I used the .htaccess method.

Here is a nifty plugin for Smarty to serve gziped tpl files
http://smarty.incutio.com/?page=GZipPlugin

Wednesday, June 25, 2008

Drag and drop between lists

http://www.gregphoto.net/sortable/advanced/

Friday, April 25, 2008

AIR 1984 SC 667

You can find the judgment passed in this case at this location - http://www.judis.nic.in/supremecourt/qrydisp.aspx?filename=9599
I personally find the judgment search tool of the Indian courts very very cumbersome.

I tried looking for the judgment in the case of AIR 1973 AP 17 and invariably the page showed - "No matching results"... WTF? Maybe there is a secret trick to finding the hidden pot of gold :)

ASCII to Hex in Verilog

I was playing around with Verilog today, it was one of those whimsical things that one does to take ones mind off writing a dissertation :) I tried it for the first time, and I like it, it seems fairly easy to pick up too. Here is a function I wrote to convert an ascii number to its ascii-hexadecimal equivalent -

/**

* converts an 8-bit wide parameter to a 16-bit wide ascii-hexadecimal equivalent
* @return 16-bit ascii-hexadecimal version of input
**/
function [15:0] a2h(i) //the function returns a 16-bit value
input [7:0] i; //input argument 8-bit wide
reg [4:0] temp;
reg [7:0] h_b, l_b;
begin
temp = i[7:4];
h_b = decode(temp); //decode higher nibble
temp = i[3:0];
l_b = decode(temp); //decode lower nibble
a2h = {h_b, l_b}; //concatenate the higher nibble result and lower nibble result
end
endfunction

/**
* Helper function to convert from nibble to ASCII representation
*/
function [7:0] decode(d_i) //output is byte wide
input [3:0] d_i; //input is nibble wide
reg [7:0] ret_value;
reg [2:0] lo_ip;
begin //this is the conversion logic... will not explain this :P
ret_value = 8'd00;
ret_value[2:0] = d_i[2:0];
if(d_i == 4'h9){
ret_value[3] = 1b'1;
}
if(d_i > 4'h9){
ret_value[7:4] = 4h'4;
}else{
ret_value[7:4] = 4h'3;
}
decode = ret_value;
end
endfunction

"a2h" accepts an input 8-bits wide and converts it to a 16-bit ascii representation of that input.

i.e. 'b' would get converted to '62'
and '6' would get converted to '36'.

Thursday, April 24, 2008

jQuery + prototype in drupal is a go!

jQuery.js and prototype.js, both define $() as a function. This was the reason for the error in the previous blog entry. Didn't figure this out myself, found it in this blog. The good news is that it is taken care of in Drupal 7, and I am using D6 with 1.12.2.1 of jQuery, so I had to use the following workaround -

1) include
var $jq = jQuery.noConflict();
at the beginning of all the javascript files I needed in the misc (and some module) directory (directories).

2) replace every instance of $( with $jq(

This took me to a different problem - I started getting these errors in the files using prototype
"$ is not a function"

I checked the order in which drupal has included the javascript files. prototype.js was defined after jQuery.js
However, according to using jQuery with other libraries, "This will revert $ back to its original library. ", which to me meant, that prototype.js should be declared before jquery.js

This rearrangement is not possible using any combination of drupal_add_js(...), so you must make this change in the template file - page.tpl.php, and if you have enabled multiple templates, then muhuhaha... god onlee to be helping you machi! yeah... change each one of them. Include the prototype script in this fashion

And guess what? It works!! The unfortunate effect of this whole shebang is that prototype.js will be included with each page that gets downloaded if caching is disabled. Which is a big waste of bandwidth and will certainly slow down the site. Perhaps, a better way of handling it would be to include prototype.js on a flag based mechanism like this
Perhaps, but for now, I think I'll just stick to the non-flag mechanism - which is nothing more than a hack. But then we will not have to do this come drupal 7, so waiting eagerly for that one!

Wednesday, April 23, 2008

A javascript mess!

I was trying to use prototype with drupal and was fairly successful until I used collapsible forms and prototype together!

Drupal uses tableheader.js for the collapsible functionality - I think, and fails with an error on

var headerClone = $(this).clone(true).insertBefore(this.parentNode).wrap('
').parent().css({...

in the same file. The error is, "$(this).clone is not a function".

Now you see prototype defines clone() on an object itself, so this is definitely a problem. Its a little too late for me to up and running, so I'll look to solve this puzzle sometime tomorrow.

Friday, April 18, 2008

Creating a module admin settings page in Drupal 6

I am new to Drupal, newer to coding Drupal and I was attempting to code a new module. Recipie for beginners block :) Anyways, among other features the module was supposed to have a settings page where certain settings, pertaining to that module, could be configured by the site administrator.

The help files at Drupal were proving to be fairly non-trivial and unwieldy, so I started looking outside the drupal ecosystem for some valuable tips. And very conveniently I stumbled across this tutorial from IBM. However, it has been written for Drupal 4.6 indicating that I could expect to do a fair bit of porting.

The very first "hook" that the example extends is hook_settings().

"The settings hook provides a way to add attributes to the module that can be controlled by the administrator and can be used when displaying this module."
Just what I was looking for! But hang on a sec, it doesn't even exist in Drupal 6. Anyways, lets us see how those folks have done it

Listing 1: hook_settings as extended by IBM's tutorial
function announcement_settings() {
$form = array();
$form['announcement_block_max_list_count'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of block announcements'),
'#default_value' => variable_get('announcement_block_max_list_count', 3),
'#description' => t('The maximum number of items listed in the announcement block'),
'#required' => FALSE,
'#weight' => 0
);
return $form;
}
Fairly easy, define and array and return the admin settings in that array object and thats it, all done. Simple, but as far as I am concerned - useless! As mentioned earlier, drupal 6 doesn't even recoginze this hook, so I had to ask my self, how can I do this in drupal 6? But, before that one may ask the question, why was this function deprecated? The answer may lie in it being interpreted as being too restrictive - i.e. only form objects are allowed, what if I wanted some elaborate content at the admin settings page. Of course, the necessity of such elaborate content will always be in doubt. Nevertheless, this the lemon we've been handed... anyways, coming back to that settings page. How do we get a settings page in Drupal 6.x?

The answer lies in extending hook_menu(), as shown below -
function announcement_menu() {
$items = array();
$items['admin/settings/announcement'] = array(
'title' => t('Maximum number of block announcements'),
'description' => t('The maximum number of items listed in the announcement block'),
'page callback' => 'drupal_get_form',
'page arguments' => array('announcement_settings_form'),
'access callback' => 'user_access',
'access arguments' => array('administer announcement'),
'type' => MENU_NORMAL_ITEM
);
return $items;
}

function announcement_settings_form($form_state) {
$form = array();
$form['uploaded_block_max_list_count'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of block announcements'),
'#default_value' => variable_get('announcement_block_max_list_count', 3),
'#description' => t('The maximum number of items listed in the announcement block'),
'#required' => FALSE,
'#weight' => 0
);
return system_settings_form($form);
}
In drupal 4.6 the _settings() hook would mimic the url http:///admin/settings/. When coding with drupal 6.x, to maintain backward compatibility, a new menu item is added such that the menu system will look for a menu item at the path "admin/settings/", in our case it is "admin/settings/announcement". This is done by defining an item element as
$items['admin/settings/announcement'] = array(...)
The page callback is used to return the page which needs to be displayed for the url defined by the menu item. In our case we use the "drupal_get_form" as the callback. The "drupal_get_form" function is described as
"Retrieves a form from a constructor function, or from the cache if the form was built in a previous page-load. The form is then passesed on for processing, after and rendered for display if necessary.

$form_id The unique string identifying the desired form. If a function with that name exists, it is called to build the form array..."
Thus to reproduce the same effect as 4.6, we pass the "announcement_settings_form" function, which is very similar to the 4.6 "announcement_settings" hook implementation, as an argument to the page callback.

Access callback and access parameters are used to define the permission levels for this particular url.

And that is how it is all done!