|
I'm trying to convert a timestamp (in seconds) to HH:MM:SS. Everything works fine, except when I try to prefix values that are less than 10 with a zero. These are the two functions I'm using: code:
So, I did a quick test and got this: code:
OUTPUT posted:0,1,2,3,4,5,6,7,0,0 I'm pretty right now. What the hell is going on? edit: Figured it out. Had to specify a base10 system: parseInt(foo, 10). I knew it was going to be something stupid. Optimus Prime Ribs fucked around with this message at 04:40 on Mar 29, 2012 |
# ? Mar 29, 2012 04:29 |
|
|
# ? Jun 5, 2024 08:37 |
|
Yeah, it's really easy to use parseInt without specifying that radix, but that's something you're technically supposed to do. I try to run my code through JSHint (or better yet, have your editor do it for you) to catch those kinds of small annoying things.
|
# ? Mar 29, 2012 05:05 |
|
Yeah a leading zero on an integer is interpreted as octal in javascript (and some other languages).
|
# ? Mar 29, 2012 05:14 |
|
Are questions about coding a custom button in Salesforce using javascript ok for this thread? If not, does anyone know where I could ask?
|
# ? Mar 29, 2012 21:34 |
|
I'm a moron and didn't notice this thread. Posted in Web Dev Small Questions as well. I apologize. I need a really simple way to replace the last number before a .jpg in one thumbnail image on a site I'm making. For example: <img id="thumb" src="t1G1.jpg" /> What type of Javascript one liner could I put inside an <a> to make this happen? I've tried messing around with onclick but nothing seems to work. I didn't use any regular expressions, just tried something like: <a href="#" onclick="document.thumb.src='t1G2.jpg';"></a> I really never experimented with Javascript, so this garbage code is just from stuff I remember seeing. Am I not calling the action correctly? If anyone could point me in the direction of simply locating the character before .jpg and replacing it with another number, that would be awesome. Maybe I'll toss in a forums upgrade or something.
|
# ? Mar 30, 2012 05:20 |
|
Using jQuery will probably make your life easier:code:
|
# ? Mar 30, 2012 05:28 |
|
e misunderstood, see below xtal fucked around with this message at 07:07 on Mar 30, 2012 |
# ? Mar 30, 2012 05:46 |
|
Suspicious Dish posted:Using jQuery will probably make your life easier: Thanks for that, is there any alternative to using regexp to change these .jpg links? I will be using a naming scheme for 600 images and 32 different styles but the number at the end will always be 1-9 and correlate to a thumbnail on the page. They will work something like this: 1G9, 3S5, 7G2. First number is style, second character is G or S, for gold or silver, and the last number is 1-9 corresponding to 9 colors. There will be appropriate style numbers and such in the url, if that would make it easier? gently caress, what did I get myself into, hah. xtal, that would work great if I was using just arrows to navigate through images, but these will be swatches displayed all at once and when clicked, will change the img src no matter what thumbnail was located there previously. I'm definitely being lazy about this, I really haven't dabbled in regexp or anything programming related in years. This will be the only scripting part of this site I'm working on. Honestly I have too many images to edit and static pages to create, if one of you could make something even remotely usable, I'll throw you or Maybe something to change just one character in a string? The string will always be the same amount of characters. coronalight fucked around with this message at 06:01 on Mar 30, 2012 |
# ? Mar 30, 2012 05:54 |
|
I don't understand. Do you have one image, and want 600*32*2 links to change that image, and want to generate those links with JavaScript?
|
# ? Mar 30, 2012 06:20 |
|
I have about 30-38 styles of earrings. They have gold and silver styles. Each gold and silver style has 9 colors. That's 30-38*18. The naming scheme can generally be the same amount of characters for all the images: 01G9.jpg, 30S8.jpg. Now, I will have one .php page that will display all of that crap dynamically. The only thing I need to figure out is how to change the one image on the page according to the 9 swatches I'm displaying. They will always be 1-9 and the image src will always be the same length.
|
# ? Mar 30, 2012 06:38 |
|
scotty posted:I have about 30-38 styles of earrings. They have gold and silver styles. Each gold and silver style has 9 colors. That's 30-38*18. The naming scheme can generally be the same amount of characters for all the images: 01G9.jpg, 30S8.jpg. Now, I will have one .php page that will display all of that crap dynamically. The only thing I need to figure out is how to change the one image on the page according to the 9 swatches I'm displaying. They will always be 1-9 and the image src will always be the same length. So, you have a base, and 9 swatch links that swap out the image? I'd have markup like this: code:
|
# ? Mar 30, 2012 06:52 |
|
scotty posted:Maybe something to change just one character in a string? The string will always be the same amount of characters. As long as you keep the fixed length then you can use the substr function on the string. code:
|
# ? Mar 30, 2012 17:04 |
|
Anyone know anything about Mocha async testing in Node? I'm finding that a callback called inside of a jsdom is bizarrely muted.code:
|
# ? Apr 2, 2012 08:13 |
|
Is it possible your 3.should.equal 5 is throwing an exception which is getting caught in an unexpected place? I was under the impression the node devs strongly recommend against using exceptions because the scoping gets rather complex due to async callbacks. If that line does throw an exception, this obviously explains why nothing after it in the same block executes.
|
# ? Apr 2, 2012 12:25 |
|
Huh, you're right, nothing after the .should call gets executed. What I put here is actually over-simplified: in the real code, the callback gets passed around to all sorts of functions, and works fine almost anywhere. But if it's in the jsdom.env call OH JESUS gently caress Just remembered what jsdom.env actually does. e: the solution is to wrap the callback in a process.nextTick call. Thank you so much for putting me on the right path. Doc Hawkins fucked around with this message at 18:01 on Apr 2, 2012 |
# ? Apr 2, 2012 17:44 |
|
I'm having to do some really nasty stuff to make Oracle WCP play nicely with our js/jQuery validation framework. Due to WCP's less than fantastic way of submiting forms I'm having to remove an onclick function from the submit button, run the validation, re-apply the onclick then fire a click event on the button. I'm aware this is completely insane. The code which does the last bit looks like this: code:
e; oh and the reason for using fireEvent like that is that the onclick function uses colons all over the place where it really shouldn't which causes jQuery to blow up.
|
# ? Apr 4, 2012 14:37 |
|
This is a Chrome extension question but related to the DOM so any Chrome-only solution is fine. I am making an extension that manipulates the DOM by adding a DIV into a page on Wikipedia right underneath the last paragraph of a page header. I need to get the actual width of the DIV to match up to the width of the paragraph. However there is usually an infobox on the pages I'm adding onto which has a css property "clear:right" Because of that, the width of the actual paragraph (from clientWidth/offsetWidth) is that of the entire length of the page and does not take into account that the infobox takes up a portion of that width. Is there any way to get this "true width?" The method I am using right now is kinda clunky so I'd rather not use if I don't have to. I've attached a picture of the actual width that I want (the line in red) vs what the DOM returns (the orange border area).
|
# ? Apr 8, 2012 06:30 |
|
I assume you mean the info box has float: right rather than clear: right. Anyways, I just messed around with it a little bit and it looks like if you give your div an overflow: hidden it'll adjust its width to compensate for the info box. I don't know why it does that, it seems like some quirk with the layout engine, but as long as you keep both your width and your height set to auto it shouldn't affect anything else.
|
# ? Apr 8, 2012 06:53 |
|
Gordon Cole posted:I assume you mean the info box has float: right rather than clear: right. Anyways, I just messed around with it a little bit and it looks like if you give your div an overflow: hidden it'll adjust its width to compensate for the info box. I don't know why it does that, it seems like some quirk with the layout engine, but as long as you keep both your width and your height set to auto it shouldn't affect anything else. Yeah meant a float:right although the div does have a clear:right. Your solution works, unfortunately Chrome still glitches on what I'm trying to do, although using overflow:hidden makes it work much smoother. Thanks!
|
# ? Apr 8, 2012 07:59 |
|
What exactly are you trying to do?
|
# ? Apr 8, 2012 20:40 |
|
Is there an easy way to check that an object is type safe before using it?
|
# ? Apr 9, 2012 03:35 |
|
NovemberMike posted:Is there an easy way to check that an object is type safe before using it? Yes and no, and I'm not exactly sure what you mean by "an object is type safe". If you are doing a comparison, then you can use triple equals to check type: code:
If you mean checking what the type of a given object is, that's tougher. There are no real "types" in javascript, and typeof can lie. Here's a bigass post that talks about all the stuff I would talk about but since they already typed it out... http://stackoverflow.com/questions/332422/how-do-i-get-the-name-of-an-objects-type-in-javascript
|
# ? Apr 9, 2012 04:22 |
|
By objects being type safe, I mean that a bird is of type Duck and not Geese. Is it considered best practice to just not check object types to ensure that the code will run?
|
# ? Apr 9, 2012 13:01 |
|
NovemberMike posted:By objects being type safe, I mean that a bird is of type Duck and not Geese. Is it considered best practice to just not check object types to ensure that the code will run? Well, you can type hint objects: function doStuff(Duck $bird, Goose $otherbird) { } And you can also use the instanceof operator (for example, if ($bird instanceof Duck) { }), or the is_a() function.
|
# ? Apr 9, 2012 13:27 |
|
Golbez posted:Well, you can type hint objects: function doStuff(Duck $bird, Goose $otherbird) { } Uh, this is the JavaScript thread, not the PHP thread. You can check for object types in JavaScript if you really want to, but usually you don't do argument checking and make the assumption that if you pass the wrong type of argument your function will error out or return an unexpected value anyway, so why bother.
|
# ? Apr 9, 2012 15:46 |
|
Suspicious Dish posted:Uh, this is the JavaScript thread, not the PHP thread. Jesus christ, that's what I get for posting on 4 hours of sleep. Sorry about that.
|
# ? Apr 9, 2012 15:50 |
|
NovemberMike posted:By objects being type safe, I mean that a bird is of type Duck and not Geese. Is it considered best practice to just not check object types to ensure that the code will run? Right, there's usually not really any point in trying to do strict type checking in JavaScript. As long as your object can fly() why does it matter if it's a Duck or a Goose? In general it's better to check for the existence of properties rather than the type of an object, like this: code:
An example of a situation where you might actually want to do type checking is if you want to explicitly support that a parameter of a function could be, say, a string or a function that returns a string. You can use type checking to make sure it's a function before you actually call it.
|
# ? Apr 9, 2012 18:20 |
|
My JS fu is dreadful, and I am trying to implement this password validator. say I have an example folder: code:
code:
code:
ufarn fucked around with this message at 00:33 on Apr 18, 2012 |
# ? Apr 18, 2012 00:30 |
|
There's nothing automatically that hooks zxcvbn up to existing password fields. You need to do that yourself. Unfortunately, I don't know of any existing projects that do.
|
# ? Apr 18, 2012 00:55 |
|
Suspicious Dish posted:There's nothing automatically that hooks zxcvbn up to existing password fields. You need to do that yourself. Unfortunately, I don't know of any existing projects that do.
|
# ? Apr 18, 2012 01:01 |
|
Assuming you're using jQuery, it looks like you need to do something like this:code:
|
# ? Apr 18, 2012 02:02 |
|
I think I get almost everything about JS except closures. Can someone post the best closure resource they know of -- some post/article that made them say "a-ha"? Or some example for us here on the forums about how they work and where they are useful? Maybe we can make it a conversation or something.
|
# ? Apr 18, 2012 03:09 |
|
smug forum rear end in a top hat posted:I think I get almost everything about JS except closures. From Crockford's Good Parts: quote:An inner function also enjoys access to the parameters and variables of the functions it is nested within. The function object created by a function literal contains a link to that outer context. This is called closure. This is the source of enormous expressive power. I already know this, and it makes good sense to me. However, when I read the article on closures at https://developer.mozilla.org/en/JavaScript/Guide/Closures , I get a bit confused. I wonder what in-between step I'm missing here.
|
# ? Apr 18, 2012 03:19 |
|
smug forum rear end in a top hat posted:My a-ha moment was when I tried binding event handlers in a loop and it spit out the "wrong" value when I triggered each handler. Click the numbers in this fiddle and use what you know to figure out why 'a' and 'b' are the values they alert: http://jsfiddle.net/AEJdw/1/
|
# ? Apr 18, 2012 04:01 |
|
smug forum rear end in a top hat posted:I think I get almost everything about JS except closures. What don't you understand about closures? What they do? Why they're useful or powerful? Or implementation details, like scope chains and how that messes with garbage collection?
|
# ? Apr 18, 2012 04:49 |
|
After a little more reading, the part that I don't understand is the idea that the inner function has to be returned to create a closure. Where did this idea come from?
|
# ? Apr 18, 2012 15:37 |
|
smug forum rear end in a top hat posted:After a little more reading, the part that I don't understand is the idea that the inner function has to be returned to create a closure. That's not true at all. It doesn't have to be returned. Any function which has access to the outer scope's variables from an inner scope is a closure, whether it's used in a loop, as a callback, passed to an other function, or returned. Of course, programmers largely argue over uninteresting semantics like this, but if you have the basic idea of saving and accessing outer scope even when the function is no longer "called", then you're good. smug forum rear end in a top hat posted:Where did this idea come from? Closures originally came from Lisp.
|
# ? Apr 18, 2012 18:17 |
|
A closure only has to be formed when a function outlives its upvalues' scopes. In the specific case of Javascript, since functions are the only scoping mechanism, conceptually closures only have to be created when returning from functions (and the function is either being returned or has been stored in a variable in a surviving scope). In practice, I'd expect most implementations to create the closure at the same time as the instantiation of the anonymous function.
|
# ? Apr 18, 2012 18:51 |
|
Gordon Cole posted:Assuming you're using jQuery, it looks like you need to do something like this: In general, don't these graders stand a good chance of exposing the passwords to other people, if you don't do it right? I guess it would be fine if it were plug and play with all the intermediate security measures implemented, but putting it up for everyone to implement themselves seems hazardous.
|
# ? Apr 18, 2012 18:59 |
|
|
# ? Jun 5, 2024 08:37 |
|
smug forum rear end in a top hat posted:After a little more reading, the part that I don't understand is the idea that the inner function has to be returned to create a closure. code:
The problem with referring you to an article on closures is that they're almost invariably Lisp or ML-based. Gazpacho fucked around with this message at 19:31 on Apr 18, 2012 |
# ? Apr 18, 2012 19:15 |