Render mangled hy attribute names as regular strings - hy

If I have an attribute self.internal/freezer in a class, and I raise an error via (raise (AttributeError f"Sorry! '{attr}' doesn't exist as an attribute!")), how can I get the attribute name to render as internal/freezer instead of hyx_internalXsolidusXfreezer? For example, I already tried (hy.eval attr) with the f-string, but it still came out mangled.

Thanks to #Kodiologist in the comments linking the mangling section in hylang's syntax documentation; unamgling can be achieved via the aptly named hy.unmangle function, documented here as well.

Related

How to Escape Property References in an OSGi Blueprint Properties file?

I'm trying to create a property in an OSGi properties file, where the property is a simple string, such as
fileName=${header.RecordType}.csv
However, this doesn't seem to work, and I assume that is because the ${...} is being processed as a property reference by the configuration manager, and since it doesn't exist as a property, is being blanked.
I've tried escaping the simple string reference as $${ and \${ but neither work.
Is it possible to somehow escape the ${ so that the property passed to the program is exactly as shown above?
Thanks for looking!
Use fileName=$simple{xxxx} as alternative syntax, which is also documented here:
https://camel.apache.org/manual/latest/simple-language.html

How to use $header in routes

I'm creating a route using the Java DSL in Camel.
I'd like to perform a text substitution without creating a new processor or bean.
I have this:
.setHeader(MY_THING,
constant(my_template.replace("{id1}", simple("${header.subs_val}").getText())))
If I don't add 'constant' I get type mismatch errors. If I don't put getText() on the simple() part, I get text mismatch answers. When I run my route, it replaces {id} with the literal ${header.subs_val} instead of fetching my value from the header. Yet if I take the quotes off, I get compile errors; Java doesn't know the ${...} syntax of course.
Deployment takes a few minutes, so experiments are expensive.
So, how can I just do a simple substitution. Nothing I am finding on the web actually seems to work.
EDIT - what is the template? Specifically, a string (it's a URL)
http://this/that/{id1}/another/thing
I've inherited some code, so I am unable to simply to(...) the URL and apply the special .tof() (??) formatting.
Interesting case!
If you place my_template in a header you could use a nested simple expression(Camel 2.9 onwards) like in the example below. I am also setting a value to subs_val for the example, but I suppose your header has already a value in the route.
.setHeader("my_template", constant("http://this/that/{id1}/another/thing"))
.setHeader("subs_val",constant("22"))
.setHeader("MY_THING",simple("${in.header.my_template.replaceAll(\"\\{id1.?\",${in.header.subs_val.toString()})}"))
After this step header MY_THING has the value http://this/that/22/another/thing.
1)In this example I could skip to_String() but I do not know what's the type of your header "subs_val" .
2) I tried first with replaceAll(\"\{id1\"}\") but it didn't work with } Probably this is a bug...Will look at it again. That's why in my regex I used .?
3) When you debug your application inside a processor, where the exchange is available you can use SimpleBuilder to evaluate a simple expression easily in your IDE, without having to restart your app
SimpleBuilder.simple("${in.header.url.replaceAll(\"\\{id1.?\",${in.header.subs_val.toString()})}").evaluate(exchange, String.class);
Hope it helped :)

AngularJs directive naming conventions

When angularJs directive is defined, we have to name it in form of 'camelCase' syntax but when we use it, we have to name it in form of 'camel-case'. Question is why this is required ?
I know that it is for avoiding naming conflicts(now/in future) but why we have to name it differently while defining and while using. Can't we define it directly in form of 'camel-case' ?
There are two reasons why it's important.
First of all, HTML attributes are not case sensitive, meaning that "someName" and "somename" is the same attribute. So the best style is to use "kebab-case" notation to separate words in attribute name. That's why we use "attribute-name" syntax for HTML attributes and tag names.
On the other hand, kebab-case names are not valid identifiers in Javascript so in order to use such names as Angular directives we would have to use verbose bracket notation. But since in Javascript world camelCase is standard de-facto for naming variables and object properties, Angular uses normalization (see source) to convert kebab-case names to camelCase, and vice versa.
Directives must have camel case names (for instance, fooBarDirective) because AngularJS converts camel case directive names to hyphen case .For instance
<foo-bar-directive>
or
< ... foo-bar-directive>
for use in HTML(which is case insensitive).

