|
Pollyanna posted:Unfortunately, it looks like Python's "translate to JSON" dealio causes a bit of a problem: all the keys are turned to strings, when I need them to be flat-out variables. e.g.:
|
# ? Jan 10, 2014 06:26 |
|
|
# ? May 16, 2024 09:57 |
|
You need to parse the JSON to convert it to a proper Object.. var options = JSON.parse(data); or take a look at this: http://stackoverflow.com/questions/18490609/select2-load-data-with-ajax-from-file
|
# ? Jan 10, 2014 11:15 |
|
Pollyanna posted:For context, this is what Select2 expects: I don't understand what data: means in this case, unless it's a key in some top-level object. Anyway, what you have there after data: is an array of objects Actually, is the data you're currently getting this: code:
While it should be this: code:
Because neither code:
code:
|
# ? Jan 10, 2014 11:19 |
|
I honestly don't know. I managed to get it working, somehow, but it runs obnoxiously slowly whenever you try to look up a symbol. The time it takes to render a page tanked, too, so I'm just removing it for now. I'll look for something like tagging that doesn't depend on a lookup, instead you can just write "aapl,google,ibm" like you do on Tumblr.
|
# ? Jan 11, 2014 04:06 |
|
What is the correct approach to determining when a recursive function which also makes a bunch of async calls is done? The solution I have come up is basically to create a counter object at each recursive call. This object contains total number of future recursive calls to be made on this level and the number completed plus a callback when all of them have been completed. I then pass it as one of the arguments to next recursive call. When a counter is done it will increment count of done calls in the parent count object. Here is some code: code:
pr0metheus fucked around with this message at 08:21 on Jan 11, 2014 |
# ? Jan 11, 2014 08:18 |
|
pr0metheus posted:What is the correct approach to determining when a recursive function which also makes a bunch of async calls is done? With jQuery this is a lot easier, and I'm sure there's a native way to implement this as well, I just don't know what it is. If each of your async calls is returning a deferred promise, you can put the promises into an array and give the script a function to run once all of the promises are resolved. So it would be something like this: code:
Sorry if this is confusing, it took me a while to work out how jQuery's deferred objects work; but they're really, really useful. http://api.jquery.com/category/deferred-object/
|
# ? Jan 11, 2014 16:30 |
|
pr0metheus posted:What is the correct approach to determining when a recursive function which also makes a bunch of async calls is done? You can use the parallel() function of the async library for this. code:
|
# ? Jan 11, 2014 17:04 |
|
The problem with promises is that I do not know exactly how many promises I will need. Same with async. I do not know ahead of time how many async tasks I will generate.
|
# ? Jan 12, 2014 01:47 |
|
pr0metheus posted:The problem with promises is that I do not know exactly how many promises I will need. Same with async. I do not know ahead of time how many async tasks I will generate. I personally use Q. This library I wrote (http://malucomarinero.bitbucket.org/johodb/ - due for a clean up, about to start rolling it into a production app and filling out the rest of the features) uses Q promises extensively to interact with asynchronous local storage (IndexedDB and WebSQL). Sometimes those asynchronous calls generate MORE calls because there's more data to be found. As long as you're consistent with your return on the asynchronous promises, you can pick it all up at the end with a simple Q.all call on the promise stack. For example (in coffeescript but you should get the idea): CoffeeScript code:
|
# ? Jan 12, 2014 03:15 |
|
pr0metheus posted:The problem with promises is that I do not know exactly how many promises I will need. Same with async. I do not know ahead of time how many async tasks I will generate. The structure I posted allows you to push as many promises into the promises array as you need to. I use it in my projects to update one or many lines of a given invoice, given the user's input - a situation in which you also don't know how many async calls you will be making. The 0-9 for loop is just for example.
|
# ? Jan 12, 2014 03:54 |
|
It looks like you're just trying to walk a file directory and then also filter out by some specifics. Why not just do a normal file walk that returns a callback'd array that you run filter() against? Honestly maybe you should clarify what you are doing since this sounds eerily like its an XY problem.
|
# ? Jan 12, 2014 04:07 |
|
I just wanted to use async methods and figure out a way to join all of them and call a user specified function. Will look into promises. I am not quite sure they would be more efficient or easier to read then my counter solution, however.
|
# ? Jan 12, 2014 04:45 |
|
No, I mean what is the actual task you are trying to do.
|
# ? Jan 12, 2014 07:21 |
|
pr0metheus posted:The problem with promises is that I do not know exactly how many promises I will need. Same with async. I do not know ahead of time how many async tasks I will generate. Use the async.queue object to do this. You basically have a dynamic set of tasks that need to be executed with a callback at completion and the queue will let you add new directories to filter as you work your way down the tree.
|
# ? Jan 12, 2014 09:04 |
|
Strong Sauce posted:No, I mean what is the actual task you are trying to do. Recursively go through a given folder and pick out path's that meet some filter criteria. Ethereal posted:Use the async.queue object to do this. You basically have a dynamic set of tasks that need to be executed with a callback at completion and the queue will let you add new directories to filter as you work your way down the tree. I will give async a try. Thank you guys for all the suggestions. Will give this more reading and experimentation.
|
# ? Jan 12, 2014 10:48 |
|
Is there a compelling reason to use Q over Bluebird or some other promises library? The benchmarks I've seen all peg Q as pretty much the slowest option out there.
|
# ? Jan 12, 2014 22:41 |
|
Damiya posted:Is there a compelling reason to use Q over Bluebird or some other promises library? The benchmarks I've seen all peg Q as pretty much the slowest option out there. I've used Q and like it, but if theres a more efficient alternative out there I'll be switching over, no question. Bluebird's API looks pretty exhaustive too, just at a quick read.
|
# ? Jan 13, 2014 11:40 |
|
I am implementing the dropzone.js photo upload. However I do not want dropzone to handle the uploads because it seems like they go in bursts instead of all at once. I would like my photos to be uploaded at one time. To do so users will drag and drop photos into the dropzone area. From here they choose some custom options on the images. Then I would like a user to hit a custom button. This button can perform the following. 1. Add photos to multiImg[] array 2. invoke form After a photo is uplaoded into the dropzone I will have access to all the information about the photo. Name, size, location(on uers computer). I am just unsure how to accomplish step 1 which is to take the photos and pass them into a form via javascript. Is this even a good approach? code:
|
# ? Jan 13, 2014 16:34 |
|
DholmbladRU posted:I am implementing the dropzone.js photo upload. However I do not want dropzone to handle the uploads because it seems like they go in bursts instead of all at once. I would like my photos to be uploaded at one time. I just used dropzone.js on a site where I have it uploading all the files at once with the rest of the form rather than one at a time, check this out: https://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone
|
# ? Jan 13, 2014 17:22 |
|
Opulent Ceremony posted:I just used dropzone.js on a site where I have it uploading all the files at once with the rest of the form rather than one at a time, check this out: https://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone Yeah I was reading that documentation now actually. Unfortunately I need to add my dropzone via html as opposed to java script. For some reason my current implementation is not passing the photos to the $this->post code:
php:<? if ($this->request->method() === 'POST') { echo 'post'; print_r($this->_post); } ?> code:
DholmbladRU fucked around with this message at 18:20 on Jan 13, 2014 |
# ? Jan 13, 2014 17:26 |
|
DholmbladRU posted:Yeah I was reading that documentation now actually. Unfortunately I need to add my dropzone via html as opposed to java script. From their docs, configuring the drop zone if you are using just HTML elements: Dropzone posted:But if you just have HTML elements with the dropzone class, then you don't programmatically instantiate the objects, so you have to store the configuration somewhere so Dropzone knows how to configure the dropzones when instantiating them. As for file data not getting posted, I recall having similar problems depending on where I was applying the special dropzone classes on my HTML elements, although I don't remember the details of making it work unfortunately. Try messing with them. Will your echo show stuff in the global FILES thingy? I'm not using PHP so I'm not really sure how that works. My form looks like this: code:
|
# ? Jan 13, 2014 18:45 |
|
Yeah, the files aren't always kept in request->post. Check your php docs for file uploading, and change the form enctype to what it is in the post above mine.
|
# ? Jan 13, 2014 19:20 |
|
Yeah I have been checking the $_FILES and $this->_post for any information related to images but is is empty. I am by no means a PHP developer... form config code:
code:
DholmbladRU fucked around with this message at 22:14 on Jan 13, 2014 |
# ? Jan 13, 2014 19:41 |
|
If that is your entire Dropzone config I think you might be missing stuff. I'm pretty sure processQueue() needs to get run to actually post the file data. Take a look at the link I posted the first time, it shows you that method being used in the init function when configuring Dropzone. Also are you sure the configuration is targetting your form? The way you identify your form in Dropzone.options needs to be camelized from the form element ID. For example, my form id is 'dropzone-form', and I'm targetting it in my Dropzone configuration by doing Dropzone.options.dropzoneForm. That is, remove hyphens and capitalize the first letter. Your id appears to be 'myDZ', so I think you would just target it with .options.mydz? I'm not sure about that part, maybe try playing with it. Also, try putting the dz-clickable class on your actual form rather than a nested ul. I know I definitely had problems with stuff like that initially. Edit: Here's my config as well: code:
Opulent Ceremony fucked around with this message at 21:53 on Jan 13, 2014 |
# ? Jan 13, 2014 21:48 |
|
The form gets submitted so I know the js for dropzone initialization is getting connected properly. But there still seems to be nothing along with the request. Ill have to look into it more. Thanks for the suggestions. Maybe its because I dont have ajax configured on this kohana...
DholmbladRU fucked around with this message at 22:52 on Jan 13, 2014 |
# ? Jan 13, 2014 22:23 |
|
Maluco Marinero posted:I've used Q and like it, but if theres a more efficient alternative out there I'll be switching over, no question. Bluebird's API looks pretty exhaustive too, just at a quick read. It's A+ compliant and assuming the benchmarks are legit (I haven't repro'd locally, but I have no reason to doubt them) Bluebird is definitely the way to go. It's even better if you're using a browser that supports generator, but I'm not sure what that compatability matrix looks like.
|
# ? Jan 13, 2014 23:01 |
|
I'm getting a very intermittent "Maximum call stack exceeded" error in an HTML5 app. Sounds like a normal recursive function error, and sure enough the last function in the stacktrace is a recursive function. But it is not in the stacktrace more than once, and actually the whole stacktrace is just 5 functions deep, starting from a setInterval. Is this supposed to happen ever? Wouldn't an actual call stack exceed-ification include the giant stacktrace with 1000 functions or whatever the limit is on Chrome? I can't find anything actually wrong with the recursive loop either. TURTLE SLUT fucked around with this message at 19:29 on Jan 20, 2014 |
# ? Jan 20, 2014 19:23 |
|
Can you post the code? Also make sure you're passing a reference to the function and not actually calling the function when you use setInterval.
|
# ? Jan 20, 2014 23:01 |
|
Yeah, the interval is set up correctly. To note again, I get the call stack error about once every hundred refreshes and an out right crash maybe twice that often. Other times things work perfectly. So I don't actually know if it has anything to do with this function. How to debug an outright browser crash?code:
|
# ? Jan 20, 2014 23:54 |
|
Are you checking if self.parent !== undefined? What is self.parent?
|
# ? Jan 21, 2014 07:25 |
|
How exactly would self change on that recursive call? (Unless you create a separate instance with captured self for every object, I guess..)
|
# ? Jan 21, 2014 14:13 |
|
OddObserver posted:How exactly would self change on that recursive call? Experience has shown that people like to use "var self = this;" when using closures, and sometimes they slip and do "self = this;"
|
# ? Jan 21, 2014 14:23 |
|
Dolex posted:Are you checking if self.parent !== undefined? That's what if(self.parent) does Bruegels Fuckbooks posted:Experience has shown that people like to use "var self = this;" when using closures, and sometimes they slip and do "self = this;" One more reason to use strict mode and linting.
|
# ? Jan 21, 2014 14:30 |
|
I guess I should've given more context, but the app in question is a very large and I actually don't know if this piece of code has anything to do with the problem anymore The larger context is a tree structure with at most three or four levels in it, all with instances of the same class. I guess at this point the question is how to debug a crash that happens once every 100 refreshes. Selenium running 1000 repetitions a second and some sort of network logger so I can see the logs even when the browser crashes?
|
# ? Jan 21, 2014 16:51 |
|
JOHN SKELETON posted:I guess I should've given more context, but the app in question is a very large and I actually don't know if this piece of code has anything to do with the problem anymore The larger context is a tree structure with at most three or four levels in it, all with instances of the same class. I guess at this point the question is how to debug a crash that happens once every 100 refreshes. Selenium running 1000 repetitions a second and some sort of network logger so I can see the logs even when the browser crashes? Generate the node objects with a unique id that gets passed to the recursive call and have a line that checks to make sure that self.parent != self. Or some sort of visited flag to make sure you're not getting loops. It's hard to see how it's not the recursive function blowing up the stack assuming it's not some obscure browser bug, although it's hard to be sure just seeing that snippet.
|
# ? Jan 21, 2014 23:12 |
|
So best practices wise, am I doing myself a disservice by leaving really detailed, obvious notes in my code? As in making myself look bad? For instance, I explain why each div is hidden and under which circumstances it will be revealed, which a more experienced coder could no doubt easily figure out by reading my code.
|
# ? Jan 22, 2014 00:08 |
|
Raskolnikov2089 posted:So best practices wise, am I doing myself a disservice by leaving really detailed, obvious notes in my code? As in making myself look bad? Strip the comments from whatever compiled/deployed version your code ends up in, but, no, you're doing the right thing. There is never enough documentation.
|
# ? Jan 22, 2014 00:12 |
|
The one thing to be wary of is documentation that may become inaccurate. Comments should generally be local in scope, otherwise you're likely to forget to update them when you change something elsewhere that happens to affect your comment. In general, wrong documentation is worse than not having documentation in the first place.
|
# ? Jan 22, 2014 00:39 |
|
Raskolnikov2089 posted:I explain why Sounds like good documentation to me.
|
# ? Jan 23, 2014 00:50 |
|
|
# ? May 16, 2024 09:57 |
|
I'm prototyping a Knockout app right now, and I'm trying to add an input form that will add a filled-out row to a predefined table. However, I'm not sure how to do this. Here's my JSFiddle: http://jsfiddle.net/UZ3fS/7/ What's happening right now is that clicking "add application" adds a blank row, when it should be the data entered into the input field. I tried using the value binding to do this, but it doesn't seem to work. What am I missing?
|
# ? Jan 23, 2014 04:43 |