I am using sugarjs. When using the numbers api it doesn't go well with coffeescript. I am thinking it is the brackets..what is a better way to do this.
(50).pad(5) gets transalated to 50..pad(5)
how to keep the brackets intact.
thanks
Why do you want to keep the brackets intact ? They're not needed. It works fine this way
Related
I can't access my array in a for loop - Why? Thanks in advance.
I want to play a state animation for my "PageDowns" elements.
Sorry, I couldn't paste the code, because CodeSample here didn't work for me.
Got it on my own.
It was a scope problem. CoffeeScript is not easy to handle when it comes to arrays, loops and so on.
I had to write:
do(pageDown)
PageDowns[i].animate "swipe"
Im constructing a URL from query items using URLComponents and I want to add some query items as OR conditions rather than AND. Im not sure what the proper terminology for this is. Anyway I would like the following, roughly
website.com/things?param1=thing¶m2=thing|param3=thing|param4=thing
but appending query items i can only get
website.com/things?param1=thing¶m2=thing¶m3=thing¶m4=thing
My goal is to check 3 different parameters for the term I pass in, and return any results that match from any of the 3. If I was constructing the url from a string, I could just use a pipe instead of ampersand (I think - please correct me if wrong), but Im using URLComponents and am not sure how to do this.
Perhaps Im going about this incorrectly. I dont have a ton of experience with this. If this is the wrong approach, please point me in the right direction. Im not sure how to word this question appropriately and that makes it hard to search for an answer
Im not sure what the proper terminology for this is
There is no terminology for it; it doesn't exist. What you're trying to do is nonstandard. There is no such thing as a query item OR condition. Standard separators are semicolon and ampersand, with ampersand used almost universally. You can't use a pipe to separate query items.
Thus, for example, if you paste website.com/things?param1=thing¶m2=thing|param3=thing|param4=thing into the parser at http://www.freeformatter.com/url-parser-query-string-splitter.html, it doesn't know what to make of the pipes; it thinks that param2 must be thing|param3=thing|param4=thing.
Thus, URLComponents is not going to insert the pipe for you. Its goal and purpose is to make a valid URL, and you are attempting to make an invalid one.
I'm using this peculiar syntax for assigning an object to an instance variable during a list iteration:
execute: =>
while #canExecute()
for #currentStack in #stacks
#executeNext()
if #currentStack.isEmpty()
#stacks.remove #currentStack
break
The important line here is for #currentStack in #stacks. This assigns this.currentStack during iteration. I like this. It makes me happy.
I'm worried though that it's an issue. I don't see it specifically documented anywhere. This code is running in several different products and I haven't found an issue myself. Anyone have experience with this?
You are using a pure javascript for...in loop, it is perfectly fine you can continue being happy. Link for documentation:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
How would I go about cloning any widget from gjs, similar to the C response given in https://stackoverflow.com/a/3030603/1829961? I have not been able to find a way to call list_properties although it is listed in the GModule gir file. Or do I have to use GIRepository, manually walk the GIR type hierarchy, emulating that which g_object_class_list_properties is supposed to do? Or another straight forward way I'm totally missing here?
Here is some code that will do that.
It takes a similar approach to the quesion you linked, but since there is no G_OBJECT_GET_CLASS() in GJS, it uses GIRepository instead -- which is an extra dependency that you need compared to the C solution.
A week or two ago I just started using Zend Framework seriously and have had trouble escaping manually with Zend_View::escape().
Does anyone knows how to escape vars in templates (Zend_View templates) automatically without using $this->escape(), or any other tricky ways like output buffering and PREG replacing *.phtml files.
I'd like to know the best practice in this case.
You can extend Zend_View to create a custom view class which autoescapes things, or you can use a view helper to turn autoescaping on/off.
I have written a blogpost about it, with example code for both approaches:
How to automatically escape template variables in Zend_View
Over at the PiKe project we build a custom stream wrapper that automatically escapes all view variables, with a MINIMAL performance hit! You can still get the RAW value with:
<?=~ $variable ?>
Notice the "~" character. Checkout http://code.google.com/p/php-pike/wiki/Pike_View_Stream
I know you said that you want to avoid "tricky ways like output buffering and PREG replacing *.phtml files.", but I still think it's a very neat way to fix auto escaping in Zend Framework 1.
You said "automatically", so I believe that that means when you do echo $this->var; you want it escaped. Well, if that's the case, maybe you could do the escaping when the variable is set to the view. AFAIK it's done in the Zend_View_Abstract class' __set magic method* (around line 300). Changing the core ZF code is not recommended, so you could go by extending Z_V_A or Z_V and just override the __set method.
*I'm not 100% sure that Z_V_A::__set is the only place where the params are assigned to the view, but I think it should be. Can't think of any other place for that.
Edit: Personally, I'd avoid this and just stick with the good ol' $this->escape(). More typing but less magic going on in the background.
You have asked for best practice then what you are doing is already it.
Wait till when you want to display your data before modifying it only for output reasons.
I understand you find writting ->escape() everytime tedious but its still the way to go.
If you where to auto escape everything then you would run into problems one day when you want/need unescaped data.
ZendX_View_Autoescaping, this project provides you a ViewRenderer with autoescaping of all assigned view variables.
https://github.com/jensklose/ZendX_View_Autoescaping
Try it!
It supports:
escaping into deep data structures
escaping the array keys
possibility to switch the escaping context (html, json, nofilter)