Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
Yeah, the Sun Java tutorial mentions not using floats for precision values (turns out apparently even double data types should not be used for precision [in this case, they keep referring to currency as an example] - there is a java.math.BigDecimal class for that purpose) For your example, I think you mean double foo = 1.5; (when delcaring a float type, it requires 'f' postfixing to the value). Hmm... yeah, this will work: daniel@daniel-laptop:~/test$ cat Test.java public class Test { public static void main(String[] args) { float foo = (float) 1.5; System.out.println(foo); } } daniel@daniel-laptop:~/test$ javac Test.java daniel@daniel-laptop:~/test$ java Test 1.5 To be honest though, just use double instead of float. Floats and doubles are only approximative data types anyway. Here is a funny example illustrating this: - load "Math"; > val it = () : unit - val x = Math.log10 1000.0; > val x = 3.0 : real - floor 3.0; > val it = 3 : int - floor x; > val it = 2 : int - x = 3.0; > val it = false : bool That is in Standard ML, specifically the MoscowML implementation. The "bug" is that it computes log(1000) to 2.99999999...9 (lots of nines) and rounds it for display, but when I ask it to floor the number, it correctly rounds down to 2.0.
-
I just hate the people who whine about other people's choice of weapon. I fail to see how it's more noobish using a grenade launcher as opposed to a sniper rifle, tactical knife or assault rifle.
-
uses colors within PHP block.
-
And how would you imagine this would work when they don't even share the same table structure?
-
A real database will be better. It'll support concurrent writes better because if the table is locked, it'll just queue queries like this: UPDATE files SET downloads=downloads+1 WHERE id=42; If you are writing to a file you risk getting incorrect results with many concurrent requests. If you are concerned about making too many writes to the database, you can use something like APC to cache download counts and only write the changes to the database every 10 minutes for instance.
-
I vote for left.
-
It's because the standard data type for representing floating point numbers in Java is called double. If you want to use float, which has only got half the precision, you'll have to explicitly specify that. However, if you do something like this: float foo = 1.5; it will work as well.
-
JavaScript Minification what are your opinions on it?
Daniel0 replied to Ninjakreborn's topic in Miscellaneous
Sounds like you guys need an actual build system instead of just FTP'ing stuff to your web host. Take a look at tools like phing, ant or make (though I probably wouldn't use make). -
How does Windows manage to address a memory address above 2^32 with a 32-bit pointer? How does it manage to say "yo, your shit is at 0x400000FF8F" when it cannot even represent an integer so large? Utilize, Not assign. It doesn't answer my question though. How does it move whatever is in e.g. 0x400000FF8F into one of the CPU registers when the largest number it knows is 0xFFFFFFFF. I don't really see how you differentiate 'utilize' and 'assign' here. What good is utilizing memory if it cannot be assigned to anything?
-
You're talking a lot about what is incorrect. How about telling me what would be the correct output? Try this: $text = urlencode(preg_replace('#[\W\d]#', '', $text));
-
Well, either you are escaping it twice or you're running with magic quotes turned on. Just escape it when you need it. It's bad practice making global changes anyway.
-
Obviously your script consists of more code than that. How about the code where you actually execute the query?
-
No, I can't explain what you're doing wrong besides what I just told you. I'm visiting some family during the holidays and I left my crystal ball at home. Somehow you are doing something that is resulting in double escaping. You may be calling things like mysql_real_escape_string() multiple times, or you have magic quotes turned on which means either 1) you're running PHP 4, in which case you should upgrade, or 2) you turned it on manually, in which case I have no idea why you would do that.
-
Well, that's because you're urlencode'ing it. \W excludes digits as well, so if you want you can go back and replace \d with nothing again.
-
If echo doesn't work it's probably because a fatal error is occurring before it. Check your error log or enable display_errors.
-
That's because you're escaping them twice.
-
SVN, git, mercurial, etc. Tools like the aforementioned are sometimes collectively called VCS (version control systems).
-
Seems to work fine for me... What exactly do you want? What did you expect as output? The code does exactly what it says. It'll replace any non-word characters as defined by the tr_TR locale with nothing and then encode the entire URL.
-
$text = urlencode(preg_replace('#\W#', '', $text)); http://php.net/manual/en/regexp.reference.backslash.php
-
You can type hint non-scalar parameter types. It'll result in a run-time fatal error if a non-matching type is given. You could write an RFC at http://wiki.php.net (and send it to the internals list) to have what I believe Java calls automatic boxing and unboxing. This would allow you to pass e.g. primitives like ints to an SplInt without having to do new SplInt(42).
-
Regex #1 does this: Nothing at the start matches "anything", can I still do that? Yes, the 'a' matches, can I still match anything, yeah the 'b' does. It continues to do that all the way until: can I still match anything, yes, the 'i' matches. Then it finally checks, can I match 'i'? Nope, so I'll go back one step. Now can I match 'i'? Yes. Done. Regex #2 does this: Can I match anything 0 or more times? Yes, the nothing at the start matches that. Now does 'i' match? No, okay then I'll try matching .*? again which 'a' does. Now does 'i' match? Not yet, but 'b' matches. It does all that until it has matched 'h'. At that point 'i' matches, the regex has ended and the engine tells you there is a match.
-
Set the correct locale using set_locale and use \W. Otherwise just specify the characters manually in your character class.
-
You can use trigger_error to raise E_USER_* errors. Aside from that, you cannot use PHP's error handling system.
-
You'd want to upgrade the memory at least. Seeing as it's so cheap, you might as well get 4 GB if your motherboard supports it.