SlideShow using jQuery

Creating Image Slide Show using jQuery:

In the code below you will see a surrounding div (id slideshow-area) which holds our slideshow content scroll area and our next and previous buttons. Inside our scroll area we have a div to hold the content and finally the content itself. As far as html goes this is pretty simple stuff.

<div id=”slideshow-area”>
<div id=”slideshow-scroller”>
<div id=”slideshow-holder”>
<div class=”slideshow-content”>
<img src=”eureka_small.jpg” />
</div>
<div class=”slideshow-content”>
<img src=”wallace_gromit_small.jpg” />
</div>
<div class=”slideshow-content”>
<img src=”dead_like_me_small.jpg” />
</div>
</div>
</div>
<div id=”slideshow-previous”></div>
<div id=”slideshow-next”></div>
</div>
CSS is up next, it is slightly more complicated than the html but nothing too crazy. The first piece to look at is the positioning and sizing of main slide show area and scroller, which can have pretty much the same css. We do however add a border to our area to bring it out a little. The code below is fairly understandable, I make sure to set the position to relative so that I can easily position the next and previous buttons absolutely.
#slideshow-area, #slideshow-scroller {
width: 500px;
height: 500px;
position: relative;
overflow: hidden;
margin: 0 auto;
}

#slideshow-area {
border: 1px solid #000;
}

We are also going to set the height of the content holder to 500px, same as the area.
#slideshow-holder {
height: 500px;
}
The next two items are the previous and next buttons. They take a little bit more work to make sure they are in the correct position. The buttons also have background images for pretty arrows (sorry IE6 users it may look bad since the arrows are png files). I also set the cursor to hand and pointer – for browser compatibility. And finally we also have classes to identify and float left each piece of content in the slideshow.
#slideshow-previous, #slideshow-next {
width: 50px;
height: 50px;
position: absolute;
background: transparent url(“arrow_left.png”) no-repeat 50% 50%;
top: 225px;
display: none;
cursor: pointer;
cursor: hand;
}

#slideshow-next {
display: block;
background: transparent url(“arrow_right.png”) no-repeat 50% 50%;
top: 225px;
right: 0;
}

.slideshow-content {
float: left;
}

Well onto the real work, we now have to create the JavaScript to handle our functionality. jQuery makes this relatively simple though. First item is adding code to the document ready event.
var totalSlides = 0;
var currentSlide = 1;
var contentSlides = “”;

