How to set root construct for SnakeYaml? - snakeyaml

I'd like to a construct which is going to kick in by default and therefore I'll be able to extract some metadata and remove it from the parsed YAML.
For instance I could have a construct to do that but in SnakeYAML to register a construct one has to specify a String for it meaning that it has to have a name. However, I don't want that but instead I want my tag to be a root one, a default one which always will kick in so to say.
Is there a possibility to do something like that?
Cheers,

I actually found the answer myself, there is a property
at org.yaml.snakeyaml.constructor.BaseConstructor#rootTag which one can set a tag like:
super.rootTag = new Tag("!root");
The rest is simple because one has to only register that construct to org.yaml.snakeyaml.constructor.BaseConstructor#yamlConstructors and you are done. Your construct will be triggered in all read attempts.
Hope that helps to someone,
Cheers,

Related

Add types in the parameter table when generating document with Stardoc

We are trying to use Stardoc when generating documentation for our Bazel macros.
I can get a table generated with parameter descriptions when follow the instruction here:
Macro/Function documenatation.
But we would also like to add the parameter Type in the table.
According to DocstringUtils.java it seems like we shall write the type in parentheses after the parameter name but before colon, as this example:
another_parameter (unused, mutable): a parameter may be followed
by additional attributes in parenthese
I have seen that it's possible to add a rule template to the stardoc() rule (attribute: func_template).
I started to use an own copy of the default template to play around with: //stardoc:templates/markdown_tables/func.vm
If I have understood correctly it doesn't seem that the attributes that I add in paranthese is fetched.
And I don't think that I will be able to retreive that information by just updating the template.
So I think that it will need an update in the Stardoc code for this, correct?!
Is that something that is already planned?
If I'm not correct then I would appreciate information how I can retreive the value of the attribute.
Thanks!
Best Regards
Elisabeth

Send only the key of the check_box_tag if checked

I have a bunch of filter categories represented by checkboxes, right now it's sending the full name + on in the query_params.
/?max%5D=5&Movies=on&Art=on&Outdoors=on
Instead, I'd rather just look for the presence of the key to know it's there. This would make the url a bit shorter for people to copy/paste.
/?max%5D=5&Movies&Art&Outdoors
Or, can I have one category key with all the checkboxes as values?
I think it's not possible by default, you'd have to construct an onsubmit script to build the URL and redirect to it, rather than posting directly to the server. You might be better off leaving it as it is.

Is it possible to have a condition for a custom variable?

Suppose I want to create 3 custom release variables on TFS.
variable1
variable2
variable3
can i specify somewhere that to enter a variable3, user must enter variable1 and 2?
i cant prepopulate them myself because the input is quiet dynamic.
for now i am using an ugly method like this:
variable2_MUST_ENTER_VARIABLE1_FIRST
variable3_MUST_ENTER_VARIABLE1_AND_VARIABLE2_FIRST
i wish there is a way to specify some sort of note next to the textbox or something :/
Is it possible to have a condition for a custom variable?
The short answer is yes. But I could not quite confirm if it is what you want.
To set a condition for a custom variable, we could enable a custom condition on the task in the pipeline:
Conditions:
Conditions are written as expressions. The agent evaluates the
expression beginning with the innermost function and works its way
out. The final result is a boolean value that determines if the task,
job, or stage should run or not. See the expressions topic for a full
guide to the syntax.
example:
and(succeeded(), ne(variables['variable1'], ''))
But, this condition for a custom variable will be applied at build/release time instead of entering the value of variable.
i wish there is a way to specify some sort of note next to the textbox
or something
If you want to set the condition for a custom variable on the UI, I am afraid there is no such better way than you are using at this moment. You can add your request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps.
Hope this helps.

Trick when dynamically appending GET attributes

When dynamically building SQL queries you often see something like this:
WHEN 1=1 AND title="Example" AND ...
The purpose of the 1=1 is to be able to keep appending AND-statements without having to check if any previous statements exist. Thereby avoiding something like this happening:
WHEN AND title="Example" AND ...
I quite often come across a related issue when building the the attributes/search-query for a GET request. I don't want to keep checking if I need to prepend the attribute with '?' or '&'.
So my question is, is there any 'safe' way for me to add an initial attribute that won't interfere with any potential software on the server side. Assuming I do not have full knowledge of the backend.
Something like:
http://example.com?1=1&title=example
http://example.com?null&title=example
http://example.com?i-am-useless&title=example
Or is this allowed?
http://example.com?&title=example
Is there perhaps a simpler way to solve this?
Make sure the URI-string you want to add parameters to already ends in a '?'. Then for every key-value pair, add 'key=value&' to it. Optionally you can then in the end delete the last character from the resulting string. - Reddit user omepiet

grails - ways to set up a replicated site?

I've got a need where each user can customize their own page on a replicated site. In grails it seems the most straightforward way to do this is:
somedomain.com/someController/JohnDoe
spelling out a controller, except this forces folks to type in a longer domain name, versus something like
somedomain.com/JohnDoe
Using sub-domains may be another approach, however they would need to be created automatically, i.e. when someone joins.
Can you please clarify the main ways Grails supports this kind of requirement/need (replicated site), and some of the pros/cons of each?
Thanks, Ray
Edit: Per Tomasz's edit below, the simplest course of action isn't clear. If you have insights on this please do share.
It is called UrlMappings in grails. You need to declare:
"/$username?" {
controller = 'someController'
action = 'user'
}
It redirects to someController, action user and optional variable called username.
This solution has one catch. Every one level path you visit passes this rule and takes you to someController. You cannot go to somedomain.com/books because it passes rule above and it follows you to someController#user with params['username']='books'. Then you can't use default actions. But if you decide that all your other paths have at least one slash, e.g. /books/list then you can follow this solution
Edit: I was wrong. It doesn't work as I've expected. I thought that UrlMappings are applied in order they are defined. That's not true, as explained here. Even worse - it's not documented (GRAILS-6246). Most specific explanation comes from Peter Ledbrook :
It uses a specificity algorithm, so the most specific match should apply
You must experiment then. I suggest you use safest solution and stick with /user/username solution.

Resources