Polymer template data binding - how to input 2 arguments into a function? - polymer

I successfully use a single argument in polymer to call a function (in Dart) -eg
{{arg1|myfunc}}
I can't get two arguments to work. I have tried several combinations, including the example shown on the polymer expressions page:
{{ {arg1,arg2} | myfunc}
and
String myfunc(String arg1, String arg2){
but my dart project won't even 'compile' (I get a 404 not found) with that.
What is the correct syntax please? Thanks, Steve

Thanks Anthony,
I just tried the obvious! Here is the syntax:
{{ myfunc(arg1,arg2) }}
Steve

Related

how to write own defined function that includes an imported function?

I am learning Julia programming by reading the book Think Julia I am including the following:
enter image description here
forward is a function in the ThinkJulia module. It acts on the Turtle() object, to move it forward. Why, after the line using ThinkJulia , am I getting this error. Do I have to be more specific in Julia about importing functions? I thought using would give me access to all functions in that particular module?
You need to pass a value not to its type to forward, so define your function like this:
function forward_len(t::Turtle, d)
forward(t, d)
end
and things should work
The error message is clear, you do not have forward method matching your parameter types.
Try 'Forward' instead of 'forward';
function forward_len(t::Turtle, d)
Forward(t, d)
end
Source: https://juliagraphics.github.io/Luxor.jl/v0.11/turtle.html

How to pass parameters or variables of arm template in log query

While working on log Queries in an arm template, I stuck with how to pass parameter values or variable values in the log Query.
parameters:
{
"resProviderName":
{
"value": "Microsoft.Storage"
}
}
For Eg:
AzureMetrics | where ResourceProvider == **parameters('resProviderName')** | where Resource == 'testacc'
Here I am facing an error like, it was taking parameters('resProviderName') as a value and it was not reading value from that particular parameter "resProviderName" and my requirement is to take the values from parameters or variables and should not hardcode like what I did in the above query as Resource=='testacc'.
Do we have any option to read the values from either parameters or variables in the log query?
If so, please help on this issue.
The answer to this would depend on what this query segment is a part of, and how your template is structured.
It appears that you're trying to reference a resource in the query. It is best to use one of the many available template resource functions if you want the details of the resource like its resourceID (within the resources section). When referencing a resource that is deployed in the same template, provide the name of the resource through a parameter. When referencing a resource that isn't deployed in the same template, fetch the resource ID.
Also, I'd recommend referring to the ARM snippet given this example to understand how queries can be constructed as custom variables as opposed to the other way round. According to ARM template best practices, variables should be used for values that you need to use more than once in a template. If a value is used only once, a hard-coded value makes your template easier to read. For more info, please take a look at this doc.
Hope this helps.
This is an old question but I bumped into this while searching for the same issue.
I'm much more familiar with Bicep templates so what I did to figure out was to create a Bicep template, construct the query by using the variables and compile it. This will generate a ARM template and you can analyze it.
I figured out you can use both concat or format functions in order to construct your query using variables.
I preferred the format one since it looks more elegant and readable (also, Bicep build generates the string using the format function).
So based on this example, the query would be something like this:
query: "[format('AzureMetrics | where ResourceProvider == {0} | where Resource == ''testacc'' ', parameters('resProviderName') )]"
Don't forget to escape the ' in the ARM template which you do by doubling the single quote.
I hope this helps some people.
André

How to insert the current date with jinja2

I am new to use Jinja2 and try to insert the current date in a document as a bottom line to tell users when the document was produced.
My current solution is
Produced on {{ utils.today|date('%x') }}
There are no error messages, but nothing is produced.
The solution need to be Jinja2 only, as I have no python process running - using Ginger (a Haskell program) to process the template.
Context Processors can be used to inject values into templates before rendering it.
In app.py:
import datetime
#app.context_processor
def inject_today_date():
return {'today_date': datetime.date.today()}
And add this in the html file:
<p>{{today_date}}</p>
Output: 2019-01-07
Jinja2 doesn't have native support for inserting the date. However, you can easily prepare the date in whatever library you use to render the template and pass the value to the rendering function.
Using jinja2 in Python:
import datetime
date = datetime.date.today()
template = Template('Produced on {{ date }}')
template.render(date=date)
If you are using Ginger, you would have the same template, just make sure to create the date in Haskell and render the template with that value.
You can also write or install a jinja2 extension that will make utilities for working with dates available in the template.
For example, after installing jinja2-time [1], your template would look like this:
Produced on {% now 'local' %}
[1]: untested code

Using jinja inside jinja

Here's what I want to do:
{% for disaster in disasters %}
{{disaster.name}}
When I try to open the HTML page I get:
Error during template rendering
With exception value as:
Exception Value:
Reverse for '{{disaster.link}}' not found. '{{disaster.link}}' is not a valid view function or pattern name.
How can I do the same task with or without jinja logic?
Have you tried removing the curly braces around disaster.link? I've only worked with Jinja once, but that stood out to me.

Why do I get a "Too many input arguments" error when not passing any?

I am working on some simple object-oriented code in MATLAB. I am trying to call one of my class methods with no input or output arguments in its definition.
Function definition:
function roll_dice
Function call:
obj.roll_dice;
When this is executed, MATLAB says:
??? Error using ==> roll_dice
Too many input arguments.
Error in ==> DiceSet>Diceset.Diceset at 11
obj.roll_dice;
(etc...)
Anyone have any ideas what could be causing it? Are there secret automatic arguments I'm unaware that I'm passing?
When you make the call:
obj.roll_dice;
It is actually equivalent to:
roll_dice(obj);
So obj is the "secret" automatic argument being passed to roll_dice. If you rewrite the method roll_dice to accept a single input argument (even if you don't use it), things should work correctly.
Alternatively, if you know for sure that your method roll_dice is not going to perform any operations on the class object, you can declare it to be a static method as Dan suggests.
For more information on object-oriented programming in MATLAB, here's a link to the online documentation.
I believe you can also get around this by declaring roll_dice to be a static method.