Tuesday, 10 September 2013

Adding an signed integer beyond 0xFFFFFFFF

Adding an signed integer beyond 0xFFFFFFFF

#include <stdio.h>
void fun3(int a, int b, int c)
{
printf("%d \n", a+b+c );
}
void fun2 ( int x, int y)
{
fun3(0x33333333,0x30303030, 0x31313131);
printf("%d \n", x+y);
}
fun1 (int x)
{
fun2(0x22222222,0x20202020);
printf("%d \n", x);
}
main()
{
fun1(0x1111111);
}
I'm going through the above program for stack corruption. I am getting the
o/p for the above program with some undesired values. All I could
understand is if the added value is beyond 0xFFFFFFFF then the small
negative integer becomes the largest value say -1 becomes 0xFFFFFFFF. Any
insights on this

Is it possible to move pages from one Module to other Module

Is it possible to move pages from one Module to other Module

I have a fully developed WPF/PRISM Application. There are four modules in
it with separate regions for each of the four modules. There is a new
requirement as to move some of the pages from each of the modules to a
separate module. Now, I have created a separate module in the application.
But have not started moving the pages from one module to this new module.
Can someone tell me the challenges involved in this task? I am not sure of
this as this is my first task in PRISM Application.

Redraw jQuery Mobile button icons in iOS Safari

Redraw jQuery Mobile button icons in iOS Safari

I'm only having this problem in iOS Safari and not other webkit browsers
(such as Chrome). Occasionally, when I trigger a change on a .ui-radio or
.ui-checkbox input, the element does not get redrawn so you cannot tell
that your change has taken effect. Any other operation (scrolling,
clicking another button, or even touching the screen) will suddenly force
the redraw necessary to make the updated element appear. It seems like
jQuery mobile removes and adds these elements when changing how they look.
I've seen several explanations of what I believe is this problem as well
as possible solutions:
http://mir.aculo.us/2009/09/25/force-redraw-dom-technique-for-webkit-based-browsers/
http://mir.aculo.us/2009/01/11/little-javascript-hints-episode-3-force-redraw/
How can I force WebKit to redraw/repaint to propagate style changes?
My current solution is something like:
$(".actual-input").on("change", function () {
setTimeout(function () {
var elem = $(this).next("label").find(".ui-icon").get(0),
dsp = elem.style.display,
txt = document.createTextNode(' ');
elem.appendChild(txt);
elem.style.display = "none";
setTimeout(function () {
elem.style.display = dsp;
txt.parentNode.removeChild(txt);
}, 200);
}.bind(this), 200);
});
The initial setTimeout is because the updated element seems to get
appended after the change event completes, so I can't find another way to
capture the element I want to redraw. With the above I can visibly see the
element flicker (and if I remove display = dsp, the element will not
reappear), however there are still times where nothing appears to redraw
(even if I don't display the element again). There doesn't seem to be any
consistency about it either.

Wordpress "two contents" split up by border

Wordpress "two contents" split up by border

I'm programming a new website for a customer based on wordpress. I got 4
pages. In 2 pages I have to seperate the content by a border. Like this:
So on top I got the text by Wordpress editor in backend and on bottom I
got in this image a slideshow, but sometimes there is more text. And every
text on the website should be able to edit by the customer in wordpress so
he don't have to go to source code. But I don't have any idea how I should
go on. Have someone an idea or a hint how I can go on?
Thanks in advance
Cheers

Efficient table structure or indexing for searchable IP address ranges in SQL

Efficient table structure or indexing for searchable IP address ranges in SQL

I have raw data provided to me for a geolocation service, in the form of a
table of IP address ranges mapped to location data.
The addresses are provided as byte-packed integers (one dotted-quad per
byte), permitting easy storage and comparisons, so each row in this table
provides a range low address, a range high address, and some text location
fields. I don't have to/am not able to use CIDR.
The table is several million records.
I don't have strong SQL chops. The code I inherited simply does a sql call
like:
SELECT location FROM geodata WHERE lookup_address >= range_low AND
lookup_address =< range_high
The performance is terrible. My understanding is that this will simply do
a linear search for matching records. To get around this temporarily I
have thrown together a client cache into a tree map to bring this down to
log performance, but a) my memory usage is now hard to justify, and b)
detecting live database updates is a problem I don't really want to tackle
right now.
It seems like this problem must come up now and then in the SQL world for
addresses, telephone numbers, etc.. Is there a "standard" way to organize
and index ranges in a SQL table so that I can get at least log performance
out of a direct SQL query?

