Tuesday, March 12, 2013
Binary Tree
Binary Trees
A binary tree is a tree in which each node can have maximum two children.
Thus each node can have no child, one child or two children
Consider a set of numbers: 25,63,13, 72,18,32,59,67.
we store these numbers in individual nodes of a singly linked list
To search for a particular item we have to go through the list, and maybe we have to go to the end of the list as well.
Thus if there were n numbers, our search complexity would be O(n).
suppose we order these numbers:
13,18,25,32,59,63,67,72. and store these in another linked list.
search complexity is still O(n)
You simply cannot apply binary search on a linked list with O(log n) complexity.
So a linear linked structure is not helping
The value at any node is more than the values stored in the left-child nodes,
and less than the values stored in the right-child nodes
Implementation
• A binary tree has a natural implementation in linked storage.
A tree is referenced with a pointer to its root.
A tree is a node with structure that contains more trees.
We have actually a tree located at each node of a tree.
http://www.cs.ucf.edu/courses/cop3502h.02/trees1.pdf
Labels:
Data Structures and Algorithms
tree traversal
- tree traversal
tree traversal refers to the process of visiting (examining and/or updating) each node in a tree data structure,
Such traversals are classified by the order in which the nodes are visited.
Although linked lists require more memory space than arrays ( as they have to store address at each node),
they have definite advantages over arrays.
Insertion and deletion of items can be carried out with out involving considerable movement of data.
http://www.cs.ucf.edu/courses/cop3502h.02/trees1.pdf
- Tree Traversals
Linked lists are traversed sequentially from first node to the last node.
However, there is no such natural linear order for the nodes of a tree.
Different orderings are possible for traversing a binary tree.
Every node in the tree is a root for the subtree that it points to.
There are three common traversals for binary trees:
• Preorder
• Inorder
• Postorder
These names are chosen according to the sequence in which the root node and its children are visited.
http://www.cs.ucf.edu/courses/cop3502h.02/trees1.pdf
- Tree Traversals
There are 3 common tree traversals.
1. in-order: left, root, right
2. pre-order: root, left, right
3. post-order: left, right, root
Note "pre" and "post" refer to when we visit the root.
(we always go from left to right throug leaves but when it is in-order root is in the middle,pre-order it's first and post-order it's last.)
The in-order traversal always prints the values in sorted order from smallest to largest.
http://www.math.ucla.edu/~wittman/10b.1.10w/Lectures/Lec18.pdf
- Depth-first search (DFS) is an algorithm for traversing or searching a tree, tree structure, or graph.
One starts at the root (selecting some node as the root in the graph case) and explores as far as possible along each branch before backtracking.
http://en.wikipedia.org/wiki/Depth-first_search
- In graph theory, breadth-first search (BFS) is a strategy for searching in a graph when search is limited to essentially two operations:
(a) visit and inspect a node of a graph; (b) gain access to visit the nodes that neighbor the currently visited node.
The BFS begins at a root node and inspects all the neighboring nodes
http://en.wikipedia.org/wiki/Breadth-first_search
- There are three types of depth-first traversal: pre-order, in-order and post-order. For a binary tree, they are defined as operations recursively at each node, starting with the root node follows:
Pre-order:
Visit the root.
Traverse the left subtree.
Traverse the right subtree.
In-order (symmetric):
Traverse the left subtree.
Visit the root.
Traverse the right subtree.
Post-order:
Traverse the left subtree.
Traverse the right subtree.
Visit the root.
http://en.wikipedia.org/wiki/Tree_traversal
- infix traversal gives an infix expression
pre-order traversal gives an pre-order expression
post-order traversal gives an post-order expression
infix,pre-order,post-order traversal example
http://www.cs.nuim.ie/~rosemary/se202/treenotes/sld029.htm
- infix,pre-order,post-order traversal example
http://www.cs.cuw.edu/csc/csc300/PowerPoint/TREE%20TRAVERSAL%20EXAMPLE.htm
- D = node, L = left, R =right
• Preorder (DLR) traversal yields: A, H, G, I,F, E, B, C, D
• Postorder (LRD) traversal yields: G, F, E, I,H, D, C, B, A
• In-order (LDR) traversal yields: G, H, F, I,E, A, B, D, C
• Level-order traversal yields: A, H, B, G, I,C, F, E, D
https://docs.google.com/viewer?a=v&q=cache:tUIMUu37Z0oJ:www.cs.siu.edu/~mengxia/Courses%2520PPT/220/finalreview.ppt+&hl=tr&gl=tr&pid=bl&srcid=ADGEEShcYilAqNqch2AN6p2yyA1XFccuhVzGrCzXYljzzrgoZdqR87OAqbgN_osKxdp3B4Jgy_KkgYCHvIImna7DTFXFxruRbv2o2yIOiBqzf6nd-sjahVvFsq0NOpRuZEjA3MrdXXMr&sig=AHIEtbRCSWKbeBnN-GpbuR0Kj_GGrNrgUA
- Inorder Traversal - LDR
The node’s left subtree is traversed
The node’s data is processed
The node’s right subtree is traversed
Preorder Traversal - DLR
The node’s data is processed
The node’s left subtree is traversed
The node’s right subtree is traversed
Postorder Traversal - LRD
The node’s left subtree is traversed
The node’s right subtree is traversed
The node’s data is processed
https://docs.google.com/viewer?a=v&q=cache:962RB0q-kPkJ:digital.cs.usu.edu/~allan/CS2/Slides/Ch20.pdf+&hl=tr&gl=tr&pid=bl&srcid=ADGEEShPsArt6bX6XAwSHqxzO9ueMEXYOczpYtzLEzcF_Ynxbjqt6S1oSfU6KZShCTWPLazYXtcZsAoDP-iJXq5Ajh_cxtYcXFFOlTGyvNt_1NJ3I4kv2c8oTNYkz372sJqPZFI2kVG0&sig=AHIEtbRfU_jyEsuIyuN6vdEPyzXhoCCEtA
Labels:
Data Structures and Algorithms
HTML5
- What is HTML5?
Some rules for HTML5 were established:
New features should be based on HTML, CSS, DOM, and JavaScript
Reduce the need for external plugins (like Flash)
Better error handling
More markup to replace scripting
HTML5 should be device independent
The development process should be visible to the public
http://www.w3schools.com/html/html5_intro.asp
- HTML5
HTML5 is a markup language for structuring and presenting content for the World Wide Web and a core technology of the Internet.
It is the fifth revision of the HTML standard (created in 1990 and standardized as HTML 4 as of 1997) and, as of December 2012, is a W3C Candidate Recommendation.
http://en.wikipedia.org/wiki/HTML5
Labels:
web 2.0
RELAX NG
- RELAX NG
In computing, RELAX NG (REgular LAnguage for XML Next Generation) is a schema language for XML
A RELAX NG schema specifies a pattern for the structure and content of an XML document.
A RELAX NG schema is itself an XML document; however, RELAX NG also offers a popular compact, non-XML syntax
http://en.wikipedia.org/wiki/RELAX_NG
Labels:
Web Service Technologies
MTOM
MTOM
MTOM is the W3C Message Transmission Optimization Mechanism, a method of efficiently sending binary data to and from Web services.
MTOM is usually used with XOP (XML-binary Optimized Packaging).
http://en.wikipedia.org/wiki/Message_Transmission_Optimization_Mechanism
Labels:
Web Service Technologies
Sunday, March 10, 2013
how to activate administrator account windows 7
normally try
net users administrator /active:yes
if you run windows 7 french version try
net users administrateur /active:yes
There are two problems with this feature of the operating system.
First, by default, the administrator account does not show up in the list of available accounts when Windows 7 boots up. This is why so many people do not know that the account even exists.
Second, there is no password set for the administrator account. These two issues combine to create a moderate to major security risk depending on how you use Windows.
http://helpdeskgeek.com/windows-7/secure-the-windows-7-administrator-account/
Labels:
windows interview questions
Thursday, March 7, 2013
javascript interview questions
- Fill in the body of the sortByFoo function below. Executing the code should display true three times in your browser.
function
sortByFoo(tab)
{
// TODO: Fill in the code here, using Array.sort.
return tab;
}
// Sort by .foo attribute
console.log(sortByFoo(
[{foo: 5}, {foo: 7}, {foo: 4}, {foo: 3}, {foo: 2}, {foo: 1}, {foo: 6}]
)[5].foo === 6);
// Does not crash on an empty array
console.log(sortByFoo([]).length === 0);
// For objects without a `foo` attribute, its value should be considered equal to '0'
console.log(sortByFoo([{foo: 42}, {bar: 7}, {foo: -5}])[1].bar === 7);
{
// TODO: Fill in the code here, using Array.sort.
return tab;
}
// Sort by .foo attribute
console.log(sortByFoo(
[{foo: 5}, {foo: 7}, {foo: 4}, {foo: 3}, {foo: 2}, {foo: 1}, {foo: 6}]
)[5].foo === 6);
// Does not crash on an empty array
console.log(sortByFoo([]).length === 0);
// For objects without a `foo` attribute, its value should be considered equal to '0'
console.log(sortByFoo([{foo: 42}, {bar: 7}, {foo: -5}])[1].bar === 7);
Tested sortByFoo.js
with firebug.
function
sortByFoo(tab){
// TODO: Fill in the code here, using Array.sort.
tab.sort(function(elem1, elem2){
var foo1 = elem1.foo || 0,
foo2 = elem2.foo || 0;
return foo1 > foo2 ? 1 : foo1 === foo2 ? 0 : -1;
});
return tab;
}
// Sort by .foo attribute
console.log(sortByFoo(
[{foo: 5}, {foo: 7}, {foo: 4}, {foo: 3}, {foo: 2}, {foo: 1}, {foo: 6}]
)[5].foo === 6);
// Does not crash on an empty array
console.log(sortByFoo([]).length === 0);
// For objects without a `foo` attribute, its value should be considered equal to '0'
console.log(sortByFoo([{foo: 42}, {bar: 7}, {foo: -5}])[1].bar === 7);
// TODO: Fill in the code here, using Array.sort.
tab.sort(function(elem1, elem2){
var foo1 = elem1.foo || 0,
foo2 = elem2.foo || 0;
return foo1 > foo2 ? 1 : foo1 === foo2 ? 0 : -1;
});
return tab;
}
// Sort by .foo attribute
console.log(sortByFoo(
[{foo: 5}, {foo: 7}, {foo: 4}, {foo: 3}, {foo: 2}, {foo: 1}, {foo: 6}]
)[5].foo === 6);
// Does not crash on an empty array
console.log(sortByFoo([]).length === 0);
// For objects without a `foo` attribute, its value should be considered equal to '0'
console.log(sortByFoo([{foo: 42}, {bar: 7}, {foo: -5}])[1].bar === 7);
References
http://www.siteduzero.com/forum/sujet/corps-de-la-fonction-20209
http://www.siteduzero.com/forum/sujet/tableau-foo-5-foo-7-10308
https://gist.github.com/1121755/0f6e5eee6dc437912fb937f5db481235e1837b7e
http://www.opendebug.com/article/321245
http://bbs.csdn.net/topics/380207906
http://www.andhrafriends.com/topic/340334-javascript-solutions-helpp/Finish the code below:
<html><head>
<script>
document.body.innerHTML = '
<div id="42" onclick="clicked(event)">1</div>
<div id="43" onclick="clicked(event)">2</div>
<div id="44" onclick="clicked(event)">3</div>';
function clicked(event)
{
// TODO: Fill in here. Use event.target.
// TODO: Display an alert containing the id of the clicked div
}
</script>
</head>
<body></body>
</html>
<script>
document.body.innerHTML = '
<div id="42" onclick="clicked(event)">1</div>
<div id="43" onclick="clicked(event)">2</div>
<div id="44" onclick="clicked(event)">3</div>';
function clicked(event)
{
// TODO: Fill in here. Use event.target.
// TODO: Display an alert containing the id of the clicked div
}
</script>
</head>
<body></body>
</html>
Tested by firefox
<html><head>
<script>
document.body.innerHTML = '<div id="42" onclick="clicked(event)">1</div><div id="43" onclick="clicked(event)">2</div><div id="44" onclick="clicked(event)">3</div>';
function clicked(event)
{
// TODO: Fill in here. Use event.target.
// TODO: Display an alert containing the id of the clicked div
var obj = event.srcElement || event.target;
alert(obj.id);
}
</script>
</head>
<body></body>
</html>
- Rewrite the code below using DOM or jQuery calls instead of using innerHTML. If using jQuery, it will be considered accessible in the $ variable.
<html><head>
<script>
document.body.innerHTML = '
<div id="42" onclick="clicked(event)">1</div>
<div id="43" onclick="clicked(event)">2</div>
<div id="44" onclick="clicked(event)">3</div>';
function clicked(event)
{
// TODO: Fill in here. Use event.target.
// TODO: Display an alert containing the id of the clicked div
}
</script>
</head>
<body></body>
</html>
<script>
document.body.innerHTML = '
<div id="42" onclick="clicked(event)">1</div>
<div id="43" onclick="clicked(event)">2</div>
<div id="44" onclick="clicked(event)">3</div>';
function clicked(event)
{
// TODO: Fill in here. Use event.target.
// TODO: Display an alert containing the id of the clicked div
}
</script>
</head>
<body></body>
</html>
Tested by firefox
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iframe Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<style type="text/css">
A:link {text-decoration: none}
A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {font-size:24; font-weight:bold; color: red;}
</style>
<body>
<ul class="nav">
<li class="first"><a href="#">item 0</a></li>
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
<li><a href="#">item 3</a></li>
<li><a href="#">item 4</a></li>
</ul>
</body>
</html>
- Write a jQuery module that provides the following methods for setting CSS border properties:
$('#foo').border('1px solid blue');
$('#foo').border({width: '2px', color: 'red', radius: '1px'});
$('#foo').border(null);
$('#foo').border(); // Returns the value of the border property
$('#foo').border({width: '2px', color: 'red', radius: '1px'});
$('#foo').border(null);
$('#foo').border(); // Returns the value of the border property
Tested by firefox
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
A:link {font-size:24; font-weight:bold; color: red;}
</style>
</head>
<body>
<table>
<th>
<ul>
<li><a href="#">Bullet 1</a></li>
<li><a href="#">Bullet 2</a></li>
<li><a href="#">Bullet 3</a></li>
</ul>
</th>
<tr>
<td><p>test1</p></td>
<td><p>test2</p></td>
<td><p>test3</p></td>
<td><p>test4</p></td>
</tr>
</table>
</body>
</html>
- Code a slideUpAndOut(elem) javascript function that makes an element disappear by sliding upwards and out of the page, without altering the layout and positioning of other elements in the page.
Tested by firefox
<!doctype html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js">
</script>
<script type="text/javascript">
function slideUpAndOut(elem){
if($("#" + elem).is(":hidden"))
$("#" + elem).slideDown('slow');
else
$("#" + elem).slideUp('slow');
}
</script>
</head>
<body>
<div id="slide-text">
<p>paragraph will disappear by sliding upwards and out of the page </p>
</div>
<button onClick="slideUpAndOut('slide-text')">Slide Paragraph</button>
</body>
</html>
<!doctype html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js">
</script>
<script type="text/javascript">
function slideUpAndOut(elem){
if($("#" + elem).is(":hidden"))
$("#" + elem).slideDown('slow');
else
$("#" + elem).slideUp('slow');
}
</script>
</head>
<body>
<div id="slide-text">
<p>paragraph will disappear by sliding upwards and out of the page </p>
</div>
<button onClick="slideUpAndOut('slide-text')">Slide Paragraph</button>
</body>
</html>
- In an XHTML document, when should you use class vs id attributes?
IDs can be used once
but classes can be used multiple times.ID is more specific. You can
use multiple classes to style an HTML element but you can only use
one ID when styling an HTML element.Classes are useful to apply
similar declarations to a variety of elements.
Should you use ID or class?
http://css.maxdesign.com.au/selectutorial/advanced_idclass.htm
The Difference Between ID and Class
http://css-tricks.com/the-difference-between-id-and-class/
When should I use a class and when should I use an ID?
http://css-discuss.incutio.com/wiki/Classes_Vs_Ids
- Explain what the following code means:
a:hover { font-weight: bold; }
A:hover
Defines the style for hovered links. A link is hovered when the mouse moves over it. font-weight: bold is used for font formatting.
Defines the style for hovered links. A link is hovered when the mouse moves over it. font-weight: bold is used for font formatting.
- In CSS2, how would you select all of the text fields of a form? What do you need to do for it to work in IE6?
This can be used.
input[type=text]
{
//css
rules
}
To comply with IE6.
IE7.js is a
JavaScript library to make Microsoft Internet Explorer behave like a
standards-compliant browser. It fixes many HTML and CSS issues and
makes transparent PNG work correctly under IE5 and IE6.
http://code.google.com/p/ie7-js/
Is there a way in CSS to select all input elements of type text?
http://stackoverflow.com/questions/5789975/select-all-text-boxes-in-css
http://stackoverflow.com/questions/4113965/css-selector-for-text-input-fields
- What differences are there between absolute and relative positionings?
Absolute positioning
This is a very
powerful type of positioning that allows you to literally place any
page element exactly where you want it. You use the positioning
attributes top, left bottom and right to set the location. These
values will be relative to the next parent element with relative (or
absolute) positioning
Relative positioning
A relative
positioned element is positioned relative to its normal position. The
content of a relatively positioned elements can be moved and overlap
other elements, but the reserved space for the element is still
preserved in the normal flow.
What are the differences between absolute and relative positioning?
http://www.phpmind.com/blog/2010/09/what-are-the-differences-between-absolute-and-relative-positioning/
- Write the code for a javascript-less CSS menu interface. The interface (a “menubar” of sorts) will have two menus, the first with 3 elements, the second with 10 elements. It must work in Google Chrome or any webkit based browser. The choice of presentation is open, but must be well argued.
Tested by google chrome and
safari
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#menu-bar {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
height: 24px;
line-height: 100%;
border-radius: 0px;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
box-shadow: 2px 2px 0px #666666;
-webkit-box-shadow: 2px 2px 0px #666666;
-moz-box-shadow: 2px 2px 0px #666666;
background: #8B8B8B;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#A9A9A9, endColorstr=#7A7A7A);
background: -webkit-gradient(linear, left top, left bottom, from(#A9A9A9), to(#7A7A7A));
background: -moz-linear-gradient(top, #A9A9A9, #7A7A7A);
border: solid 0px #6D6D6D;
}
#menu-bar li {
margin: 0px 6px 0px 0px;
padding: 0px 0px 0px 0px;
float: left;
position: relative;
list-style: none;
}
#menu-bar a {
font-weight: bold;
font-family: arial;
font-style: normal;
font-size: 12px;
color: #E7E5E5;
text-decoration: none;
display: block;
padding: 8px 20px 8px 20px;
margin: 0;
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
text-shadow: -20px -20px 0px #000000;
}
#menu-bar .current a, #menu-bar li:hover > a {
background: #0399D4;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#EBEBEB, endColorstr=#A1A1A1);
background: -webkit-gradient(linear, left top, left bottom, from(#EBEBEB), to(#A1A1A1));
background: -moz-linear-gradient(top, #EBEBEB, #A1A1A1);
color: #444444;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
text-shadow: 2px 2px 3px #FFFFFF;
}
#menu-bar ul li:hover a, #menu-bar li:hover li a {
background: none;
border: none;
color: #666;
-box-shadow: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
}
#menu-bar ul a:hover {
background: #0399D4 !important;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#04ACEC, endColorstr=#0186BA);
background: -webkit-gradient(linear, left top, left bottom, from(#04ACEC), to(#0186BA)) !important;
background: -moz-linear-gradient(top, #04ACEC, #0186BA) !important;
color: #FFFFFF !important;
border-radius: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
text-shadow: 2px 2px 3px #FFFFFF;
}
#menu-bar ul {
background: #DDDDDD;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#CFCFCF);
background: -webkit-gradient(linear, left top, left bottom, from(#FFFFFF), to(#CFCFCF));
background: -moz-linear-gradient(top, #FFFFFF, #CFCFCF);
display: none;
margin: 0;
padding: 0;
width: 185px;
position: absolute;
top: 30px;
left: 0;
border: solid 1px #B4B4B4;
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-webkit-box-shadow: 2px 2px 3px #222222;
-moz-box-shadow: 2px 2px 3px #222222;
box-shadow: 2px 2px 3px #222222;
}
#menu-bar li:hover > ul {
display: block;
}
#menu-bar ul li {
float: none;
margin: 0;
padding: 0;
}
#menu-bar ul a {
padding:10px 0px 10px 15px;
color:#424242 !important;
font-size:12px;
font-style:normal;
font-family:arial;
font-weight: normal;
text-shadow: 2px 2px 3px #FFFFFF;
}
#menu-bar ul li:first-child > a {
border-top-left-radius: 10px;
-webkit-border-top-left-radius: 10px;
-moz-border-radius-topleft: 10px;
border-top-right-radius: 10px;
-webkit-border-top-right-radius: 10px;
-moz-border-radius-topright: 10px;
}
#menu-bar ul li:last-child > a {
border-bottom-left-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
-moz-border-radius-bottomleft: 10px;
border-bottom-right-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
-moz-border-radius-bottomright: 10px;
}
#menu-bar:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#menu-bar {
display: inline-block;
}
html[xmlns] #menu-bar {
display: block;
}
* html #menu-bar {
height: 1%;
}
</style>
</head>
<body>
<ul id="menu-bar">
<li><a href="#">Menu 1</a>
<ul>
<li><a href="#">Sub Menu 1</a></li>
<li><a href="#">Sub Menu 2</a></li>
<li><a href="#">Sub Menu 3</a></li>
</ul>
</li>
<li><a href="#">Menu 2</a>
<ul>
<li><a href="#"> Sub Menu 1</a></li>
<li><a href="#"> Sub Menu 2</a></li>
<li><a href="#"> Sub Menu 3</a></li>
<li><a href="#"> Sub Menu 4</a></li>
<li><a href="#"> Sub Menu 5</a></li>
<li><a href="#"> Sub Menu 6</a></li>
<li><a href="#"> Sub Menu 7</a></li>
<li><a href="#"> Sub Menu 8</a></li>
<li><a href="#"> Sub Menu 9</a></li>
<li><a href="#"> Sub Menu 10</a></li>
</ul>
</li>
</ul>
</body>
</html>
- What does the following code mean? What does it display, and why?
<html><head><style>
#foo {
position:
relative; overflow: hidden; background-color: red;
top: 10px;
left: -50px; width: 100px; height: 100px;
}
div.bar {
position:
absolute; background-color: blue;
height:
50px; width: 75px; bottom: 0px; right: -30px;
}
.foo {
float:
right; background-color: green;
width: 30px;
height: 30px; margin: 10px 0 30px;
}
span {
background-color: black; width: 50px; height: 400px;
}
</style></head>
<body>
<div id=”foo”>
<div
class=”bar”></div><div
class=”foo”></div><span></span>
</div>
</body></html>
In IE9 page spans
black block on the left side of the web page.In mozilla chroma and
safari page is blank
I tested like below
<div id=”foo”>
<div
class=”bar”>test1</div>
<div
class=”foo”>test2</div>
<span>test3</span>
</div>
Aim is to
position div tags side by side.
Labels:
javascript
immutable class
- What is immutable class in Java
Immutable classes are those class, whose object can not be modified once created, it means any modification on immutable object will result in another immutable object. best example to understand immutable and mutable objects are, String and StringBuffer.
Since String is immutable class, any change on existing string object will result in another string e.g. replacing a character into String, creating substring from String, all result in a new objects.
While in case of mutable object like StringBuffer, any modification is done on object itself and no new objects are created.
Some times this immutability of String can also cause security hole, and that the reason why password should be stored on char array instead of String.
advantages
1) Immutable objects are by default thread safe, can be shared without synchronization in concurrent environment.
2) Immutable object simplifies development, because its easier to share between multiple threads without external synchronization.
3) Immutable object boost performance of Java application by reducing synchronization in code.
disadvantages
Since immutable object can not be reused and they are just a use and throw.
String being a prime example, which can create lot of garbage and can potentially slow down application due to heavy garbage collection
http://javarevisited.blogspot.com/2013/03/how-to-create-immutable-class-object-java-example-tutorial.html#ixzz2Mry69OKV
- What is immutable object? Can you write immutable object?
You can achieve same functionality by making member as non final but private and not modifying them except in constructor
Labels:
java interview questions
How to create and export PDF files in Java
- How to create and export PDF files in Java
There are lots of open source library that lets you play with the pdf files in java
http://mrbool.com/how-to-create-and-export-pdf-files-in-java/27343#ixzz2MrralrNH
Labels:
java interview questions
Apache POI
Apache POI - the Java API for Microsoft Documents
The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is your Java Excel solution (for Excel 97-2008)
http://poi.apache.org/
Labels:
opensource
JavaScript library
- Java Plugin Detector
http://www.pinlady.net/PluginDetect/Java/
- Browser Plugin Detection with PluginDetect
http://www.pinlady.net/PluginDetect/
A JavaScript library to make MSIE behave like a standards-compliant browser.
http://code.google.com/p/ie7-js/
Use the most advanced JavaScript debugger available for any browser
http://getfirebug.com/
YUI is a free, open source JavaScript and CSS library for building richly interactive web applications
http://yuilibrary.com/
The dynamic stylesheet language.
LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.
LESS runs on both the server-side (with Node.js and Rhino) or client-side (modern browsers only).
http://lesscss.org/
Rhino is an open source JavaScript engine. It is developed entirely in Java and managed by the Mozilla Foundation
en.wikipedia.org/wiki/Rhino_(JavaScript_engine)
- ie7-js
A JavaScript library to make MSIE behave like a standards-compliant browser.
http://code.google.com/p/ie7-js/
- Firebug
Use the most advanced JavaScript debugger available for any browser
http://getfirebug.com/
- YUI
YUI is a free, open source JavaScript and CSS library for building richly interactive web applications
http://yuilibrary.com/
- LESS
The dynamic stylesheet language.
LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.
LESS runs on both the server-side (with Node.js and Rhino) or client-side (modern browsers only).
http://lesscss.org/
- Rhino (JavaScript engine)
Rhino is an open source JavaScript engine. It is developed entirely in Java and managed by the Mozilla Foundation
en.wikipedia.org/wiki/Rhino_(JavaScript_engine)
Labels:
javascript
content management system
- Drupal
Drupal is an open source content management platform powering millions of websites and applications. It’s built, used, and supported by an active and diverse community of people around the world.
http://drupal.org/
- The Leading Open Source Portal for the Enterprise
Labels:
Systems and Networks
Wednesday, March 6, 2013
Memory safety
- Memory safety
Memory safety is a concern in software development that aims to avoid software bugs that cause security vulnerabilities dealing with random-access memory (RAM) access, such as buffer overflows and dangling pointers.
Computer languages such as C and C++ that support arbitrary pointer arithmetic, casting, and deallocation are typically not memory safe
Types of memory errors
Buffer overflow - Out-of bound writes can corrupt the content of adjacent objects, or internal data like bookkeeping information for the heap or return addresses.
Dynamic memory errors - Incorrect management of dynamic memory and pointers:
Dangling pointer - A pointer storing the address of an object that has been deleted.
Double frees - Repeated call to free though the object has been already freed can cause freelist-based allocators to fail.
Invalid Free - Passing an invalid address to free can corrupt the heap. Or sometimes will lead to an undefined behavior.
Null pointer accesses will cause an exception or program termination in most environments, but can cause corruption in operating system kernels or systems without memory protection, or when use of the null pointer involves a large or negative offset.
Uninitialized variables - A variable that has not been assigned a value is used. It may contain an undesired or, in some languages, a corrupt value.
Wild pointers arise when a pointer is used prior to initialization to some known state. They show the same erratic behaviour as dangling pointers, though they are less likely to stay undetected.
Out of memory errors:
Stack overflow - Occurs when a program runs out of stack space, typically because of too deep recursion.
Allocation failures - The program tries to use more memory than the amount available. In some languages, this condition must be checked for manually after each allocation.
Buffer overflow
A buffer is a temporary data storage area. Buffer overflow is the most common way for an attacker outside the system to gain unauthorized access to the target system. A buffer overflow occurs when a program tries to store more data in a buffer than it was intended to hold. Since buffers are created to contain a finite amount of data, the extra information can overflow into adjacent buffers, corrupting or overwriting the valid data held in them.It allows attacker to interfere into the existing process code. Attacker uses buffer or stack overflow to do following,
Overflow the input field, command line space or input buffer.
Overwrite the current return address on the stack with the address of the attacking code.
write a simple code that attacker wishes to execute.
http://en.wikipedia.org/wiki/Memory_safety
Labels:
programming languages
Type safety
- Type safety
In computer science, type safety is the extent to which a programming language discourages or prevents type errors.
A type error is erroneous or undesirable program behaviour caused by a discrepancy between differing data types for the program's constants, variables, and methods (functions), e.g., treating an integer (int) as a floating-point number (float).
some languages have type-safe facilities that can be circumvented by programmers who adopt practices that exhibit poor type safety
Type enforcement can be static, catching potential errors at compile time, or dynamic, associating type information with values at run-time and consulting them as needed to detect imminent errors, or a combination of both.
Type safety is closely linked to memory safety, a restriction on the ability to copy arbitrary bit patterns from one memory location to another. For instance, in an implementation of a language that has some type t, such that some sequence of bits (of the appropriate length) does not represent a legitimate member of t, if that language allows data to be copied into a variable of type t, then it is not type-safe because such an operation might assign a non-t value to that variable.
Conversely, if the language is type-unsafe to the extent of allowing an arbitrary integer to be used as a pointer, then it is clearly not memory-safe.
Type-safe code accesses only the memory locations it is authorized to access
(For this discussion, type safety specifically refers to memory type safety and should not be confused with type safety in a broader respect.)
For example, type-safe code cannot read values from another object's private fields.
Type safety is ultimately aimed at excluding other problems
Prevention of illegal operations. For example, we can identify an expression 3 / "Hello, World" as invalid, because the rules of arithmetic do not specify how to divide an integer by a string.
Memory safety
Wild pointers can arise when a pointer to one type object is treated as a pointer to another type. For instance, the size of an object depends on the type, so if a pointer is incremented under the wrong credentials, it will end up pointing at some random area of memory.
Buffer overflow - Out-of bound writes can corrupt the contents of objects already present on the heap. This can occur when a larger object of one type is crudely copied into smaller object of another type.
Logic errors originating in the semantics of different types. For instance, inches and millimeters may both be stored as integers, but should not be substituted for each other or added. A type system can enforce two different types of integer for them.
#include <iostream>
using namespace std;
int main()
{
int ival = 5; // A four-byte integer (on most processors)
void *pval = &ival; // Store the address of ival in an untyped pointer
double dval = *((double*)pval); // Convert it to a double pointer and get the value at that address
cout << dval << endl; // Output the double (this will be garbage and not 5!)
return 0;
}
/*
Even though pval does contain the correct address of ival,
when pval is cast from a void pointer to a double pointer the resulting double value is not 5,
but an undefined garbage value. On the machine code level,
this program has explicitly prevented the processor from performing the correct conversion from a four-byte integer to an eight-byte floating-point value.
When the program is run it will output a garbage floating-point value and possibly raise a memory exception.
Thus, C++ (and C) allow type-unsafe code.
*/
http://en.wikipedia.org/wiki/Type_safety
- Type safety means that the compiler will validate types while compiling, and throw an error if you try to assign the wrong type to a variable.
Some simple examples:
// Fails, Trying to put an integer in a string
String one = 1;
// Also fails.
int foo = "bar";
This also applies to method arguments, since you are passing explicit types to them:
int AddTwoNumbers(int a, int b)
{
return a + b;
}
If I tried to call that using: The compiler would throw an error, because I am passing a string ("5"), and it is expecting an integer.
int Sum = AddTwoNumbers(5, "5");
In a loosely typed language, such as javascript
function AddTwoNumbers(a, b)
{
return a + b;
}
Sum = AddTwoNumbers(5, "5");
Javascript automaticly converts the 5 to a string, and returns "55".
This is due to javascript using the + sign for string concatenation
To make it type-aware, you would need to do something like:
function AddTwoNumbers(a, b)
{
return Number(a) + Number(b);
}
Or, possibly:
function AddOnlyTwoNumbers(a, b)
{
if (isNaN(a) || isNaN(b))
return false;
return Number(a) + Number(b);
}
http://stackoverflow.com/questions/260626/what-is-type-safe
Labels:
programming languages
So What is hiberfil.sys Anyway?
- So What is hiberfil.sys Anyway?
Windows has two power management modes that you can choose from: one is Sleep Mode,The other is Hibernate mode, which completely writes the memory out to the hard drive, and then powers the PC down entirely, so you can even take the battery out, put it back in, start back up, and be right back where you were.
Hibernate mode uses the hiberfil.sys file to store the the current state (memory) of the PC,
http://www.howtogeek.com/howto/15140/what-is-hiberfil.sys-and-how-do-i-delete-it/
Labels:
windows interview questions
why does array index start from zero?
- why does array index start from zero?
To use a data item, you must calculate its correct address
Why do indexes of arrays start with zero?
The first location of an array is addressed by the pointer to the array.
Subsequent locations in the array are indicated by an offset from that pointer.
http://www.linkedin.com/groupItem?view=&gid=70526&type=member&item=218956807&commentID=123192360&report.success=8ULbKyXO6NDvmoK7o030UNOYGZKrvdhBhypZ_w8EpQrrQI-BBjkmxwkEOwBjLE28YyDIxcyEO7_TA_giuRN#commentID_123192360
- Here's some C code to explain the offsets a little better:
Code:
int array[3];
int* parray = &array;
int val0 = *(parray + 0); // 1st element (note the +0 is not required)
int val1 = *(parray + 1); // 2nd element
int val2 = *(parray + 2); // 3rd element
http://ubuntuforums.org/showthread.php?t=1275797
- Zero-based numbering
Advantages
One advantage of this convention is in the use of modular arithmetic as implemented in modern computers. Usually, the modulo function maps any integer modulo N to one of the numbers 0, 1, 2, ..., N - 1, where N = 1. Because of this, many formulas in algorithms (such as that for calculating hash table indices) can be elegantly expressed in code using the modulo operation when array indices start at zero.
A second advantage of zero-based array indexes is that this can improve efficiency under certain circumstances. To illustrate, suppose a is the memory address of the first element of an array, and i is the index of the desired element. In this fairly typical scenario, it is quite common to want the address of the desired element. If the index numbers count from 1, the desired address is computed by this expression:
a + s × (i - 1)
where s is the size of each element. In contrast, if the index numbers count from 0, the expression becomes this:
a + s × i
This simpler expression can be more efficient to compute in certain situations.
A third advantage is that ranges are more elegantly expressed as the half-open interval, [0,n), as opposed to the closed interval, [1,n], because empty ranges often occur as input to algorithms (which would be tricky to express with the closed interval without resorting to obtuse conventions like [1,0])
http://en.wikipedia.org/wiki/Zero-based_numbering
- It starts at 0 because the index value tells the computer how far it needs to move away from the starting point in the array.
if you use an array (without giving an index number in brackets), you are really only referring to the memory address of the starting point of the array
When you reference a specific value in the array, you are telling the programming language to start at the memory address of the beginning of the array and then move up the memory address as needed
lets say a program allocates space in the memory between address numbers 1024 and 2048 and it starts at 1024 and each item in the array is 8 bytes long
arrayName[0] is the same as telling it to look at the data stored at the memory address of (1024 + (0 * 8)), or 1024
If you want the value stored at arrayName[1], then it looks at the value held at (1024 + (1*8)), which is 1032
If you wanted the value held at arrayName[10], then it would look at the data stored in the memory address of 1024 + (10 * 8), which is 1104.
http://answers.yahoo.com/question/index?qid=20090528223815AACZDDY
- The discussion over why the array index should start at zero is not a trivial one and relates to interesting concepts from computer science.
First of all, it has strong relation to language design. For example in C, the name of an array is essentially a pointer, a reference to a memory location, and so the expression array[n] refers to a memory location n-elements away from the starting element.
This means that the index is used as an offset.
The first element of the array is exactly contained in the memory location that array refers (0 elements away), so it should be denoted as array[0]
http://developeronline.blogspot.com/2008/04/why-array-index-should-start-from-0.html
Labels:
programming languages
Tuesday, March 5, 2013
What is the difference between javac and the Eclipse compiler?
What is the difference between javac and the Eclipse compiler?
Eclipse's built-in compiler is based on IBM's Jikes java compiler.
(Note that Eclipse also started its life at IBM).
It is completely independent of Sun's Java compiler in the JDK;
Another difference is that the Eclipse Compiler allows for incremental builds from within the Eclipse IDE, i.e. all code is compiled as soon as you finish typing.
The fact that Eclipse comes with its own compiler is also apparent because you can write, compile, and run Java code in Eclipse without even installing the Java SDK.
Few examples where ECJ is preferred over javac - Apache Tomcat uses ECJ to compile JSPs, IntelliJ IDEA has support ECJ, as of GCJ 4.3, GCJ integrates with ECJ, Liferay Builds with ECJ
An incremental Java compiler. Implemented as an Eclipse builder, it is based on technology evolved from VisualAge for Java compiler. In particular, it allows to run and debug code which still contains unresolved errors.
http://stackoverflow.com/questions/3061654/what-is-the-difference-between-javac-and-the-eclipse-compiler
Labels:
java interview questions
how to compile java file without javac command?
how to compile java file without javac command?
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int result = compiler.run(null, null, null, "yourClass.java");
The compiler is a command line tool but can also be invoked using the Java Compiler API.
The compiler accepts source code defined by the Java Language Specification (JLS) and produces class files defined by the Java Virtual Machine Specification (JVMS)
http://docs.oracle.com/javase/7/docs/technotes/guides/javac/index.html
- ECJ - Eclipse Compiler for Java
Eclipse provides and uses its own compiler that is not javac
The Eclipse compiler is used inside the IDE (Eclipse)
The Eclipse compiler can also be used as a pure batch compiler outside of Eclipse
- OpenJDK is the only open-source Java SE implementation
http://openjdk.java.net
- The GNU Compiler for the JavaTM Programming Language
GCJ is a portable, optimizing, ahead-of-time compiler for the Java Programming Languag
http://gcc.gnu.org/java/
Labels:
java interview questions
Wireless Networks
- How to Secure Your Wireless Network
Securing Your Wireless Network
Encryption scrambles the information you send over the internet into a code so
Two main types of encryption are available: Wi-Fi Protected Access (WPA) and Wired Equivalent Privacy (WEP).
Your computer, router, and other equipment must use the same encryption.
WPA2 is strongest
Secure Your Computer and Router
Use anti-virus and anti-spyware software, and a firewall
Change the name of your router from the default.
The name of your router (often called the service set identifier or SSID) is likely to be a standard
Change the name to something unique that only you know.
Change your router's pre-set password. The manufacturer of your wireless router probably assigned it a standard default password that allows you to set up and operate the router
Limit Access to Your Network
Allow only specific computers to access your wireless network.
Wireless routers usually have a mechanism to allow only devices with particular MAC addresses to access to the network.
Some hackers have mimicked MAC addresses
Turn off your wireless network when you know you won't use it.
Don’t Assume That Public Wi-Fi Networks Are Secure
Be cautious about the information you access or send from a public wireless network.
Many
These "hot spots" are convenient, but they may not be secure.
You can be confident a hotspot is secure only if it asks you to provide a WPA password. If you're not sure, treat the network as if it were unsecured.
Protect Yourself When Using Public Wi-Fi
When using a Wi-Fi hotspot, only log in or send personal information to websites
Don’t stay permanently signed in
Do not use the same password on different websites. It could give someone who gains access to one of your accounts access
If you regularly access online accounts through Wi-Fi hotspots, use a virtual private network (VPN)
Installing browser add-ons or plug-ins can help, too.
For example, Force-TLS and HTTPS-Everywhere are free Firefox
http://www.onguardonline.gov/articles/0013-securing-your-wireless-network
- SSID - Service Set Identifier
An SSID is the name of a wireless local area network (WLAN).
All wireless devices on a WLAN must
A network administrator often uses a public SSID, that
Some newer wireless access points disable the automatic SSID broadcast feature
Also Known As: Service Set Identifier, Network Name
http://compnetworking.
- How to Secure Your Wireless Network
The first line of defense for your Wi-Fi network is
Make sure you change the default network name and password on your router
The firewall built into your router prevents hackers on the Internet from getting access to your PC
For extra protection,
How can I secure my notebook at public Wi-Fi hotspots?
Verify that
Never send bank passwords, credit card numbers, confidential e-mail, or other sensitive data unless you're sure you're on a secure site
The best way to protect a public wireless link is by using a virtual private network, or VPN.
VPNs keep your communications safe by creating secure "tunnels" through which your encrypted data travels.
Many companies provide VPN service to their mobile and offsite workers,
http://www.pcworld.com/article/130330/article.html
- Wireless Encryption - WEP, WPA,WPA2
WEP.
Each packet of the Encryption has 24bits Initialization vector. Which unfortunately done in plaintext.
WPA
It is an interim solution that is used now until 802.11i comes out.
http://www.ezlan.net/wpa_wep.html
- WPA
Implements the majority of IEEE 802.11i
TKIP vs. AES-based CCMP
Defines the algorithm used for message integrity and confidentiality.
WPA was designed to be used with TKIP (and WPA2 designed to use stronger AES-based).
WPA2, aka 802.11i
Fully conforms with 802.11i as it implements all mandatory features.
EAP options
Authentication options for 802.11i
AES-based CCMP
WPA2 mandates AES-based CCMP for message integrity and confidentiality.
TKIP (weaker) is optional.
WEP
WEP was supposed to provide Confidentiality, but has found to be vulnerable and should no longer be used
https://learningnetwork.cisco.com/thread/11207
- wpa2 vs wpa2/wpa mixed mode
In mixed mode you can connect with WPA/TKIP and WPA2/AES
TKIP is not as secure as AES.Use AES only if possible.
when to use mix mode?
some older wireless clients are WPA/TKIP only which may leave you no choice but use mixed mode.
802.11n only supports AES for speeds higher than 54 Mbit/s
WPA and WPA2 mixed mode operation permits the coexistence of WPA and WPA2 clients on a common SSID
WPA2 is the next generation of Wi-Fi security
Wi-Fi Alliance's interoperable implementation of the ratified IEEE 802.11i standard.
It implements Advanced Encryption Standard (AES) encryption algorithm using Counter Mode with Cipher Block Chaining Message Authentication Code Protocol (CCMP)
http://community.linksys.com/t5/Wireless-Routers/wpa2-security-vs-wpa2-wpa-mixed-mode/td-p/469610
- WPA2 vs WPA for Wireless Security
newer version of Wireless Protected Access (WPA) security and access control technology for Wi-Fi wireless networking
It is designed to improve the security of Wi-Fi connections by requiring use of stronger wireless encryption than what WPA requires
WPA2 does not allow use of an algorithm called TKIP (Temporal Key Integrity Protocol) that has known security holes
http://compnetworking.about.com/b/2010/01/06/wpa2-vs-wpa-for-wireless-security.htm
WPA vs WPA2 (802.11i)
How your Choice Affects your Wireless Network Security
WPA still relies on the RC4 encryption algorithm and TKIP (Temporary Key Integrity Protocol)
the new 802.11i standard, also known as WPA2 by the WiFi Alliance.
What is 802.11i?
802.11i uses the concept of a Robust Security Network (RSN).
802.11i allows for various network implementations and can use TKIP, but by default RSN uses AES (Advanced Encryption Standard) and CCMP (Counter Mode CBC MAC Protocol) and it is this which provides for a stronger, scalable solution.
What is AES/CCMP?
Advanced Encryption Standard (AES) is the cipher system used by RSN.
It is the equivalent of the RC4 algorithm used by WPA.
However the encryption mechanism is much more complex and does not suffer from the problems associated with WEP.
AES is a block cipher, operating on blocks of data 128bits long
CCMP is the security protocol used by AES.
It is the equivalent of TKIP in WPA
http://www.openxtra.co.uk/articles/wpa-vs-80211i#ixzz2MfcPtrdb
- Wardriving
Wardriving is the act of searching for Wi-Fi wireless networks by a person in a moving vehicle, using a portable computer, smartphone or personal digital assistant (PDA).
http://en.wikipedia.org/wiki/Wardriving
- Originally the Authentication and Privacy mechanisms for Wi-Fi were very weak. The standard
had a simple option to provide encryption called Wired Equivalent Privacy WEP. WEP used a
key to encrypt traffic using the RC4 keystream. However, someone could compromise WEP
fairly quickly if they had the right tools and a reasonably powerful machine
Wi-Fi Protected Access WPA.
It added extra security features, but retained the RC4 algorithm, which made it easy for users to
upgrade their older devices. However, it still didn’t solve the fundamental security problem
new standard, based on the Advanced Encryption Standard AES, algorithm from the National
Institute of Standards and Technology NIST, was also introduced as Wi-Fi Protected Access 2
WPA2
new enterprise-grade authentication
was added to the technology, creating two flavors of each security style. The personal level of
security continued to use a Shared passphrase for network authentication and key exchange.
The enterprise level of security used 802.1x authentication mechanisms, similar to those used
on wired networks, to authenticate users and set up encryption. However, poorly chosen or
weak passphrases could still leave networks vulnerable
Released in 2018, Wi-Fi Protected Access 3 (WPA3) introduced a new, more secure handshake
for making connections, an easier method for adding devices to the network, increased key
sizes, and other security features
https://training.fortinet.com/pluginfile.php/1624883/mod_scorm/content/1/story_content/external_files/NSE%202%20WiFi%20Script_EN.pdf
Labels:
security
Subscribe to:
Posts (Atom)