CSS trick (CSS RESET BY ERIC MEYER)

CSS RESET

This piece of CSS code resets all the browser default styles preventing any browser inconsistencies in your CSS styles.

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: ”;
content: none;
}
/* remember to define focus styles! */
:focus {
outline: 0;
}
/* remember to highlight inserts somehow! */
ins {
text-decoration: none;
}
del {
text-decoration: line-through;
}
/* tables still need ‘cellspacing=”0″‘ in the markup */
table {
border-collapse: collapse;
border-spacing: 0;
}

html, body, div, span, applet, object, iframe,h1, h2, h3, h4, h5, h6, p, blockquote, pre,a, abbr, acronym, address, big, cite, code,del, dfn, em, font, img, ins, kbd, q, s, samp,small, strike, strong, sub, sup, tt, var,b, u, i, center,dl, dt, dd, ol, ul, li,fieldset, form, label, legend,table, caption, tbody, tfoot, thead, tr, th, td {margin: 0;padding: 0;border: 0;outline: 0;font-size: 100%;vertical-align: baseline;background: transparent;}body {line-height: 1;}ol, ul {list-style: none;}blockquote, q {quotes: none;}blockquote:before, blockquote:after,q:before, q:after {content: ”;content: none;}
/* remember to define focus styles! */:focus {outline: 0;}
/* remember to highlight inserts somehow! */ins {text-decoration: none;}del {text-decoration: line-through;}
/* tables still need ‘cellspacing=”0″‘ in the markup */table {border-collapse: collapse;border-spacing: 0;}

Permanent link to this article: https://blog.openshell.in/2011/01/css-trick-css-reset-by-eric-meyer/

CSS trick (Two classes together)

Two classes together

Usually attributes are assigned just one class, but this doesn’t mean that that’s all you’re allowed. In reality, you can assign as many classes as you like! For example:

<p class="text side"></p>

Using these two classes together (separated by a space, not with a comma) means that the paragraph calls up the rules assigned to both text and side. If any rules overlap between the two classes then the class which is below the other in the CSS document will take precedence.

Permanent link to this article: https://blog.openshell.in/2011/01/css-trick-two-classes-together/

CSS trick ( CSS box model hack alternative)

CSS box model hack alternative

The box model hack is used to fix a rendering problem in pre-IE 6 browsers on PC, where by the border and padding are included in the width of an element, as opposed to added on. For example, when specifying the dimensions of a container you might use the following CSS rule:


#box
{
width: 100px;
border: 5px;
padding: 20px
}

This CSS rule would be applied to:

<div id="box">...</div>

This means that the total width of the box is 150px (100px width + two 5px borders + two 20px paddings) in all browsers except pre-IE 6 versions on PC. In these browsers the total width would be just 100px, with the padding and border widths being incorporated into this width. The box model hackcan be used to fix this, but this can get really messy.

A simple alternative is to use this CSS:


#box
{
width: 150px
}


#box div
{
border: 5px;
padding: 20px
}

And the new HTML would be:

<div id="box"><div>...</div></div>

Perfect! Now the box width will always be 150px, regardless of the browser!

Permanent link to this article: https://blog.openshell.in/2011/01/css-trick-css-box-model-hack-alternative/

PHP Pagination Script

In this article, attached the script to make it working and easy to edit. This is a flexible and easy to implement PHP pagination script which will help you split large result sets over multiple pages. Click here to download the script

Steps to use:

  1. include the ps_pagination.php file to your script.
  2. Create a ps_pagination object. The ps_pagination class constructor takes five parameters:
    • MySQL connection link
    • SQL query
    • Number of records to display per page. Defaults to 10
    • Number of pagination links to display. Defaults to 5
    • Your own custom parameters you want to be appended to pagination links
  3. The first two are compulsory and the last three are optional’s.
  4. Call the paginate() function. This function returns a paginated result set for the current page. You can use this result set just as you would use a normal MySQL result set.
  5. To display the pagination links, use the renderFullNav() function to generate and display the links in one go or you can use individual function calls to display each link separately. You can also use this functions to display the paginate links:
    • renderFirst – This function displays the link to the first page
    • renderLast – This function displays the link to the last page
    • renderNext – This function displays link to next page
    • renderPrevious – This function displays link to previous page
    • renderNav – Displays the page links
    • renderFullNav – This function displays all the pagination links in one go

Example:

<?php
//Enable & display error messages
ini_set(‘display_errors’, ‘On’);
error_reporting(E_ALL);

//Include the PS_Pagination class
include(‘ps_pagination.php’);

