more debugs

Tuesday, January 31, 2012

Speaker Microphone Circuit

Speaker Microphone Circuit

Description:

This circuit takes an ordinary loudspeaker and allows it to be used in reverse, as a microphone.

Notes:

This circuit allows you to use a cheap loudspeaker as a microphone. Sound waves reaching the speaker cone cause fluctuations in the voice coil. The voice coil moving in the speakers magnetic field will produce a small electrical signal. The circuit is designed to be used with an operating voltage between 6 and 12 volts dc. The first transistor operates in common base mode. This has the advantage of matching the low input impedance of the speaker to the common base stage, and secondly has a high voltage gain. The second stage is direct coupled and operates in emitter follower. Voltage gain is slightly less than unity, but output impedance is low, and will drive long cables.

Speech quality is not as good compared to an ordinary or ECM microphone, but quite acceptable results can be obtained. Speaker cones with diameters of 1 inch to 3 inches may be used. Speaker impedance may be 4 ohm to 64 ohm. The 8.2 ohm resistor value may be changed to match the actual speakers own impedance.









Wednesday, December 14, 2011

Dynamic Menu In ASP.NET Using MSSQL, and XML

Creating a dynamic menu which gets the menu items and sub menu item during the execution time of the asp.net project requires to construct a table say Menu where we insert the information of the menu items to be rendered in the asp page.


Design Table for Dynamic Menu
Design Table for Dynamic Menu


First drag a menu control from the toolbox of the Visual Studio to the form where you want to see your dynamic menu. Then Create a table having a MenuId as primary key, MenuName where we insert the name of the menu to be displayed in the view page,UnderMenu where we insert sub menu which are to be shown on mouse hover. For example, on the mouse hover of Tutorials Main Menu we need to show different topics such as HTML,Ruby On Rails, C#, ASP.NET, JAVA, MSSQL etc. OR any thing else according to your choice.So now insert the data in the above table according to requirement.

Dynamic Menu
Insert Data Into Table


similarly go on adding menus in parent child relationship.




Here you can see that the parent menu are given under menu id '0' and its child are given its parents menu id as under menu id. Here you can see that MenuId of Company is 2, and its under menu is 0 which indicates that menu Company is parent menu. Then the other two menu Board of Directors and Organization Structure are filled with UnderMenu of 2, Which says that these two menu are child of Company menu.


Now Its time to do some coding to create xml consisting dynamically of all the values in the table given above. The PostUrl field in the above table give the url to follow on click of the menu such the you dont need to hard code Response.Redirect manually to redirect a click to different url.
So now the C# code goes here, Its a bit complicated in viewing but try to understand it.

XmlDataSource xd = new XmlDataSource();
string xmlstr;
xmlstr = "";
xmlstr += "";


Here you will have to make some connections to your database table, open it and call it con.

string sql = "select * from Menu where MenuId order by MenuId";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
string menuName = reader["MenuName"].ToString();
string MenuId = reader["MenuId"].ToString();
string underMenu = reader["UnderMenu"].ToString();

Checks if it is the parent menu. If its parent menu goes to find own child menu in the table

if (underMenu == "0")
{
xmlstr += " ";
string innerSql = "select * from Menu;

make another connection to your database and call it innercon
SqlCommand innerCmd = new SqlCommand(innerSql, innercon);
SqlDataReader innerReader = innerCmd.ExecuteReader();
while (innerReader.Read())
{
string innerMenuName = innerReader["MenuName"].ToString();
string postUrl = innerReader["PostUrl"].ToString();
}
innerReader.Close();
innercon.Close();

Dont forget to close inner connections
}
}
xmlstr += "";
xd.CacheExpirationPolicy = DataSourceCacheExpiry.Absolute;
xd.CacheDuration = 1;
xd.EnableCaching = false;
xd.Data = xmlstr;

MainMenu is the ID of the menu dragged from toolbox to the form in aspx. You can get or change your ID easily from the view.

MainMenu.DataSource = xd;
MainMenu.DataBind();
}
}


