CSS/HTML : ID or CLASS attribute? Which one to use when ?

A simple, yet powerful classification of the DOM elements can done using the element attributes ID and CLASS. By giving a CLASS attribute, we can refer/select MULTIPLE elements with the same class. Example:

<div class="myclassA">first content</div>
<div class="myclassA">second content</div>
<div class="myclassA">third content</div>

Once we have such layout, we can access all the div's easily, some of them would be: 1. In the .CSS file as :

.myclassA{
 color : red;
}

2. If ur using JQuery:

$(".myclassA").css("color", "blue");

By giving a ID attribute, we can refer/select EXACTLY one element with that ID. Example:

<div id="myDivIdA">first content&lt;/div>
<div id="myDivIdB">second content</div>

Once we have such layout, we can access EXACTLY one div easily, some of them would be: 1. In the .CSS file as :

#myDivIdA{
 color : red;
}

2. If ur using JQuery:

$("#myDivIdB").css("color", "blue");

NOTE: 
When accessing, CLASS attributes are prefixed with '.'
and ID attributes are prefixed with '#'

Elements can have both CLASS and ID attributes. So you can can even more flexibility.

jQuery: $("#elementId") != document.getElementById("elementId")

The most natural assumption is that  $ in jQuery is equivalent to document.getElementById. But it is NOT !! Took me a while to figure it out.

$("#elementId")!=document.getElementById("elementId")

$("#elementId") method gives a jQuery object that is always an array of Elements.

So to the get the real DOM element you have to use $("#myElementId")[0] or the more readable $("#myElementId").get(0)

Gmail Adds Drag-and-Drop Attachment Uploads and Attach Calendar Invitation

A very cool feature from google GMAIL !
Now you can drag and drop attachments and insert invitations directly in 'compose mail'.
Simply drag single/multiple files into the 'Compose Mail' window !

ShiftIt: Windows 7 Aero Snap for Your Mac !

Wondered if you wanted to get the smart resizing introduced in Windows 7 on your Mac ?

Well Try this http://code.google.com/p/shiftit/
ShiftIt is a free download for Mac OS X only.

Theres another software Called Cinch http://www.irradiatedsoftware.com/cinch/ ,but you need to pay for it !

Easy and smart way to install Eclipse plugins

You can install the eclipse plugin in 2 standard ways:
1. Download the plugin from web and place both the "features" and "plugins" folder's contents into your eclipse installation features and plugins folders respectively.
2. You can install through "Update Manager"() by giving the update URL.

Note: The disadvantage with the above approaches are, all the installed plugins will work for only your eclipse installation. If your eclipse crashes, you will ended up with installing all the plugins that you did. And moreover every team member has to do the same every time they install Eclipse.

There is one other way that you can install Eclipse plugin and get rid of above disadvantage. And its pretty easy I believe. Please follow the steps below:

1. Create a folder structure like below anywhere in your shared folder. (The folder name must be 'eclipse' with subfolders matching exactly 'features' and 'plugins')







2. Download the plugins from web and place features folder contents and plugin folder contents into respective folders that you have created above.

3. Create a new folder called "links" in your eclipse home installation like below and create a new plain text file called plugins.link (Technically, it can be called anything.link). In it put the line path=...\My Shared Folder (i.e. path value should be the eclipse folder path that you have created above.)



4. Finally launch the eclipse. It will notices the links/plugin.link file and load any plugins from that path as well.

Advantage: With this approach you will be decoupling external plugins with your eclipse installation so that way you can have your team share the same plugins every time they change their project preferences or eclipse installation.




Click a button using Javascript

Here is how you click a button in using javascript.


<script type="text/javascript" >

  document.getElementById("mybutton").click;

</script>


This specifically helps when ur using AJAX helpers in cakePHP and you want to submit the AJAX form using javascript. In this case u will not be able to use either .submit or .onClick

Change permissions for ALL the files/subfolders within a directory

Change permissions for all the files/subfolders within a directory Option to use is 'do it recursively', the -R option . Example in unix based machines

chmod 777 -R directoryname

OffiSync integrates between MS Office on the desktop and Google Apps on the cloud

"OffiSync integrates between MS Office on the desktop and Google Apps on the cloud, allowing users to work together on the same files and see changes in real time, access document from any computer and share files with people in a secure way."


CakePHP : DbAcl::allow() - Invalid node [CORE\cake\libs\controller\components\acl.php, line 325]