// database connection config
$dbHost = ‘localhost’;
$dbUser = ‘root’;
$dbPass = ”;
$dbName = ‘mydb’;

// database Connection
$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die (‘MySQL connect failed. ‘. mysql_error());
mysql_select_db($dbName) or die(‘Cannot select database. ‘. mysql_error());

$sql = ‘select post_title from posts’;

$rows_per_page = 10;
$links_to_display = 5;
$extra_parameters = “param1=value&param2=value”;

//Create a PS_Pagination object
$pager = new PS_Pagination($dbConn, $sql, $rows_per_page, $links_to_display, $extra_parameters);

$rs = $pager->paginate();
//Loop through the result set

while($row = mysql_fetch_assoc($rs)) {
echo $row[‘post_title’].”<br/>”;
}
//Display the navigation
echo $pager->renderFullNav();

?>

Permanent link to this article: https://blog.openshell.in/2010/12/php-pagination-script/

Aptitude Question

  1. Eight peoples take positions in clockwise, direction starting from the position of head of the group around a circular table. There are 4 males: Ajay, Nilesh, Gautam and Vishal and 4 females: Komal, Babita, Chaitali and Divyani in the group.

The following conditions are to be followed:

  1. The head of the group, Vishal has a female opposite to him.
  2. Chaitali is 1 place to the right of Vishal.
  3. Divyani sits immediate to the right of Babita.
  4. Gautam who  sits diametrically opposite to Divyani is to the the immediate right of Vishal.
  5. Nilesh sits opposite to Chaitali and has a female to his right.
  6. The people are numbered from 1 to 8 in the clockwise direction starting from Vishal.

(i)                Who sits at the 6th position?

1] Vishal              2] Ajay           3]Gautam                 4] Nilesh

(ii)       Who sits at the 2nd position?

1] Ajay                2] Divyani     3] Komal                   4] Gautam

(iii)      Who sits opposite to Vishal?

1] Divyani         2] Komal       3] Nilesh                    4] Babita

(iv)       Komal sits diagonally opposite to?

1] Vishal           2] Ajay           3]Gautam                 4] Divyani

(v)         How many people sit between Divyani and Gautam?

1] 3                    2] 2                 3] 5                             4] 4

Answers: (i) 2]       (ii) 3]              (iii) 4]                        (iv) 2]             (v) 1]

Permanent link to this article: https://blog.openshell.in/2010/12/aptitude-question/

MySQL Subquery Optimization

Never use a subquery inside a WHERE field IN(…)  the SQL query.  It will slow down the process.

Slow:

SELECT * FORM table1 WHERE field1 IN
(SELECT field2 FROM table2 GROUP BY field1)

Instead of using a subquery inside an IN(…),  use INNER JOIN query. It will speed up the process, but in IN(…) query speed will slow exponentially as more rows are added.

Optimized:

SELECT * FROM table1 AS t1 INNER JOIN (
SELECT field2 FROM table2 GROUP BY field1
) AS t2 ON t1.field1=t2.field2;

Permanent link to this article: https://blog.openshell.in/2010/12/mysql-subquery-optimization/

Exception Handling Provided by Struts

Exception Handling Capabilities of Struts

Target Audience: J2EE Developers, Web Component Developers

What you should know already: MVC Design Pattern, Struts Framework, Struts configuration file

Exception handling is very crucial part in Web application development. Throwing an exception is Java’s way of informing the client that something has gone wrong while doing a certain processing action.

The Struts framework provides two solutions for exception handling:

  1. Declarative Exception Handling
  2. Programmatic Exception Handling

In this blog I am going to explain about Declarative Exception Handling only.

Declarative Exception Handling

In this approach the exceptions are defined in the struts-config.xml file and in case of the exception occurs, the control is automatically passed to the appropriate error page.

The <exception> tag is used to define the exception in the struts-config.xml file. The following are the attributes of the <exception> tag.

key Defines the key present in message resource bundle file to describe the exception occurred.
type The class of the exception occurred.
path The page where the control is to be followed when an exception occurs.
handler The exception handler which will be called before passing the control to the file specified in path attribute.

The Struts framework has a default exception-handler class that is used to process the exceptions if you do not configure one of your own. The default handler class is org.apache.struts.action.ExceptionHandler. The execute( ) method of this handler creates an ActionError, stores it into the proper scope, and returns an ActionForward object that is associated with the path attribute specified in the <exception> element.

Where to define <exception> ?

There are following two sections in struts-config.xml where the exceptions can be defined:

