Archive for the ‘Programming’ Category

How to prevent browser from caching a page in rails

I used devise for authentication in my rails project. After I signed out; I clicked the back button in the browser; Oh!!! the browser was showing the previous page from which I clicked ‘sign out’.  I tested this and found that the browser is caching the page.

I used firebug to analyze the project page(s). I found that the

no-cahe is added

To add ‘no-cache’, I added the following lines @ the application_controller.rb file

before_filter :set_no_cache

and the function

def set_no_cache
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end

Restarted the server and found that after I signout and hit ‘back button’ of the browser; the page is redirected to the sign_in page. [ I have configured devise to redirect to sign_in when the session is not valid].

Hope this helps rails users like me.

and I analyzed the rails project page(s) using firebug andThe firebug analyzed results

no-cache implemeted

Popularity: 2% [?]

Steps to Convert the CLOB to VARCHAR2 Data Type

Steps to convert the CLOB(Character Large OBject) to Varchar2 data type.

Step 1: Create a new temporary column with varchar2
Step 2: Move the CLOB column content to new temporary column, if it is needed. (Note : By this situation you may loose the data depending upon Max length)
Step 3: Drop the CLOB column.
Step 4: Rename the temporary column with dropped CLOB column.

Example:

Step 1: ALTER TABLE your_table (temp_column VARCHAR(4000));
Step 2: UPDATE your_table SET temp_column = DBMS_LOB.SUBSTR(clob_column, 4000, 1);
Step 3: ALTER TABLE your_table DROP COLUMN clob_column;
Step 4: ALTER TABLE your_table COLUMN temp_column TO clob_column;

Popularity: 3% [?]

How to Convert the Data Type VARCHAR2 to CLOB in Oracle

We cannot directly convert the data type VARCHAR2 to CLOB(Character Large OBject). Using below two options, we can able to covert it.

Option 1:

Step 1 : Convert the VARCHAR2 To LONG Data Type
Step 2 : Convert the LONG to CLOB Data Type.

Example:

Step 1: ALTER TABLE YOUR_TABLE_NAME MODIFY(Your_Column_Name LONG);
Step 2: ALTER TABLE YOUR_TABLE_NAME MODIFY(Your_Column_Name CLOB;

Option 2:

Step 1: Add a new column as CLOB
Step 2: UPDATE VARCHAR2 date to CLOB column
Step 3: DROP VARCHAR column
Step 4: Rename CLOB column to VARCHAR column name

Popularity: 6% [?]

Remove white spaces in a string c#

By using trim() we can remove white space characters from the beginning and end of a string.But to remove white space characters in middle we cannot use trim() method.

we can easily remove the white spaces/empty space in a string by replace method

string strSample = “Test with white space”;
strSample = strSample.Replace(” “, “”);

Result : strSample = “Testwithwhitespace”

Popularity: 7% [?]

How to enable gzip compression in jBoss?

To enable JBoss http protocol gzip compression you have to change the server.xml file.
Location:
Less than 4.0 Version : ${jBoss-home}\server\default\deploy\jbossweb-tomcat50.sar\server.xml
above 4.0 Version     : ${jBoss-home}\server\default\deploy\jboss-web.deployer\server.xml

Find this piece of xml code:
<Connector port=”8080″ address=”${jboss.bind.address}” maxThreads=”250″
maxHttpHeaderSize=”8192″ emptySessionPath=”true” protocol=”HTTP/1.1″
enableLookups=”false” redirectPort=”8443″ acceptCount=”100″ connectionTimeout=”20000″
disableUploadTimeout=”true” compression=”0″></Connector>

When compression is disabled compression parameter is set to 0.
To enable compression set it to 1.

After that you can see the difference.
It can compress HTML,CSS,JavaScript,Images File from 1 MB to around 300kb.

Popularity: 5% [?]

What is Generics in java?

Generics:

Generics provides compile-time (static) type safety for collections and
eliminates the need for most typecasts (type conversion).

For Example:

List<String> stringList = new ArrayList<String>();
stringList.add(“one”);
stringList.add(“two”);
stringList.add(“three”);
stringList.add(“four”);
stringList.add(“five”);

In the above example,we can add only the String in a ArrayList.If we add
Other than String mean it’s throw an error.

Other Uses Of Generics are:
In For loop we directly use without checking condition of length.

Example:
Previously Used For Loop:
========================
String value=”";
for(int i=0;i<stringList.length();i++)
{
value=(String)stringList.get(i);
System.out.println(value);
}

Generic For Loop
================
for(String value : stringList)
{
System.out.println(value);
}

Popularity: 2% [?]

How to deploy WAR/JAR File in JBOSS

Step to deploy WAR/JAR File in JBOSS

  • Paste your WAR/JAR File into jboss\server\default\deploy Folder
  • Go to jboss\bin and run the file run.bat.
  • After successful run.go to jboss\server\default folder and see three new folder log,tmp,work.
  • log – Log File is created here
  • tmp – All the Deployed WAR and JAR File extacted here.
  • work – all the code in a servlet form maintain here.

Popularity: 3% [?]

Difference between String and String Buffer

String
=====
String are immutable object.Its value cannot be changed(constant).String object are readonly.If you create one instance of string and change the value of string then it create new instance.

String Buffer
=========
String Buffer is mutable.Its Value can be Changed.If you create one instance and append the text without creating a new instance

Example:
======
String
=====
String str=”welcome”;
str + = “to fordevs”;

String Buffer
=========
StringBuffer strbuff=new StringBuffer(“welcome”);
strbuff.append(“to fordevs”);

Both code give same output but Second approach much faster than first one.

Popularity: 6% [?]

How to bring the cursor to the end of text in the textbox control – WPF C#

Normally if we focus a textbox control the cursor would be in the start of the textbox.But when there is text already in the textbox it would be annoying if the cursor is in start.It would be better if the cursor is at the end of content in texbox.

Thus to position the cursor at the end of the text content of a textBox control,we have to call the select method and specify the selection start position to the length of the text and a selection length to 0.

txtExample.focus();
txtExample.Select(txtExample.Text.Length, 0);

Ref : msdn

Popularity: 7% [?]

How to find 2nd highest value in a table ?

To Find the 2nd Maximum Of Mark in a Data Set

SELECT * FROM Student a WHERE 2=(SELECT COUNT(DISTINCT Mark)
FROM Student b WHERE a.Mark&lt;=b.Mark)

To Find the 2nd Minimum Of Mark in a Data Set

SELECT * FROM Student a WHERE 2=(SELECT COUNT(DISTINCT Mark)
FROM Student b WHERE a.Mark&gt;=b.Mark)

To Find nth Maximum and Minimum

SELECT * FROM Student a WHERE n=(SELECT COUNT(DISTINCT Mark)
FROM Student b WHERE a.Mark&lt;=b.Mark)
SELECT * FROM Student a WHERE n=(SELECT COUNT(DISTINCT Mark)
FROM Student b WHERE a.Mark&gt;=b.Mark)

replace n with the corresponding number

Popularity: 2% [?]

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars