- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Wait, after 9 goes to 10, won't the next update do 20 then 30? How did it get to 26?
Admin
I was wondering the same thing.
Admin
yeah, me too i guess the images used in the article weren't from the actual site, they made them probably without thinking to much at the numbers
Admin
Must have something to do with counting in hex and reverting to dec.
Btw, that is a sh^Htrange language - not only the counterintuitive postfix if, but the result of the match() method seems to need a call to its first() method, but not the replace() method.
Otherwise I'd expect the following sequence:
... -> 8 -> 9 -> 10 -> 22 -> 33 -> ...
Admin
You're all wrong: The current value seems to be server side generated and is always right. The counter is just for these people who want to bookmark/unbookmark the current site and increases or decreases the current bookmark value with the own activity.
The developer propably only testet this with a few bookmarks - less than 10 - an supposed a correct functionality.
Admin
But how would the server know how many people had clicked the button?
Admin
Maybe with some more magic - possibly some source code
Admin
It's simple: the original button and count are server-generated, then when the user clicks the button, two things happen: 1) a AJAX call to the server is made, informing the server that someone has pressed the button, and 2) the count is updated locally with JavaScript. Only the second part is wrong.
Admin
Can anybody enlighten me what the purpose of this line is? match a digit from a variable and replace with the complete variable is this the dwsperate attempt to prevent the injection of non digits? yeah client slient side with Javascript - what can possibly go wrong? but on the other hand: it was a Javascript Webdeveloper...
Admin
When the only tool you have is a regex.....
Admin
@uwe The idea is to make the count go up by 1 so the user sees their attempt at interaction was successful. Maintaining an accurate count isn't a top priority.
I assume the developer originally had the number along with some text in the box, since they are specifically trying to pull out the number and put it back.
If I had this code and was asked to quickly fix it ,I would change both "/\d/"s to /\d+/ in order to match against the full number. Quick and dirty but it would now function correctly with minimal changes.
But if I was designing it from scratch, I would make a tag specifically to hold the number separate from the other content, and then I could get and put the number directly without worrying about other text content around it.
Admin
The counter was already 16 when the new code went live. After that, it only did the leftmost digit.
...and, coming right up:
Bookmarks 10000000000000000000000000000000000000000000000000000000000000000000006
Admin
What language was that supposed to be? It isn't JavaScript
Admin
Good question. Reminds me a bit of Coffeescript, but it isn't quite right, and why would there be coffeescript on the front-end anyways?
Admin
I just thought that 9 other people had bookmarked it during the time the page was loaded in memory for him.
Admin
INB4 : http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
Addendum 2016-03-24 12:12: SO, wait... how do I make a link clickable?
Admin
Not currently available in the New Comments System. Also: I hope it's marking this in reply to Carl Witthoft (google), because there's no visual indication it will do so.
Addendum 2016-03-24 14:49: Edit: It did.
Admin
It's JavaScript, looks like they are using the Prototype.js library.
Admin
Some people, when faced with a problem that can't be counted by regular expressions, say "I know! I'll use context free languages!"
Then their problem count gets a stack overflow.
Admin
in reply to Hoodle:
Can't be javascript due to these two lines ("if" and "else" are keywords):
Maybe coffeescript? (But that wouldn't have appeared in view source of course...)
Admin
With the right scripts loaded, CoffeeScript can be compiled on the fly clientside instead of precompiled on the server.
Admin
reminds me of a Flash game that quit working when i upgraded Flash to version 10-and the game thought it was version 1! so when i tried to run it, is got a "you need a newer version" message...
Admin
Something something regex. Something something two bookmarks.