Now the only thing left is the DataBinding portion of the program. But if you like to have some designs in your menu you can add which will not affect the entire process how the menu is shown.In aspx page add the databinding functionality.

<asp:Menu ID="MainMenu" Orientation="Horizontal" BackColor="#000000">

<DataBindings> <asp:MenuItemBinding DataMember="TopMenu" TextField="text" ValueField="text" SelectableField="isSelectable" ToolTipField="toolTipMsg" EnabledField="isEnabled" /> <asp:MenuItemBinding DataMember="Menu" TextField="text" ValueField="text" NavigateUrlField="url" SelectableField="isSelectable" ToolTipField="toolTipMsg"/> <asp:MenuItemBinding DataMember="SubMenu" TextField="text" ValueField="text" NavigateUrlField="url" SelectableField="isSelectable" /> </DataBindings> </MainMenu>



The above mentioned MainMenu is ID of the menu dragged and dropped into the aspx page
default color taken by the menu may have been white so try to add colors to the menu styles.Menu Style will be covered later on this blog.



Monday, December 12, 2011

Difference between Store Procedures and Triggers


We can call procedures explicitly but trigger is automatically invoked when the action defined in trigger is performed. Store procedure can't be inactive but triggers can be inactive.


With this short introduction of store procedure and trigger I want to give idea of creating store procedures in any phpmyadmin . It's all same as creating store procedure in MSSQL but the little different part is the delimiter determination. So we have to set delimiter from ';' to '//' which is only one tricky part of store procedure in MySQL.



Sunday, December 11, 2011

Model View Controller Framework

Model View Controller framework(MVC) is a software architecture. The Pattern isolates "domain logic" (the application logic for the user) from the user interface(input and presentation), permitting independent development, testing and maintenance of each(separation of concerns).


MODEL is not necessarily merely a database; the model in MVC is both data and the business/domain.
The model manages the behaviour and data of the application domain, responds to request for information about its state (usually from view) and responds to instruction to change state(usually from the controller).

The CONTROLLER receiver the input and initiates a response by making calls on model objects. A controller accepts input from the user and view part to perform actions based on that input.

The VIEW renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exists for a single model for different purpose. A view part typically has a one to one correspondence with a display surface and known to render to it.

Wednesday, December 7, 2011

Some Definations

What is Serialization?

- The process of  writing the state of an object to a byte system is called serialization, also, it is used to save the program to persistent storage area, like a file and easily restore using deserialization process.

 Why do we need finalize() method when Garbage Collection is there?

-Some time an object (which is lost there object reference) is holding some JAVA resources like file handle, Character font, need to free from the resource before that object is collected by JVM or say garbage collection.

Why finally methods in exceptions?
- The finally method will be executed after a try or catch execution, and mainly used to free up resources. Any code that must be execute before a method returns is put in a finally block.

                               try {
                                     // block of code to monitor for errors
                                    }
                              catch(Exception exObject)
                                             {
                                              // exception handler for Exception Type1
                                              }
                                finally 
                                           {
                                              // block of code to be executed before method returns
                                         }

Method Overloading ?
   -   Operator Overloading is a specific case of polymorphism in which some or all of opertors like    +,=,or == have different implementations depending on the types of their arguments.

        Function Overloading or method overloading allows to creation of several methods with the same name which differ from each other in terms of the type of input and the type of the output of the function(not available in JAVA).

Method overloading is usually associated with statically-typed programming languages which enforce type checking in functions call.


Method Overriding ?
   - In overriding, a method in a super class is overridden the subclass. The method in the subclass will have the same signature as that of the super class, Since the method in the subclass has the same signature and name as the method of its superclass, it is termed as overriding.
                         


Monday, December 5, 2011

Telnet - SMTP Commands (sending mail using telnet)

Telnet - SMTP Commands (sending mail using telnet)

In order to access your mailbox you will need three things.

1. An active internet connection.