1. With Any Action mapping: In this approach, the action class is identified which may throw an exception like password failure, resource access failure and so on. See the following code snippet:

<action path=”/login” type=”com.struts.LoginAction”>
<exception key=”error.system” type=”java.lang.Exception” path=”/index.jsp”/>
</action>

This specifies the path to which to forward when one of the specified exceptions occurs during the corresponding action invocation.

2. Defining Exceptions Globally: If the application control is to pass on a single page for all similar type of exception then the exception can be defined globally. So if in any circumstance the exception occurs the control is passed globally to the exception and control is passed to the error page. This is done using the <global-exceptions> tag :

<global-exceptions>
<exception key=”error.system” type=”java.lang.Exception” path=”/index.jsp”/>
</global-exceptions>

Declarative exception handling is a great addition to the struts framework which saves developers time, during both initial development and maintenance.

Permanent link to this article: https://blog.openshell.in/2010/12/exception-handling-provided-by-struts/

Enable .htaccess in Apache2

At first You should define,  mod_rewrite is a part of Apache server that can rewrite requested urls on the fly.

To enable in Ubuntu, you just need to write this command in terminal

sudo a2enmod rewrite

Then edit /etc/apache2/sites-available/default

Find the following

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

and change it to

Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all

and finally restart Apache

/etc/init.d/apache2 restart

To enable in windows, open the httpd.conf file. This file is found in the apacheconf directory

Locate the following line of code:
#LoadModule rewrite_module modules/mod_rewrite.so

Remove the # from the line as seen below to enable the module:
LoadModule rewrite_module modules/mod_rewrite.so

Under “<directory XXX></directory>” section:
Change the line “AllowOverride None” to “AllowOverride All“.

Save the httpd.conf file

Restart your Apache Server

After enabling mod_rewrite you can write .htaccess file for your web application.

Permanent link to this article: https://blog.openshell.in/2010/12/enable-htaccess-in-apache2/

Configure Ruby on Rails with no database

Although Rails is intended for creating database-backed web applications, this example is simple enough that it doesn’t require one. In this case, you need to edit the enviroment.rb configuration file to indicate that your application does not use a database. It is possible to disable loading ActiveRecord by making a simple modification to environment.rb:

1. Open ‘/config/environment.rb’ file in a text editor.

2. Remove the pound character (#) in front of line 21 to uncomment it so that it reads as:

config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

ActiveRecord supports database access for Rails applications. When you create model objects, you will most likely base them on ActiveRecord::Base.

3. Save the file.

Permanent link to this article: https://blog.openshell.in/2010/12/configure-ruby-on-rails-with-no-database/

Registering XML Schema to IBM DB2 pureXML

Target Audience: DBA, DB Developers
What you should know: XML, XML Schema, Understanding of IBM DB2 pureXML

DB2 is unrivaled in its ability to manage both relational and XML data, enabling strong runtime performance and high levels of development time and cost savings. By integrating XML data intact into a relational database structure, users can take full advantage of DB2’s relational data management features.

XML Document Validation

Using your file system, XML documents can be validated using Document Type Definition (DTD) or XML Schema Document (XSD). The validation is done using the namespace declaration in the XML document.

XML Column Validation

XML (column) validation is the process of determining whether the structure, content, and data types of an XML (column) document are valid according to an XML schema.

When you plan to make use of pureXML features you should consider XML document validation when you insert into XML columns. You can register schema document (XSD) to DB2 and that can be identified using schema id. For example, the following XML schema document contains definitions for element called isbn:

<?xml version="1.0" ?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://library.com/isbn-schema" xmlns:tns="http://library.com/isbn-schema">
<complexType name="isbnType">
<sequence>
<element name="bktitle" type="string"/>
<element name="author" type"string" />
</sequence>
</complexType>
<element name="isbn" type="tns:isbnType" />
</schema>

Suppose, the above file is located in /home/theuser/ibm/schema_for_isbn.xsd then, the CLP command for registering above schema is as follows
REGISTER XMLSCHEMA 'schema_for_isbn.xsd' FROM 'file:////home/theuser/ibm/schema_for_isbn.xsd' AS DB2INST1.LIBRARY_BOOK_SCHEMA;
Then issue the following command to validate the XML schema and activate it:
COMPLETE XMLSCHEMA DB2INST1.LIBRARY_BOOK_SCHEMA


Reference
Managing XML Schema in IBM DB2

Permanent link to this article: https://blog.openshell.in/2010/12/registering-xml-schema-to-ibm-db2-purexml/