How to check host connection with internet connection

How to check host connection with internet connection

I want to full check connection to internet and a domain or host. I used a
method to check internet connection, but i can not add checking host
availability. My code is here;
public class InternetCheck{
public static boolean isInternetAvailable(Context context)
{
NetworkInfo info = (NetworkInfo) ((ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info == null){
Constants.connectionProblem = "Check your internet connection";
return false;
}
else{
return true;
}
}
}
I want to add host or domain availability check inside of
isInternetAvailable() method. It must return false and set
Constant.connectionProblem = "Host is not available" . Because, i will
call that method on my main activity and if it returns false, i will show
a Toast which shows that Constants.connectionProblem .

Monday, 9 September 2013

Can't get bubble sort to work w/ comparing object properties

Can't get bubble sort to work w/ comparing object properties

For an array of books, the assignment is to get attributes of the objects
from the user, then sort based on their choice of author, title, or page
count. My bubble sort is working for the page count but not when the user
chooses author or title, so I'm guessing I'm missing something with
reference storage vs. value storage, maybe? Thanks!
import javax.swing.*;
import java.util.*;
public class LibraryBookSort {
public static void main(String[] args) {
LibraryBook[] books = new LibraryBook[5];
LibraryBook tempBook = new LibraryBook();
String enteredAuthor = "", enteredTitle = "";
String enteredPageCount;
String sortBy;
String displayString = "";
int parsedSortBy;
int parsedPageCount;
int booksLength = books.length;
// populate the array
for (int x = 0; x < booksLength; ++x)
books[x] = new LibraryBook();
// get property values from user
for (int x = 0; x < booksLength; ++x)
{
enteredTitle = JOptionPane.showInputDialog(null, "Enter book " +
(x + 1) + " of 5's title:");
books[x].setTitle(enteredTitle);
enteredAuthor = JOptionPane.showInputDialog(null, "Enter book " +
(x + 1) + " of 5's author:");
books[x].setAuthor(enteredAuthor);
enteredPageCount = JOptionPane.showInputDialog(null, "Enter book "
+ (x + 1) + " of 5's page count:");
parsedPageCount = Integer.parseInt(enteredPageCount);
books[x].setPageCount(parsedPageCount);
}
// sort by property values
sortBy = JOptionPane.showInputDialog("Choose option to sort by: (1)
title, (2) author, or (3) page count");
parsedSortBy = Integer.parseInt(sortBy);
while (parsedSortBy < 1 || parsedSortBy > 3)
{
sortBy = JOptionPane.showInputDialog("Invalid selection, please
choose option to sort by: (1) title, (2) author, or (3) page
count");
parsedSortBy = Integer.parseInt(sortBy);
}
if (parsedSortBy == 1)
{
for (int a = 0; a < booksLength - 1; ++a)
{
for (int b = 0; b < booksLength - 1; ++b)
{
if (books[b].getTitle().compareTo(books[b+1].getTitle()) > 1)
{
tempBook = books[b];
books[b] = books[b+1];
books[b+1] = tempBook;
}
}
}
}
else if (parsedSortBy == 2)
{
for (int a = 0; a < booksLength - 1; ++a)
{
for (int b = 0; b < booksLength - 1; ++b)
{
if (books[b].getAuthor().compareTo(books[b+1].getAuthor())
> 1)
{
tempBook = books[b];
books[b] = books[b+1];
books[b+1] = tempBook;
}
}
}
}
else
{
for (int a = 0; a < booksLength - 1; ++a)
{
for (int b = 0; b < booksLength - 1; ++b)
{
if (books[b].getPageCount() > books[b+1].getPageCount())
{
tempBook = books[b];
books[b] = books[b+1];
books[b+1] = tempBook;
}
}
}
}
for (int i = 0; i < booksLength; ++i)
{
displayString += (books[i].getTitle() + ", by " +
books[i].getAuthor() + ". " + books[i].getPageCount() + "
pages.\n");
}
JOptionPane.showMessageDialog(null, "Books sorted by your choice:\n\n"
+ displayString);
}
}