2. The address of a mail server capable of relaying for you - usually
provided by your internet provider.(e.g. mail.domain.ext)

3. A valid email address(e.g. mail@domain.ext)

After verification of the above mentioned three points go to following steps.

1. The first thing is to do is open a connection from your computer
to your mail server.

telnet mail.domain.ext 25

you should receive a reply like:

Trying ???.???.???.???...
Connected to mail.domain.ext.
Escape character is '^]'.
220 mail.domain.ext ESMTP Sendmail ?version-number?; ?date+time+gmtoffset?

2. You will then need to delcare where you are sending the email from:

HELO

- dont worry too much about your local domain name although you
really should use your exact fully qualified domain name as seen by
the outside world the mail server has no choice but to take your
word for it as of RFC822-RFC1123.
This should give you:

250 mail.domain.ext Hello [loc.al.i.p], pleased
to meet you

3. Now give your email address:

(On many mailservers the space after the : is
required rather that optional.)

MAIL FROM: mail@domain.ext
Should yeild:
250 2.1.0 mail@domain.ext... Sender ok

4. If it doesn't please see possible problems.

5. Now give the recipients address:

RCPT TO: mail@otherdomain.ext
Should yeild:
250 2.1.0 mail@otherdomain.ext... Recipient ok
6. If it doesn't please see possible problems. Note Google mail
servers require < and > around the email address.

7. To start composing the message issue the command DATA

8. If you want a subject for your email type Subject:-type subject
here- then press enter twice (these are needed to conform to RFC 882)

9. You may now proceed to type the body of your message (e.g. hello
mail@otherdomain.ext from mail@domain.ext)

10. To tell the mail server that you have completed the message enter
a single "." on a line on it's own.

The mail server should reply with: 250 2.0.0 ???????? Message
accepted for delivery

11. You can close the connection by issuing the QUIT command.

The mailserver should reply with something like:221 2.0.0
mail.domain.ext closing connection
Connection closed by foreign host.

Wednesday, November 30, 2011

Database Management System

Normalization is the process of organizing data in a database. This includes creating tables and
establishing relationships between those tables according to rules designed both to protect the
data and to make the database more flexible by eliminating two factors: redundancy and
inconsistent dependency.
Redundant data wastes disk space and creates maintenance problems. If data that exists in more
than one place must be changed, the data must be changed in exactly the same way in all
locations. A change in the customer is much easier to implement if that data is stored only in the
Customers table and nowhere else in the database.
What is an "inconsistent dependency"? While it is intuitive for a user to look in the Customers table
for the address of a particular customer, it may not make sense to look there for the salary of the
employee who calls on that customer. The employee's salary is related to, or dependent on, the
employee and thus should be moved to the Employees table. Inconsistent dependencies can
make data difficult to access; the path to find the data may be missing or broken.

Goals
  
  • Ensuring data dependencies make sense. 
  • Role of Normalization.

Role of Normalization

In the E-R model, a conceptual schema using an entity- relationship diagram is built and then
mapped to a set of relations. This technique ensures that each entity has information about only
one thing and once the conceptual schema is mapped into a set of relations, each relation would
have information about only one thing. The relations thus obtained would normally not suffer from
any of the anomalies. This bottom-up approach is likely to lead to a relation that is likely to suffer
from all the problemsn. For example, the relation is highly likely to have redundant information and
update, deletion and insertion anomalies. Normalization of such large relation will then be essential
to avoid (or at least minimize) these problems.
Now to define the normal forms more formally, we first need to define the concept of functional
dependence.

Functional Dependency

Consider a relation R that has two attributes A and B. The attribute B of the relation is functionally
dependent on the attribute A if and only if for each value of A no more than one value of B is
associated. In other words, the value of attribute A uniquely determines the value of B and if there
were several tuples that had the same value of A then all these tuples will have an identical value
of attribute B.
If B is functionally dependent on A (or A functionally determines B).

For example, in the student database that we have discussed earlier, we have the following
functional dependencies:
sno -> sname
sno -> address
cno -> cname
cno -> instructor
instructor -> office

