Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=KmartSqrl;44706114]If you are getting a number as a string, it probably came from user input or from somewhere other than your codebase (third party api, file, etc). What happens if a user types a large number and puts a comma every 3 digits...
[code]
"1,000" + 5 == 6
[/code]
That's [B]REALLY[/B] wrong.
If you want a string to be treated as a number, it should be explicit. There are too many edge cases, and PHP does not handle them well.
[editline]2nd May 2014[/editline]
Lol... PHP...
[code]
"0,125" == 0 -> true
0 == false -> true
"0,125" == false -> false
[/code][/QUOTE]
Try using the . (dot) instead of the , (comma) when doing arthimetics, because what's inside the code tag of yours, is not math in any way. There is no comma in math. 1,000 is not 1, it's considered 1000 (For humans, does not exist at all in computer mathematics because the , (comma) indicates it is a string.). While 1.000 is considered 1.
This
[CODE]
"0,125" == 0 -> true
[/CODE]
If you take a look and read what I stated earlier, PHP ignores everything after a non-mathematic character when performing artimetics on a string. In this case, the comma.
So basically, you asked PHP this:
[CODE]
"0" == 0 -> true
[/CODE]
This on the other hand produces false:
[CODE]
"0.125" == 0 -> false
[/CODE]
Here's another example:
[CODE]
"1,000" + 5 == 6
"1.000" + 5 == 6.000
[/CODE]
Excuse me for this, but before you go bashing PHP down into the ground by giving it math problems it can't solve, maybe you should get your math straight first? Who teached you the comma even exists in math? It is simply a placeholder for humans to make it more human read-able;
Instead of this:
1000000000000
We use this:
1,000,000,000,000
Are you dense? Read the post before you respond to it
[QUOTE=KmartSqrl;44706114]If you are getting a number as a string, it probably came from user input or from somewhere other than your codebase (third party api, file, etc). [B]What happens if a user types a large number and puts a comma every 3 digits...[/B][/QUOTE]
[editline]2nd May 2014[/editline]
Also, some countries swap the meaning of the . and , when used in numbers. There are nations that would use 1.000,50 to represent 1000.50.
[url]http://en.wikipedia.org/wiki/Decimal_mark#Countries_using_Arabic_numerals_with_decimal_comma[/url]
[editline]2nd May 2014[/editline]
Also also, the point of the
[code]
"0,125" == 0 -> true
0 == false -> true
"0,125" == false -> false
[/code]
bit was that PHP decides that "0,125" is equal to zero, and that zero is equal to false, which logically should mean that "0,125" is equal to false, but it isn't because PHP is high and doesn't reliably do the automatic string to number conversion at all.
[QUOTE=KmartSqrl;44706469]Also, some countries swap the meaning of the . and , when used in numbers.[/QUOTE]
Italy isn't a country.
[QUOTE=KmartSqrl;44706469]Are you dense? Read the post before you respond to it[/QUOTE]
No just bad at reading I guess. I apologize, my bad.
Most user input is sanitized and if a system expects integer from user input, I'm sure the system designer includes a replacement for that comma.
Either way, I'm just gonna call this argument/discussion off. You hate PHP, I don't. Now it's all settled.
This has nothing to do with whether or not I like PHP, it's just that this is a terrible "feature".
Would you prefer, when users enter numbers in to a system you're building, that it potentially silently fails and does something they weren't trying to do, or would you rather have an exception thrown and know something went wrong so you can show them a pretty error page, log the issue and fix it for real later?
[QUOTE=KmartSqrl;44704195]If you disagree with this you have not been using PHP long enough for something like this to bite you in the ass yet. Everything in this post is spot on.[/QUOTE]
Here's a good example of it [URL="http://phpsadness.com/sad/47"]doing just that[/URL].
[QUOTE=KmartSqrl;44706707]This has nothing to do with whether or not I like PHP, it's just that this is a terrible "feature".
Would you prefer, when users enter numbers in to a system you're building, that it potentially silently fails and does something they weren't trying to do, or would you rather have an exception thrown and know something went wrong so you can show them a pretty error page, log the issue and fix it for real later?[/QUOTE]
Definitely the latter, but I'd not want the feature completely removed. I wish that it would solely be able to do mathematics on string types if the string solely contains numbers and dots. If the stirng contains non-mathematic characters, throw exception. That would be the ultimate solution for me.
Either way, PHP has not let me down once during these 5 years of using it. I'm still getting amazed over the potential it brings.
I got a question about a project I'm working on. What I got right now is that you can double click on a "canvas" and enter some information such a message and a username. This data includes the coordinates of the click.
So the idea is that I repopulate this canvas with that same message on that exact coordinate. But what would be the best way to do that?
I was thinking of using CSS and create a style for each element, and use the absolute positioning that it allows. But that seems kinda stupid, and I'm not really sure if it'd work.
What other alternatives are there?
[QUOTE=Swebonny;44708679]I got a question about a project I'm working on. What I got right now is that you can double click on a "canvas" and enter some information such a message and a username. This data includes the coordinates of the click.
So the idea is that I repopulate this canvas with that same message on that exact coordinate. But what would be the best way to do that?
I was thinking of using CSS and create a style for each element, and use the absolute positioning that it allows. But that seems kinda stupid, and I'm not really sure if it'd work.
What other alternatives are there?[/QUOTE]
Draw it to the canvas with JS?
[QUOTE=supersnail11;44708815]Draw it to the canvas with JS?[/QUOTE]
Just to clarify for Swebonny, he is referring to the HTML <canvas> element, not just a generic white box used as a canvas
And yeah this would be a good way to do it
Does anyone with a google apps account for their domain mind going to [url]https://code.google.com/googleapps/console/a/(your[/url] domain) and seeing if it gives you an error when creating a project?
edit:
is agree yes its giving you an error
I don't really seem to understand Composer. I installed it, but do I really have to use SSH to install addons? But also the fact that if I have the PayPal REST API and PHPMailer, do I HAVE to include both? I don't seem to get it, so anyone who bothers to give me a Composer 101?
[t]http://lw2.co.uk/ewj.gif[/t]
my mmo is coming along nicely :rolleye:
I found a few scripts and combined them, all Node.js.
Basically, the following:
[code]var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8007});
var dgram = require('dgram'),
server = dgram.createSocket('udp4');
wss.broadcast = function(data) {
for(var i in this.clients) {
this.clients[i].send(data);
}
}
server.on('message', function (message, rinfo) {
var msg = message.toString('ascii').slice(30,-2);
console.log(msg);
wss.broadcast(msg);
});
server.on('listening', function () {
var address = server.address();
console.log('UDP Server listening ' + address.address + ':' + address.port);
});
server.bind(8006);[/code]
This script receives the log from SRCDS, then broadcasts it to all WebSocket users.
Now what the problem is, everyone who scans my ports would be able to find this WebSocket server. Is there a way to authenticate the user? I haven't been able to do this, and googling it doesn't really give me an answer. Would I just write code that requires the user to send a message to the server, check if the code is what I require (so, basically a password), if password is correct, write user to an array, and then broadcast to all the people in the array?
Then use [code]
ws.on('close', function() {
console.log('disconnected');
});[/code] to check if the person disconnected, to remove them from the array. That should work, shouldn't it?
Main concerns:
- Safe?
- Best way to do it?
edit:
What I mean by "safe", someone could easily go to websocket.org and enter my IP + Port and then listen my console:
[img]http://i.imgur.com/fwjG0IQ.png[/img]
edit2:
If I make a password and put that password in plain text, it'll be easy to guess by the people who use my website. so, if I ever have someone who has the ability to view the server's console, and I revoke their access, they can still use my websocket to read the console's output. How could I prevent this?
Yay, someone understood my vague ramblings :v:
[QUOTE=Cyberuben;44723782]I found a few scripts and combined them, all Node.js.
...[/QUOTE]
Maybe try [URL="http://www.sitepoint.com/http-authentication-in-node-js/"]this[/URL]. Simply create an "account" for each and every person you wish to grant access to, and then remove it from the password file when you revoke their access.
(Scroll down to the Digest Access Authentication method)
Apologies if this isn't the kind of thing you guys are interested in answering, but I can't figure out for myself no matter how much I attempt it. I'm using wordpress to power my site, using an edited child theme of twenty-twelve.
My issue is the comments take up a load of space, with lots of whitespace etc. I want to compress them all so there's much less whitespace etc. I've tried looking about to find the relevant parts I need to edit, I assume it's the margins in the css for the comments, but haven't been successful. Any ideas on where I should be looking?
snip
I'm not sure if those document.ExamEntry.xxxx will work without any getElements, but right off the bat, on the form you call 'returnvalidationForm' while the function in the script is called 'validateForm'. As they're diferent names, it never executes.
Also, I'd suggest you to hit F12 and open the Console tab of the developers' menu. It will log any errors that you might have, so you'll have an easier time debugging it.
Does anyone have a link to a way to set a selectparameter from the code behind file in ASP.NET? Basically I've got a table of articles that I want to display using a listview and an sqlDataSource, but these need to be organised by the author who is logged in, no idea how to go about this so any help is appreciated. I think it's setting the authID field in my table with the name of the logged in user and selecting any fields with that name but I can't figure the code out :(
Edit:
Somehow managed to get it working but I have no idea how:suicide:
Are there any sites that you can host webpages on for free, perhaps in exchange for advertising? I'm quite interested in building myself a portfolio, and the premade portfolio sites are a little limiting.
[editline]6th May 2014[/editline]
By a webpage, I mean something I've thrown together myself.
[url=https://pages.github.com]GitHub Pages[/url]
[QUOTE=~ZOMG;44737667]Are there any sites that you can host webpages on for free, perhaps in exchange for advertising? I'm quite interested in building myself a portfolio, and the premade portfolio sites are a little limiting.
[editline]6th May 2014[/editline]
By a webpage, I mean something I've thrown together myself.[/QUOTE]
Depends on if you want to use your own domain name and if you'll use PHP/Nodejs/RoR as backend.
There are loads of websites you can host with ads.
Does anyone know of a site to use to test redirect loops?
[editline]6th May 2014[/editline]
I mean a site that has one to test something you've made, not one that checks for them.
[QUOTE=Shadaez;44739432]Does anyone know of a site to use to test redirect loops?
[editline]6th May 2014[/editline]
I mean a site that has one to test something you've made, not one that checks for them.[/QUOTE]
Do you mean something like [URL="http://redirectcheck.com/"]this[/URL]?
[QUOTE=~ZOMG;44737667]Are there any sites that you can host webpages on for free, perhaps in exchange for advertising? I'm quite interested in building myself a portfolio, and the premade portfolio sites are a little limiting.
[editline]6th May 2014[/editline]
By a webpage, I mean something I've thrown together myself.[/QUOTE]
GitHub Pages or Heroku is the way to go.
[QUOTE=~ZOMG;44737667]Are there any sites that you can host webpages on for free, perhaps in exchange for advertising? I'm quite interested in building myself a portfolio, and the premade portfolio sites are a little limiting.
[editline]6th May 2014[/editline]
By a webpage, I mean something I've thrown together myself.[/QUOTE]
Definitely GitHub pages as Rieda said, easy and pretty urls. No "yourname.BESThostingEVeR13.com"
[QUOTE=~ZOMG;44737667]Are there any sites that you can host webpages on for free, perhaps in exchange for advertising? I'm quite interested in building myself a portfolio, and the premade portfolio sites are a little limiting.
[editline]6th May 2014[/editline]
By a webpage, I mean something I've thrown together myself.[/QUOTE]
You should never build your portfolio on top of free hosting, first of all your work could go missing without a clue. Second of all would you hire a programmer who cant even host a webpage?
I feel its sort of the same for when you make a buisness card and put on your [email]me@gmail.com[/email] it just doesnt look good, and you should avoid it. Hosting these days cost less than what you use in the sandwichbar, basically if you cant afford the domain, you got other priorities :)
[QUOTE=~ZOMG;44737667]Are there any sites that you can host webpages on for free, perhaps in exchange for advertising? I'm quite interested in building myself a portfolio, and the premade portfolio sites are a little limiting.
[editline]6th May 2014[/editline]
By a webpage, I mean something I've thrown together myself.[/QUOTE]
[url=http://geoshitties.installgentoo.com/]Geoshitties?[/url]
Sorry, you need to Log In to post a reply to this thread.