WPF Drag, drop image into canvas, reject wrong ones

I have 8 images and 2 canvas, and i am trying to do a drag drop game, which will be able to reject the wrong image that is drop into the wrong canvas. I tried many codes online just for the drag drop function but it didn't work. The most common error I have is
1) "The type 'WpfApplication9.Window1' already contains a definition for 'butterfly'"
2) 'WpfApplication9.Window1' does not contain a definition for 'Grid_PreviewMouseDown' and no extension method 'Grid_PreviewMouseDown' accepting a first argument of type 'WpfApplication9.Window1' could be found (are you missing a using directive or an assembly reference?)
How do solve the problem? Thankyou in advance
These are very basic errors and developers typically solve these by pasting them into any search engine and reading the result pages. If you can't fix these kinds of problems yourself, you'll have real problems later. Either way, your first error is this:
The type 'WpfApplication9.Window1' already contains a definition for 'butterfly'
In plain English, this means that you have a class named Window1 in a namespace named 'WpfApplication9 (so I'm assuming this is your 9th test application) and in that class, you have declared a property, method, enum, or other member named butterfly... the actual problem is that you have defined two members named butterfly in the same class. You cannot do this, so rename one of them.
Your second error is:
'WpfApplication9.Window1' does not contain a definition for 'Grid_PreviewMouseDown' and no extension method 'Grid_PreviewMouseDown' accepting a first argument of type 'WpfApplication9.Window1' could be found (are you missing a using directive or an assembly reference?)
Again, this is a very common error and simply means that you have attached a PreviewMouseDown event handler to your Grid, but then you didn't actually declare the handler method itself. The solution is to implement your Grid_PreviewMouseDown method.

with HTMLpurifier, how to add a couple attributes to the default whitelist, e.g. 'onclick'

Two questions:
I have been reading docs and SO posts.. and know how to do it the long way (defining each and every element and attribute myself), but all I want to do is add 2 or 3 attributes to the default whitelist.. so that I do not have to constantly find and add more elements/attributes to, e.g., HTML.AllowedElements and/or HTML.AllowedAttributes.
Specifically, now, (for internal trusted users) I need to allow javascript attributes (input from tinymce). Question #1.) Is there a way to just add an attribute (to what HTMLpurifier allows) without causing the whole default sets of allowed elements/attributes to be effectively wiped out (overwritten by ONLY what is explicitly written in HTML.AllowedElements or HTML.AllowedAttributes)?
For what I need right now (the javascript attributes), I got excited when I saw in this thread:
Whitelist Forms in HTML Purifier Configuration
...where Edward Z. Yang says, "... [$config->set('HTML.Trusted', true);] allows JavaScript."
...but even after setting this: $config->set('HTML.Trusted', true);, HTMLpurifier 4.4.0 is still stripping e.g. any input onclick="dostuff();" attribute. Why? Question #2.) Is there a quick way to add just the javascript attributes to the allowed list?
You're losing onclick because HTML Purifier doesn't know about that attribute, and if HTML Purifier passed everything through when you turned on %HTML.Trusted you might as well just not use HTML Purifier at all.
HTML Purifier has attribute collections for just this case; 'Common' is probably the right one to insert them into.
But... why? The real name of %HTML.Trusted really should be %HTML.UnsafeMakeMyApplicationVulnerable
HTMLPurifier does not support onClick and similar java script related attributes to any HTML element as a default behaviour.So if you wish to allow such attribute any way, you may add such attribute to specific element in following way.
$config = HTMLPurifier_Config::createDefault();
$def = $config->maybeGetRawHTMLDefinition()
$def->addAttribute('a', 'onclick', 'Text');
But be careful, this may lead to xss attack as you are allowing any java script code to be there in that attribute.

Resources