Topic targeting keywords with commas split into two keywords during validation - url

When searching for keywords and keyword suggestions, there are some keywords that facebook returns, such as "#Dude, Where's My Car?" that have commas in them. While trying to validate them, these keywords get split in two. I've tried a number of things from slashes to urlencode to keep them from getting separated, but I haven't been successful. Anyone have any ideas?
The below url part returns valid for every keyword but not for %23Dude%2c+Where%27s+My+Car%3f
search?type=adkeywordvalid&keyword_list=Hey+Dude+Wheres+My+Car,Dude+Where+Is+My+Car,Dude+Wheres+My+Car,%23Dude%2c+Where%27s+My+Car%3f,Dude+Wheres+My+Car+Then,Dude+Where039s+My+Car,%23The+Hangover,%23Harold+%26+Kumar+Go+to+White+Castle

Turns out it's not so much a bug as a documentation issue.
You just need to surround the keyword by urlencoded quotes AND square brackets:
["#Dude, Where's My Car?"]
becomes
%5B%22%23Dude%2C%20Where's%20My%20Car%3F%22%5D
... and the result is correct:
{
"data": [
{
"name": "#Dude, Where's My Car?",
"valid": true,
"id": "6003406131991"
}
]
}

Related

Exclude empty fields from Log4J2 JsonTemplateLayout output

The log4j2 PatternLayout offers a %notEmpty conversion pattern that allows you to skip sections of the pattern that refer to empty variables.
Is there any way to do something similar for JsonTemplateLayout, specifically for thread context data (MDC)? It correctly (IMO) suppresses null fields, but it doesn't do the same with empty ones.
E.g., given the following in my JSON template:
"application": {
"name": { "key": "x-app", "$resolver": "mdc" },
"context": { "key": "x-app-context", "$resolver": "mdc" },
"instance": {
"name": { "key": "x-appinst", "$resolver": "mdc" },
"context": { "key": "x-appinst-context", "$resolver": "mdc" }
}
}
is there a way to prevent blocks like this from being logged, where the only data in the subtree is the empty string values for context?
"application":{"context":"","instance":{"context":""}}
(Yes, ideally I'd prevent those empty strings being put into the context in the first place, but this isn't my app, I'm just configuring it.)
JsonTemplateLayout author speaking here. Currently, JsonTemplateLayout doesn't support blank property exclusion for the following reasons:
The definition of empty/blank is ambiguous. One might have, null, {}, "\s*", [], [[]], [{}], etc. as valid JSON values. Which one of these are empty/blank? Let's assume we have agreed on a certain behavior. Will it apply to the rest of its users?
Checking if a value is empty/blank incurs an extra runtime cost.
Most of the time you don't care. You persist logs in a storage system, e.g., ELK stack, and there blank value elimination is provided out of the box by the storage engine in the most efficient way.
Would you mind sharing your use case, please? Why do you want to prevent the emission of "context": "" properties? If you deliver your logs to Elasticsearch, there you can easily exclude such fields via appropriate index mappings.
Near as I can tell, no. I would suggest you create a Jira issue to get that addressed.

regular expression for removing empty lines produces wrong results

Can someone help me solve the problem I'm having with a regular expression? I have a file containing the following code:
I'm using a visit to find matches and replace them so that I can remove the empty lines. The result is, however, not what I'm expecting. The code is as follows:
str content = readFile(location);
// Remove empty lines
content = visit (content) {
case /^[ \t\f\v]*?$(?:\r?\n)*/sm => ""
}
This regular expression also removes non empty lines resulting in an output equal to:
Can someone explain what I'm doing wrong with the regular expression as well as the one shown below? I can't seem to figure out why it's not working.
str content = readFile(location);
// Remove empty lines
content = visit (content) {
case /^\s+^/m => ""
}
Kind regards,
Bob
I think the big issue here is that in the context of visit, the ^ anchor does not mean what you think it does. See this example:
rascal>visit ("aaa") { case /^a/ : println("yes!"); }
yes!
yes!
yes!
visit matches the regex at every postfix of the string, so the ^ is relative for every postfix.
first it starts at "aaa", then at "aa" and then at "a".
In your example visit, what will happen is that empty postfixes of lines will also match your regex, and substitute those by empty strings. I think an additional effect is that the carriage return is not eaten up eagerly.
To fix this, simply not use a visit but a for loop or while, with a := match as the condition.

How to escape special symbols in "term" query

I try to find records in elastic using "term". Like this:
bool: {
must: [
{term: {"contexts.key": "resource"}},
{term: {"contexts.tag.name": 'billing/partner_accounts'}}
]
}
But search request returns nothing. Looks like it's waiting to escape slash symbol inside my term sentence. So... I tried next variants: 'billing/partner_account', 'billing/partner_account', 'billing\/partner_account'. It didn't give success result. If replace "term" with "match" it will return results for "contexts.tag.name" that include "billing" or "partner_accounts" substrings. But I need to exact matching. Can you please explain what should I to do. Thanks
the problem was resolved with adding "keyword" to field's name, like
term: { "contexts.tag.name.keyword": 'bla-bla-bla' }

How to access nested JSON in Google Tag Manager value collection in iOS Swift

I'm using the GoogleAnalytics-iOS-SDK 3.10 with iOS 8.1/Swift/XCode 6.1.
I have a GTM container with a value collection macro, which has nested JSON, like this:
{
"cat":
{
"legs": 4,
"sound": "meow"
},
"dog":
{
"legs": 4,
"sound": "woof"
},
"fox":
{
"legs": 4,
"sound": "?"
}
}
How do I get the number of legs a dog has? I've tried (among other variations)
container.stringForKey("dog.legs"), where container is an instance of TAGContainer, and that doesn't work.
If I inspect container.stringForKey("dog"), I get a string, "{legs=4, sound=woof}". Unfortunately, I can't use the .propertyList() string method to get a dictionary from the string because there are commas instead of semicolons, and even if I replace the commas with semicolons, I run into issues if values have spaces in them. For instance, if I used "woof woof" instead of just "woof", the .propertyList() method fails to parse a dictionary from the string. It's also not a valid JSON string so I can't use JSON parsing tools, either.
Is there a clean (or at least recommended) way to do this in Swift?

How do I scan url for a specific string with spaces and special characters?

I'm using stringscanner on my request URL in order to get the name of the user's currently selected category, but I've been having difficulty dealing with spaces and special characters.
request.url.scan(/\?category=\w+/).to_s.gsub('?category=', '')
URL examples followed by result
http://localhost:3000/search?category=dog&search=&utf8=%E2%9C%93 => ["dog"]
http://localhost:3000/search?category=dog.com&search=&utf8=%E2%9C%93 => ["dog"]
http://localhost:3000/search?category=dog+cat&search=&utf8=%E2%9C%93 => ["dog"]
I'm trying to get ["dog"] ["dog.com"] and ["dog cat"], but am currently stuck. Any ideas?
Note: Considering removing spaces from categories and replacing them with dashes as multiple spaces could be problematic, but if it's possible to create one function to rule them all, that would be awesome.
This is Rails, is there a reason you're not just using params[:category]?
If you are trying to extract params then you could use parse_query :
uri = "http://localhost:3000/search?category=dog+cat&search=&utf8=%E2%9C%93"
result = Rack::Utils.parse_query(URI(uri).query) #=> {"category"=>"dog cat", "search"=>"", "utf8"=>"\xE2\x9C\x93"}
result["category"] #=> dog cat

Resources