DbAcl::allow() - Invalid node [CORE\cake\libs\controller\components\acl.php, line 325]
If your following the “Simple Acl Controlled Application” , then you might see the above error message.
A simple fix is, in the function 'initDB()' replace
 $this->Acl->allow($group, 'controllers');
 with
 $this->Acl->allow(array( 'model' => 'Group', 'foreign_key' => 1), 'controllers');

So the total function would look like the following:


function initDB() {
 $group =&amp; $this-&gt;User-&gt;Group;
//Allow admins to everything
 $this-&gt;Acl-&gt;allow(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 1), 'controllers');
 //allow managers to posts and widgets
 $this-&gt;Acl-&gt;deny(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 2), 'controllers');
 $this-&gt;Acl-&gt;allow(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 2), 'controllers/Posts');
 $this-&gt;Acl-&gt;allow(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 2), 'controllers/Widgets');

//allow users to only add and edit on posts and widgets
 $this-&gt;Acl-&gt;deny(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 3), 'controllers');
 $this-&gt;Acl-&gt;allow(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 3), 'controllers/Posts/add');
 $this-&gt;Acl-&gt;allow(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 3), 'controllers/Posts/edit');
 $this-&gt;Acl-&gt;allow(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 3), 'controllers/Widgets/add');
 $this-&gt;Acl-&gt;allow(array( 'model' =&gt; 'Group', 'foreign_key' =&gt; 3), 'controllers/Widgets/edit');
}

Beautiful BING images as your Desktop Wallpaper !!

Theres a BING downloader http://bing.codeplex.com/releases/ , helps to download the current BING image and sets as your Desktop Wallpaper.

This app requires .NET Framework for working. Download and install the latest .NET framework as well.

jQuery : Execute particular code after the animation effect has completed

If you want to execute particular code after the animation has completed, try the following:


$("#myDivToFade").fadeOut(function() {
 // This code will be executed
 // after the animation is complete
});

Associating CakePHP files ( *.ctp or *.thtml ) with Eclipse

To set up your version of Eclipse to read either file type( *.ctp or *.thtml), follow these steps

  • Go to Window > Preferences > General > Content types
  • In the content types window navigate the tree to text > PHP content type
  • Click add
  • Enter *.ctp or *.thtml depending on what version of CakePHP you use. It might be best to add both - just in case.
  • Now navigate to Editors > File Associations
  • Enter *.ctp or *.thtml depending on what version of CakePHP you use.
  • Under "Associated Editors:", select the PHP Editor and click Default.


    Fixing Warning (2): Cannot modify header information - headers already sent by (output started at...

    How to fix the following error in PHP
    Warning (2): Cannot modify header information - headers already sent by (output started at  ... 

    This is also referred to as "whitespace problem".
    The error message typically looks something like
    Warning (2): Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/test-cake/app/models/post.php:1) [CORE/cake/libs/controller/controller.php, line 644]

    Steps to resolve the issue:
    1) Find the header() statement that is causing the problem. The error must be at or before this line.

    2) Identify statements that could send output to the user before this header statement. Example 'echo ' statements. You cannot have these 'echo' statements before header() statement.

    3) Make sure there is no white space before the php start and end tags.
    Also at the beginning of the file a blank line before the <?php start tag may look innocent, when processed by PHP, it will turn into an echo statement printing out a blank line. This is a common culprit.

    Running Tomcat manager when you start the server through eclipse

    You can't open the tomcat manager by hitting http://localhost:8080 URL when you start the server through eclipse. This is because the eclipse by default creates the tomcat server instance separate from your installation and uses its custom config files for starting and stopping the tomcat. And also it deploys the webapps under workspace temporary folders (Ex: .metadata\.plugins\org.eclipse.wst.server.core\tmp0). The solutions is to change the default behavior and

    You can switch off this default behavior by fallowing th
    e below steps so that you can login to tomcat manager/admin by hitting the http://localhost:8080 URL.
    1. Add a new server by right clicking in the servers perspective of your eclipse.
    2. Double click on the server added in the above step and change both the server and deploy paths like below.
    Server Path : {Tomcat home}
    Deploy Path : {Tomcat home}/webapps













    3. Start the server.

    Note: When you do this, your custom config files will be overwritten in your Tomcat installation each time the tomcat server is started within eclipse. And the manipulation you do through manager/admin will be lost next time the Tomcat server is started in Eclipse.

    Python contextlib for Timing Python code

    If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...