These functional dependencies imply that there can be only one name for each sno, only one
address for each student and only one subject name for each cno. It is of course possible that
several students may have the same name and several students may live at the same address. If
we consider cno -> instructor, the dependency implies that no subject can have more than one
instructor (perhaps this is not a very realistic assumption). Functional dependencies therefore
place constraints on what information the database may store. In the above example, one may be
wondering if the following FDs hold
sname -> sno
cname -> cno

First Normal Form (1NF)

A table satisfying the properties of a relation is said to be in first normal form. As discussed in an
earlier chapter, a relation cannot have multivalued or composite attributes. This is what the 1NF
requires.
A relation is in 1NF if and only if all underlying domains contain atomic values only.
The first normal form deals only with the basic structure of the relation and does not resolve the
problems of redundant information or the anomalies discussed earlier. All relations discussed in
these notes are in 1NF.
For example consider the following example relation:
student (sno, sname, dob)
Add some other attributes so it has anomalies and is not in 2NF

The attribute dob is the date of birth and the primary key of the relation is sno with the functional
dependencies sno -> sname and sno -> dob. The relation is in 1NF as long as dob is considered
an atomic value and not consisting of three components (day, month, year). The above relation of
course suffers from all the anomalies that we have discussed earlier and needs to be normalized.
(add example with date of birth)


Second Normal Form (2NF)

The second normal form attempts to deal with the problems that are identified with the relation
above that is in 1NF. The aim of second normal form is to ensure that all information in one
relation is only about one thing.
A relation is in 2NF if it is in 1NF and every non-key attribute is fully dependent on each candidate
key of the relation.
To understand the above definition of 2NF we need to define the concept of key attributes. Each
attribute of a relation that participates in at least one candidate key of is a key attribute of the
relation. All other attributes are called non-key.
The concept of 2NF requires that all attributes that are not part of a candidate key be fully
dependent on each candidate key. If we consider the relation
student (sno, sname, cno, cname)
and the functional dependencies
sno -> cname
cno -> cname

and assume that (sno, cno) is the only candidate key (and therefore the primary key), the relation
is not in 2NF since sname and cname are not fully dependent on the key. The above relation
suffers from the same anomalies and repetition of information as discussed above since sname
and cname will be repeated. To resolve these difficulties we could remove those attributes from
the relation that are not fully dependent on the candidate keys of the relations. Therefore we
decompose the relation into the following projections of the original relation:
S1 (sno, sname)
S2 (cno, cname)
SC (sno, cno)
Use an example that leaves one relation in 2NF but not in 3NF.
We may recover the original relation by taking the natural join of the three relations.
If however we assume that sname and cname are unique and therefore we have the following
candidate keys
(sno, cno)
(sno, cname)
(sname, cno)
(sname, cname)
The above relation is now in 2NF since the relation has no non-key attributes. The relation still has
the same problems as before but it then does satisfy the requirements of 2NF. Higher level
normalization is needed to resolve such problems with relations that are in 2NF and further
normalization will result in decomposition of such relations.

Third Normal Form (3NF)