$(document).ready(function(){
$(“#slideshow-previous”).click(showPreviousSlide);
$(“#slideshow-next”).click(showNextSlide);

var totalWidth = 0;
contentSlides = $(“.slideshow-content”);
contentSlides.each(function(i){
totalWidth += this.clientWidth;
totalSlides++;
});
$(“#slideshow-holder”).width(totalWidth);
$(“#slideshow-scroller”).attr({scrollLeft: 0});
updateButtons();
});

Next we need to create the two functions showPreviousSlide and showNextSlide. These two functions do mainly three things: change current slide number, update the buttons, and scroll the content. These functions along with support functions are below.
function showPreviousSlide()
{
currentSlide–;
updateContentHolder();
updateButtons();
}

function showNextSlide()
{
currentSlide++;
updateContentHolder();
updateButtons();
}

function updateContentHolder()
{
var scrollAmount = 0;
contentSlides.each(function(i){
if(currentSlide – 1 > i) {
scrollAmount += this.clientWidth;
}
});
$(“#slideshow-scroller”).animate({scrollLeft: scrollAmount}, 1000);
}

function updateButtons()
{
if(currentSlide < totalSlides) {
$(“#slideshow-next”).show();
} else {
$(“#slideshow-next”).hide();
}
if(currentSlide > 1) {
$(“#slideshow-previous”).show();
} else {
$(“#slideshow-previous”).hide();
}
}

Permanent link to this article: https://blog.openshell.in/2010/12/slideshow-using-jquery/

CPU Power States

The CPU power states C0C3 are defined as follows:

  • C0 is the operating state.
  • C1 (often known as Halt) is a state where the processor is not executing instructions, but can return to an executing state essentially instantaneously. All ACPI-conformant processors must support this power state. Some processors, such as the Pentium 4, also support an Enhanced C1 state (C1E or Enhanced Halt State) for lower power consumption,.
  • C2 (often known as Stop-Clock) is a state where the processor maintains all software-visible state, but may take longer to wake up. This processor state is optional.
  • C3 (often known as Sleep) is a state where the processor does not need to keep its cache coherent, but maintains other state. Some processors have variations on the C3 state (Deep Sleep, Deeper Sleep, etc.) that differ in how long it takes to wake the processor. This processor state is optional.
Device power state Registry key Description
Full on D0 Device is on and running. It is receiving full power from the system and is delivering full functionality to the user.
Low on D1 Device is fully functional at a lower power or performance state than D0. D1 is applicable when the device is being used, but peak performance is unnecessary and power is at a premium.
Standby D2 Device is partially powered, with automatic wakeup on request.
Sleep D3 Device is partially powered, with device-initiated wakeup, if available. A device in state D3 is sleeping but capable of raising the system power state on its own. It consumes only enough power to be able to do so; which must be less than or equal to the amount of power used in state D2.
Off D4 Device has no power. A device in state D4 should not be consuming any significant power. Some peripheral buses require static terminations that intrinsically use non-zero power when a device is physically connected to the bus. A device on such a bus can still support D4.

Have a happy day..

Permanent link to this article: https://blog.openshell.in/2010/12/cpu-power-states/

Escape String Literals for SQL

To run a SQL query with text data containing single quotes ‘ as well as other SQL reserved punctuations, and to prevent SQL injections, you will always want to escape the text values before using them in a SQL query.

mysql_real_escape_string() calls MySQL’s library function mysql_real_escape_string, which prepends backslashes to the following characters: x00, n, r, , ‘, ” and x1a.

mysql_real_escape_string($content); 

“SELECT * FROM users WHERE user=’%s’ AND password=’%s'”, mysql_real_escape_string($user), mysql_real_escape_string($password)

Permanent link to this article: https://blog.openshell.in/2010/12/escape-string-literals-for-sql/

Linux gzip and gunzip commands

gzip:

gzip compresses files in linux and unix.

If given a file as an argument, gzip compresses the file, adds a “.gz” suffix, and deletes the original file. With no arguments, gzip compresses the standard input and writes the compressed file to standard output( use “>” to redirect to a file).

Examples:Compress the file named vallu.txt. Creates vallu.gz and deletes vallu.txt.

$ gzip vallu.txt

Compress the file called vallu.txt. The standard output (which is the compressed file) is redirected by the shell to vallu.gz. Keeps vallu.txt.

$ gzip -c vallu.txt > vallu.gz

note: -c option Write compressed file to stdout and keeps the original file.

Some useful options are:

-1  Performance: Use fast compression (somewhat bigger result)

-9  Performance: Use best compression (somewhat slower)

gunzip:

gunzip uncompresses a file that was compressed with “gzip”.

Examples:Uncompress the file named vallu.gz and extracts the vallu.txt in that compressed file and deletes vallu.gz.

$ gunzip vallu.gz

Uncompress the file named vallu.gz and extracts the vallu.txt in that compressed file and keeps the vallu.gz.

$ gunzip -c vallu.gz > vallu.txt

zcat:

zcat is also same as gunzip -c it is basically used to display the content of compressed fule.

Examples:

$zcat vallu.gz

Permanent link to this article: https://blog.openshell.in/2010/12/linux-gzip-and-gunzip-commands/

Passing Parameters to Crystal Report in .Net

Now we are going to see, how we can show report by passing parameters or values. For example, Let us see how to retrieve details of an employee by means of Empid.

First Step

Create a table like the below structure.

Eg:

Column name Datatype
Name varchar(50)
Empid varchar(20)
Gender char(10)
Designation varchar(30)

Second Step

Create a crystal report and drag down your details. Create a parameter for empid. In the details right click the empid->select expert->select is equal to and select your parameter(here empid).

Third Step

Create a web or windows form add the control (Eg.dropdownlist, from where we are going to get the parameter) and add  crystalReportViewer in the same form.

Fourth Step

This is the time to add the code.

add the below packages to the code file,

using CrystalDecisions.CrystalReports.Engine;using CrystalDecisions.Shared;

add the below code to the Form_Load() event:

//setting the path of your crystal report

string path = “type the path of your report”;

this.crystalReportViewer1.ReportSource = path;

ReportDocument cryRpt = new ReportDocument();

cryRpt.Load(path);

//Creating parameters

ParameterFieldDefinitions crDefinitions;

ParameterFieldDefinition crDefinition;

ParameterValues crParameterValues = new ParameterValues();

ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

//Binding the parameter with class variable

crParameterDiscreteValue.Value = sample_class.empid; //you can save this value from your control

crDefinitions = cryRpt.DataDefinition.ParameterFields;

crDefinition = crDefinitions[“empid”];//Parameter Name which is same in the table

crParameterValues = crDefinition.CurrentValues;

crParameterValues.Clear();

crParameterValues.Add(crParameterDiscreteValue);

crDefinition.ApplyCurrentValues(crParameterValues);

crystalReportViewer1.ReportSource = cryRpt;

crystalReportViewer1.Refresh();

Run your program and select the parameter(here empid).It will show the details of an employee.

Have a happy coding..

Permanent link to this article: https://blog.openshell.in/2010/12/passing-parameters-to-crystal-report-in-net/

Java Design Pattern

Design Patterns are recurring solutions to design problems.

The 23 design patterns included in Design Patterns all had several known applications and were on a middle level of generality, where they could easily cross application areas and encompass several objects. These patterns are divided into 3 types.

  1. Creational Patterns: create objects for you, rather than your having to instantiate objects directly. Your programs gains more flexibility in deciding which objects need to be created for a given case.
  2. Structural Patterns: help you to compose group of objects to larger structures, such as complex user interfaces and accounting data.
  3. Behavioural Patterns: help you to define the communication between objects in your system and how the flow is controlled in a complex program.

Permanent link to this article: https://blog.openshell.in/2010/12/java-design-pattern/

Who Uses XML?

Introduction

XML (eXtensible Markup Language) is self-describing. XML tags act as metadata, describing each element. The main purpose is for information exchange between organizations, applications, services, processes, etc.

Who Uses XML?

Financial
FIXML Financial Information eXchange Protocol http://www.fixprotocol.org
FPML Financial Product ML http://www.fpml.org
FUNDSML Funds Markup Language http://www.funds-xml.org
XBRL eXtensible Business Markup Language http://www.xbrl.org
Publication etc.
SportML Sport Markup Language http://www.sportsml.com
NewsML News Markup Language http://www.newsml.org
XBITS XML Book Industry Transaction Standards http://www.xmlbits.org
XPRL eXtensible Public Relations Language http://www.xprl.org
Life Sciences
BSML Bioinformatic Sequence Markup Language http://www.bsml.org
CML Chemical Markup Language http://www.xml-cml.org
Other
LandML Land Development Markup Language http://www.landml.org
MatML Materials Property Data Markup Language http://www.matml.org
JXDM Global Justice XML Data Model http://www.it.ojp.gov/jxdm/3.0/index.html
ebXML Electronic Business using eXtensible Markup Language http://www.ebxml.org

Permanent link to this article: https://blog.openshell.in/2010/12/who-uses-xml/

Aptitude question for maths

Six bells commence tolling together and toll at intervals 2,4,6,8,10 and 12 seconds respectively. In 30 minutes how many times they toll together.

a) 4

b) 10

c) 15

d) 16

Solution: L.C.M. of 2,4,6,8,10,12 = 120

So they toll together after every 120 seconds i.e. 2 minutes. So in 30 minutes they toll together 30/2 + 1 = 16 times

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

Quoting HTML attribute values

The values of attributes can contain text, hexadecimal color codes or numbers. In case of JavaScript event handlers, the values consist of small JavaScript code. A sincere advice for good and clean HTML coding is to always put quotes around attribute values. It is a good habit, will save you many headaches and avoid errors especially when attribute values contain spaces.

while using bgcolor=”#ffffff” instead of bgcolor=#ffffff results is greater browser compatibility and differentiates it nicely from other attribute-value pairs.

Quoting attribute values is also required in XHTML. Your pages will fail the W3C validation if you leave the values hanking around with the quotes.

Permanent link to this article: https://blog.openshell.in/2010/12/quoting-html-attribute-values/

HTML mailto attribute

The HTML mailto is a quick way to add the facility of receiving feedback from visitor on the web site. when the visitor clicked the HTML mailto, It lanuches their email program with new email window.

Note: HTML mailto assumes that the visitor has configured an email client (Outlook Express, Netscape Messenger, Thunderbird or any other) to send emails.

The Basic form HTML mailto requires an email address.

Its looks like:

<a href=”mailto:info@openshell.in”>Feedback Form</a>

The Complex form HTML mailto by adding an email subject and the email body so that it looks a little more professional.

Its look Like:

<a href=”mailto:info@openshell.in?subject=Feedback for Openshell.in&body=Thanks for Provinding useful Tips”>Feedback Form</a>

In addition to the body and subject, we can also provide HTML mailto with CC (Carbon Copy) and BCC (Blind Carbon Copy). This, as you would have guessed, requires us to append these values to the HTML mailto attribute just like we had done for body and subject.

Its look Like:

<a href=”mailto:info@openshell.in?subject=Feedback for Openshell.in&body=Thanks for Provinding useful Tips&cc=anotheremailaddress@anotherdomain.com&bcc=onemore@anotherdomain.com”>Feedback Form</a>

HTML mailto is a quick and easy way for beginners and who don’t know server-side programming languages (such as JSP, PHP, ROR etc.) to add a link on their web site for receiving visitor feedback.

Permanent link to this article: https://blog.openshell.in/2010/12/html-mailto-attribute/