gaurish

 

Ruby 1.9 has a cool hash syntax which is quite similar to javascript, so the following hash

hash = {:symbol => "value"}

can be written as

hash = {symbol: "value"}

now, what if both key & values are symbols, in ruby 1.8 & before you would write

:pick => :any

but now, this could be written in short form as

pick: :any

And this both new & old syntax for hash are supported in ruby 1.9, you can use whatever syntax you are comfortable the most but it helps to know both forms of syntax specially when reading the code that other might have written. personally, I like the new one — fewer characters to type :P

 

PS: this new has syntax is applicable only if the key is a :symbol. In case when key is not a symbol. you have to still stick with old array syntax(=>)

 

Heroku is the popular ruby on rails PAAS hosting platform. With the earlier versions, if you were hosting a rails web application on it. All apps deployed to Heroku used to automatically compress pages they serve, by passing through Nginx’s gzip filter on the way out. But with their newest Cedar Stack, things have changed

In Cedar, the HTTP requests terminates directly at your app server & no longer goes through a proxy server(Nginx), hence there can’t be automatic gzip compression. More information about this can be found in HTTP routing dev center article So we have to manage gzip compression on our own. fortunately, this is trivial as adding just one line to your config. basically, you will need to use Rack::Deflater & make sure that it get loaded before ActionDispatch::Static. The simplest way to enable gzip compression in Rails 3.2 is by adding “use Rack::Deflater” in config.ru file.

After the change, this how your config.ru file should look like:

# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment',  __FILE__)
use Rack::Deflater
run Improvingoutcomes::Application

I spending sometime gather information about this. So Hope this post help you save some time.

 

I shared my views on GPS technology by a journalist. As everyone knows, I love to share my views on technology. Like little did I knew that it would end up in Major National Newspaper of Country – Times of India.

This article made into Times of India on march 11 2012, I got little delayed in posting it here. Not something big but it feels nice to read your name in paper upon waking up :)

you read the article Online at:
How your phone can be your compass – Times of India

 

Caching helps to cut the load on server & increase server speed. Hence, Drupal comes with caching build-in at various levels. there will be situations where,  you may want to disable *ALL* caching like I was doing some module development and without clearing out the caches the changes were not visible. So, I had to disable caches.  Incase, you too want to disable Caching for say for development – here below

  1. Go to Site Configuration -> Performance:
    • Set the following options, and click Save configuration:
      • Caching mode: Disabled
      • Minimum cache lifetime: none
      • Page compression: Disabled
      • Block cache: Disabled
      • Optimize CSS files: Disabled
      • Optimize JavaScript files: Disabled
    • Click Clear cached data.
  2. Go to Site building -> Views -> Tools:
    • Check Disable views data caching and click Save configuration.
    • Click Clear Views’ cache.
  3. Install the Devel module, and go to Site Configuration -> Devel settings:
    • Check Rebuild the theme registry on every page load and click Save configuration.
  4. Add the following to your .module file to disable menu caching

function hook_init(){
   //FIXME: remove before going into production
   menu_rebuild();
}

With this, now ALL caching in drupal will disabled. Enjoy quicker development & don’t forget to undo these changes once your site goes into production!

 
Drupal Module Development

I am building a new site & I have chosen to create that with Drupal. as you may know, Drupal is a popular open-source, free to use Content Management System but you may not know that Drupal also has a powerful framework which can be used to be built just about anything. This is done by creating custom modules. Now, as with other things the hardest part is to get started. so this post will deal on how to get started with Drupal development

Learning Drupal Module Development

In Drupal, Whatever you want to do. There is a modules for that! If not, then you have to write a custom module that accomplishes that.

Introduction

A Drupal module mainly consists of bunch of loosely coupled functions  written in procedural style(you can use some OO features though). some might ask why it’s not object-oriented, that because Drupal was written in the time when PHP didn’t support OOP & lacked namespaces. Sadly, that hasn’t changed even when even now PHP does support full OOP including namespaces(PHP 5.3+).
However, it is commendable on Drupal’s part that it managed to work around PHP’s limitations by adopting design such architecture.

Hook System

Hook System is nothing but a glorified naming convention adopted universally by Drupal Community. Infact, entire architecture of Drupal is build around this naming convention. According to this naming convention, the module name you choose must be unique, and should be all lowercase, containing only letters & numbers, always starting with a letter. Within the module itself, all functions must then be prefixed with the module filename, followed by an underscore, and then action(called hook in drupal land) in following way

function ModuleName_action()

here,
ModuleName = name of your module
action = pre-defined hook

These hooks are pre-defined and are called automatically by Drupal when specific event occurs, so you just have to define an appropriate hook/action & Drupal will take care of the rest. for example, your module was called “mymodule” & want to add some help text. so, in custom module, you will add function named “mymodule_help“.

/**
* This Implements hook_help()
*/
function mymodule_help($path, $arg){
    if($path=='admin/structure'){
        return t('This is the sample help text');
    }
}

This function gets called automatically by Drupal when a page is displayed, then we check if $path is admin/structure, if yes. then the help text is displayed. Simple!

So, this was a 20,000 feet view to Drupal Modules. I hope now you have at least basic idea about Drupal’s hook system, how it works,why its build that way & how go about writing custom modules. To end, I am leaving you with some resources that would guide you further on this journey of writing Drupal modules.

Good Luck & have fun Drupalizing the web!

 

Many JavaScript programmers treat eval & new Function construct as the same. But new Function & eval are NOT the same. the important difference is:-

  • eval() works within the current execution scope and can affect local variables.
  • new Function() cannot affect local variables because the code runs in a separate scope

So both are evil & should only be used when there is no other way but as you may notice new Function is slightly less evil

© 2011 Gaurish Sharma Live Suffusion theme by Sayontan Sinha