Although transforming a relation that is not in 2NF into a number of relations that are in 2NF
removes many of the anomalies that appear in the relation that was not in 2NF, not all anomalies
are removed and further normalization is sometime needed to ensure further removal of
anomalies. These anomalies arise because a 2NF relation may have attributes that are not directly
related to the thing that is being described by the candidate keys of the relation. Let us first define
the 3NF.
A relation R is in third normal form if it is in 2NF and every non-key attribute of R is non-transitively
dependent on each candidate key of R.
To understand the third normal form, we need to define transitive dependence which is based on
one of Armstrong's axioms. Let A, B and C be three attributes of a relation R such that A -> B and
B -> C. From these FDs, we may derive A -> C. As noted earlier, this dependence A -> C is
transitive.
The 3NF differs from the 2NF in that all non-key attributes in 3NF are required to be directly
dependent on each candidate key of the relation. The 3NF therefore insists, in the words of Kent
(1983) that all facts in the relation are about the key (or the thing that the key identifies), the whole
key and nothing but the key. If some attributes are dependent on the keys transitively then that is
an indication that those attributes provide information not about the key but about a kno-key
attribute. So the information is not directly about the key, although it obviously is related to the key.
Consider the following relation
subject (cno, cname, instructor, office)
Assume that cname is not unique and therefore cno is the only candidate key. The following
functional dependencies exist
sno -> cname
cno -> instructor
instructor -> office
We can derive cno -> office from the above functional dependencies and therefore the above
relation is in 2NF. The relation is however not in 3NF since office is not directly dependent on cno.
This transitive dependence is an indication that the relation has information about more than one
thing (viz. course and instructor) and should therefore be decomposed. The primary difficulty with
the above relation is that an instructor might be responsible for several subjects and therefore his
office address may need to be repeated many times. This leads to all the problems that we
identified at the beginning of this chapter. To overcome these difficulties we need to decompose
the above relation in the following two relations:
s (cno, cname, instructor)
ins (instructor, office)
s is now in 3NF and so is ins.
An alternate decomposition of the relation subject is possible:










Tuesday, November 29, 2011

jQuery

Image SlideShow Using jQuery

index.html

<!doctype html>
<html>
    <head>
        <link rel="stylesheet" href="css/style.css">
        <title>Image SlideShow</title>       
    </head>
   
    <body>
        <header id="main-header">
        </header>

        <section id="slideshow-app">       
            <div id="slideshow-frame">
                <ul id="slideshow-nav"></ul>               
                <ul id="slideshow-images">
                    <li class = "visible">
                        <figure class="slideshow-image">
                            <img alt="" src="images/everest.jpg" />
                            <figcaption>Everest Nepal</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                            <img alt="" src="images/mountain-lake.jpg" />
                            <figcaption>Mountain Lake</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                            <img alt="" src="images/kantegapeak.jpg" />
                            <figcaption>Kantega Peak</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                            <img alt="" src="images/khumbu_valley.jpg" />
                            <figcaption>Khumbu Valley</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                        <img alt="" src="images/mount everest.jpg" />
                        <figcaption>Mount Everest</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                        <img alt="" src="images/mt_everest.jpg" />
                        <figcaption>Sagarmatha</figcaption>
                        </figure>
                    </li>
                    <li>
                        <figure class="slideshow-image" >
                        <img alt="" src="images/view-at-chomrong.jpg" />
                        <figcaption>View at Chomrong</figcaption>
                        </figure>
                    </li>
                </ul>
            </div>
            <div id="slide-control">
                <a id="previous-slide" href="#">&larr;</a>
                <a id="play-toggle" href="">Pause</a>
                <a id="next-slide" href="">&rarr;</a>
            </div>
        </section>
               
        <footer>
            <script src="js/jquery-1.5.1.js"></script>
            <script src="js/application.js"></script>   
        </footer>
    </body>
</html>




application.js



function slide_next() {
    $("#slideshow-nav li#"+ page).removeClass("current-slide");
    if (page >= total_images)
        page= 1;
    else
        page++;
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    $("#pagination").text(page);
    var current = $('#slideshow-images li.visible');
    current.removeClass('visible');
    current.fadeOut(100);   
    var remaining_images = current.nextAll().length;       
    if (remaining_images == 0) {
        $('#slideshow-images li:first').addClass('visible');
        $('#slideshow-images li:first').fadeIn('slow');
    }
    else {
        current.next().fadeIn("slow");
        current.next().addClass('visible');
    }
}

function slide_jump(img_number) {
    $("#slideshow-nav li#"+ page).removeClass("current-slide");
    var current = $('#slideshow-images li.visible');
    current.removeClass('visible');
    current.fadeOut(100);
    page=img_number;
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    var first_image = $('#slideshow-images li:first');
    for(i=1;i<page;i++)
    {
        first_image = first_image.next();
    }
    first_image.addClass('visible');
    first_image.fadeIn('slow');
}

