Archive for the ‘Uncategorized’ Category
GoogleAPI’s hosting of jQuery 1.3.2 didn’t load on Firefox for me today, but was fine on IE8 and Chrome. Specifically this link: http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js would result in a “Firefox could not find the file at…” page. Surprisingly, all other versions of jQuery that they are hosting were working. Clearing my FF cache seemed to solve this. Wonder what was the actual problem?
These are some very helpful comments I came across from Stack Overflow. Thanks to Martin York and Adam Liss for providing these useful and concise comments.
Question 1: Float division
int a = 2, b = 3;
float c = static_cast(a) / b; // need to convert 1 operand to a float
Question 2: How the compiler works
Five rules of thumb to remember:
* Arithmetic operations are always performed on values of the same type.
* The result type is the same as the operands (after promotion)
* The smallest type arithmetic operations are performed on is int.
* ANSCI C (and thus C++) use value preserving integer promotion.
* Each operation is done in isolation.
The ANSI C rules are as follows:
Most of these rules also apply to C++ though not all types are officially supported (yet).
* If either operand is a long double the other is converted to a long double.
* If either operand is a double the other is converted to a double.
* If either operand is a float the other is converted to a float.
* If either operand is a unsigned long long the other is converted to unsigned long long.
* If either operand is a long long the other is converted to long long.
* If either operand is a unsigned long the other is converted to unsigned long.
* If either operand is a long the other is converted to long.
* If either operand is a unsigned int the other is converted to unsigned int.
* Otherwise both operands are converted to int.
Overflow is always a problem. Note. The type of the result is the same as the input operands so all the operations can overflow, so yes you do need to worry about it (though the language does not provide any explicit way to catch this happening.
As a side note:
Unsigned division can not overflow but signed division can.
std::numeric_limits::max() / -1 // No Overflow
std::numeric_limits::min() / -1 // Will Overflow
In general, if operands are of different types, the compiler will promote all to the largest or most precise type:
If one number is… And the other is… The compiler will promote to…
——————- ——————- ——————————-
char int int
signed unsigned unsigned
char or int float float
float double double
char + int ==> int
signed int + unsigned char ==> unsigned int
float + int ==> float
Beware, though, that promotion occurs only as required for each intermediate calculation, so:
4.0 + 5/3 = 4.0 + 1 = 5.0
This is because the integer division is performed first, then the result is promoted to float for the addition.
It can be a pain reaching up to the ESC key everytime to exit insert mode in VIm. An alternative that’s built-in by default is Ctrl+[
Forgive me for not being constructive and not submitting bugs to the devs and that sort of thing (I may later on…), but for now, I just have to let off some steam… and from the experience I’ve got using this application, I believe I have every right to!
So I was looking for Wordpad’s equivalent in Linux-world, and according to a post in the Ubuntu forums Abiword was it. So I apt-get install it, and try it out… (running Ubuntu 8.10)
1) I copy some text into the page… then I realize the font size is too big, so I Ctrl+A and highlight the “font size” box and replace the “12” with “10”… voila! the TEXT I selected gets replaced with “10” instead of the number in the “font size” field. Genius! So I guess I will just have to use the arrows to change font sizes…
2) Then I wanted to change the font. I look at the “font” bar, and there’s no way to type in it! I can’t even enter an ‘M’ to get to the fonts that start with ‘M’… I have to SCROLL through the 100 or so fonts on my system to find the one I want. This is not a bug per se, but c’mon!
3) Then I needed to paste in more text. I do so, then to look at the bottommost text I use my mousewheel to scroll all the way down. Good, its there. But… when I scroll back up, Abiword keeps slowly scrolling the screen down! I tried using my keyboard arrows and a bunch of other things to try to make it behave but it just wouldn’t quit. At this point I had no choice but to close the whole abomination.
Looks like I will just stick to the heavier OpenOffice for now. I am just in complete shock and awe that this software is in the Ubuntu repos and is classified as a “finished product”. It would be poor even if it was in beta. Lesson of the day: Beware of Abiword!
So I’ve been working on some AJAX stuff, dealing with Yahoo! Weather, specifically, and I realized I needed some way to make cross domain xmlhttprequests. Using a PHP Proxy seemed for me to be the easiest way to go, so I first tried what was suggested by Yahoo! I then tried some similar methods from others here and here, both to no avail. I then did some asking around on forums and made the necessary changes to make Yahoo’s example work. Just thought I’d share that with those of you who have similar troubles.
This is the PHP Proxy that I used. Note that:
- Your webserver’s PHP needs to support cURL
- This code doesn’t support POST requests, only GET.
<?php // PHP Proxy example for Yahoo! Web services. // Responds to both HTTP GET and POST requests // // Author: Jason Levitt // December 7th, 2005 //(Modified by Suan-Aik Yeo) $path = $_SERVER["QUERY_STRING"]; $url = $path; // Open the Curl session $session = curl_init($url); // Don't return HTTP headers. Do return the contents of the call curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Make the call $xml = curl_exec($session); // The web service returns XML. Set the Content-Type appropriately header("Content-Type: text/xml"); echo $xml; curl_close($session); ?>
var proxy_name = "phpProxy.php"; //proxy's filename var actualReq = "http://search.yahoo.com/blablabla?=...."; //actual request var myDomain = "www.domainName.com/location/"; //where your proxy file is placed var url = "http://"+myDomain+proxy_name+"/?"+actualReq; //go on to do the usual httprequest steps... httpRequest("GET",url,true,handleResponse); ... ...
Hope this helps!