Wednesday, April 11, 2012

Boost asio io_service dispatch vs post

Can anyone tell me the difference between io_service dispatch and post? It was not clear to me what is more suitable for my problem.



I need to invoke a handler inside another handler and I don't know what invoker to use.



Thanks.





How should I use Youtube API [closed]

How should I use youtube API?
I want to use youtube API to search a movie, such as Titanic and then play it in a web page. How should I do these using jsp?





Simple remove text script

this might be simple, but I've spent ages searching and googling, I've come close, but no cigar...



Is anyone able to whip me up a little script to delete all instances of



<a href="http://mysite.com/search?mode=results&amp;queries_name_query="></a>


in the body of a HTML doc?



My tags are generated by JS and they always print an extra blank href so hopefully another quick script to remove them can clear this up?



All help and helpful advice is always very much appreciated.





ruby regular expressions

I am trying to create a program where a user enters four numbers using regular expressions . If one of those numbers is 13 then the numbers to the left do not count toward the sum. My problem is creating an exception where none of the numbers equal 13. I cant seem to find a regular expression for my exception
thanks in advanced



puts "enter a number then hit enter four times"

number1 = STDIN.gets

number2 = STDIN.gets
number3 = STDIN.gets

number4 = STDIN.gets


if number1 =~ /13/ then
puts number2.to_i + number3.to_i + number4.to_i
end

if number2 =~/13/ then
puts number3.to_i + number4.to_i
end

if number3 =~/13/ then
puts number4.to_i
if number4 =~/13/ then
puts "0"
end
if number1 != 13 or number2 != 13 or number3 != 13 or number4 != 13
puts number1.to_i + number2.to_i + number3.to_i + number4.to_i
end
end




Multiple SimpleModals on one page

Newbie question I think, but maybe not... I am using SimpleModal for a project, and have a case where there are multiple triggers and modals on a page.



Page is here: http://lumetta.highchairdesign.com/newsite/lumenate-portfolio/linen



Markup for the trigger is like:



<a class="modalbutton" href="#item_31" title="D112 Sand"
style="background-image: url(/newsite/documents/gallery_photos/59.D112-Sand.jpg);">
</a>


Markup for the Modal is like:



<div id="#item_31" class="modal">
<h3>D112 Sand</h3>
<a href="javascript:;" class="lumenate_largethumb" style="background-image: url(/newsite/documents/gallery_photos/59.D112-Sand.jpg);">
</a>
</div>


Yes, I know it's odd, but the modal contains a sprite so that is why I am using an A with a background image...



My JS looks like:



$(".modalbutton").click(function (e) {

var iden = $(this).attr("href");

$("" + iden + "").modal( {
close: true
});
});


My JS is trying to figure out which link has been clicked, and inject it with the proper DIV. I get the click action, I get the modal container to appear, but the content does not get injected.



I tried quotes around the "iden" variable, I tried no quotes... doesn't help. I tried thedirect call to the modal action, which looks like $.modal( $( iden ), { etc..., no luck there. I tried passing the content div ID to the proper setting variable for SimpleModal, which is "dataId"... no dice.



I'm losing my mind and going to bed. This was supposed to be simple. Help?





Location vs GeoPoint vs 1E6 vs Charging

I am writing a location based App and want to get some wisdom on sensible API usage.



What I've understood so far is that working with int is more efficient. I'm going to need to store loads of them and do alot of distance calculations.



My app uses a Service that implements LocationListener and I am storing longitude & latitude as int values (micro-degrees) inside an SQL db (via ormlite) calculated thus ::



public static int degreesToMicroDegrees(double degrees){
return (int)(degrees * 1E6);
}


Sometimes I need to know when I have returned to a particular 'location' and as such I fetch the int values back out of the db to compare with the latest location update.



Question is, what is the best way to compare 'location' between the int values (where I used to be) and the double values (where I am now) in my latest Location update?



I have searched around for some Math to accomplish the distance calculation and found this ::



public static double distanceBetween(double lat1, double lng1, double lat2, double lng2) {

double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;

return dist;
}


I have tried passing my int values in like this :: ((double)myIntValue) / 1E6F
The returned distance values are confusing me. If I walk 100m my app sensibly tells me I've gone about 100m using Location.distanceTo(myLastLocation). But if I use the method above against my stored int values I get the value zero back.



If anyone can explain the E6 format that would be great.



1E6 is the same as 1000000 ?



Additionally I can see there is this GeoPoint class. I am hesitant to use this as I'm not clear if making vast numbers of calculations on GeoPoints is going to be charged for by Google. There seems to be some noise about charges for use of GoogleMaps APIs and I haven't been able to find a clear explanation of how that charging works.



All wisdom gratefully received.





How well do Tomahawk20 and Richfaces3.3.3.Final work together?

When i use Tomahawk20(Tomahawk20-1.1.11 for jsf-2.0) and Richfaces3.3.3.Final together, the tag of t:inputCalender can not work, the pop-up overlay can not displayed, and got javascript errors. I find that the function processEvent() can not work after adding richfaces, some javascript and css files can not include in the jsp page. After adding the js and css files manually, the t:inputCalender work, but tag of rich:pickList and rich:orderingList will not work both.