function slide_previous() {
    $("#slideshow-nav li#"+ page).removeClass("current-slide");
    if (page <= 1)
        page= total_images;
    else
        page--;
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    $("#pagination").text(page);
    var current = $('#slideshow-images li.visible');
    current.removeClass('visible');
    current.fadeOut(100);
    var remaining_images = current.prevAll().length;
    if (remaining_images == 0) {
        $('#slideshow-images li:last').addClass('visible');
        $('#slideshow-images li:last').fadeIn('slow');
    }
    else {
        current.prev().addClass('visible');
        current.prev().fadeIn('slow');
    }
}

function auto_play() {
    if (play == true)
        slide_next();
}

function play_toggle() {
        if ($("#play-toggle").text()=="Pause") {
            play=false;
            $("#play-toggle").text("Play");
        }
        else {
            play=true;
            $("#play-toggle").text("Pause");
        }
}

$(function () {
    play = true;
    page=1;
    $("#pagination").text(page);
   
    total_images= $('#slideshow-images li.visible').nextAll().length +1;
    for(i=1;i<=total_images;i++) {       
        $('#slideshow-nav').append("<li>.</li>");
        $('#slideshow-nav li:last').attr("id",i);
    }
   
    $("#slideshow-nav li").click(function () {
        slide_jump(this.id);
    });
   
    $('#slideshow-images li:first').fadeIn("slow");
    $("#slideshow-nav li#"+ page).addClass("current-slide");
    //automatic slide show
    setInterval("auto_play()",1500);
   
    $('#next-slide').click( function () {
        slide_next();
        return false;
    });

    $('#play-toggle').click( function () {
        play_toggle();
        return false;
    });
   
    $("#slideshow-frame, #slide-control").mouseover(function () {
        play=false;
    });
   
    $("#slideshow-frame, #slide-control").mouseout(function() {
        if ($("#play-toggle").text()=="Pause")
            play=true;
    });

    $('#previous-slide').click( function () {
        slide_previous();
        return false;
    });
});

style.css

body {
    text-align: center;
}

#slideshow-app {
    background: #000000;
    padding: 8px 0px 10px 0px;
}

#slideshow-frame {
    border: solid 1px #D4CDCF;
    height: 620px;
    width: 660px;
    display:inline-block;
    border-radius: 20px;
    padding-top: 0px;
    background: #000000;
    overflow: hidden;
    margin-bottom: 10px;
    padding-right: 30px;
}

#pagination {
    color: #D4CDCF;
}

ul#slideshow-nav {
    cursor: hand;
}

ul#slideshow-nav li{
    display:inline;
    color: #73172E;
    font-size: 30px;
    font-weight: bolder;
    padding-right: 15px;
}

ul#slideshow-nav li.current-slide {
    color: #D4CDCF;
}

ul#slideshow-images {
    list-style: none;
    overflow:hidden;
}

ul#slideshow-images li {
    display: none;
    overflow: hidden;
}

ul#slideshow-images li img {
    -webkit-box-reflect: below 5px -webkit-gradient(linear, left top, left bottom, from(transparent), color-stop(.8, transparent), to(white));
    -webkit-border-radius: 7px;
    margin-bottom: 100px;
    height: 400px;
    width: 533px;
}

figure.slideshow-image figcaption {
    color: #D4CDCF;
}

figcaption {
    display:block;
}

#slide-control a {
    text-decoration: none;
    font-size: 30px;
    padding: 0px 18px;
    background-color: #000000; /* fallback color */
    background: -moz-linear-gradient(100% 100% 90deg, #303030, #000000);
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#505050), to(#000000));
    color: #FFFFFF;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    box-shadow: 0 5px 5px rgba(0,0,0,.4);
    text-shadow: 0 3px 3px rgba(255,255,255,.6);
}

#slide-control a:hover {
    background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#666666), to(#666666), color-stop(.6,#333));
    background-color: #000000;
}