I have this URL to match:
$httpBackend.whenGET('/api/alerts/1121212156/0/4/0').repond(someObject)
The problem is that 1121212156 is a tick so it can be different every time. Does someone know how to create a regex to do that?
$httpBackend.whenGET(/\api/alerts/[0-9]+/2/4/0/).
respond(someObject);
The docs for $httpBackend.whenGET say that you can can pass in a regex object in place of a URL. I just did a quick test on regexpal.com to see if this regex works, and it says it does, although I didn't actually test it through whenGET.
var urlRegex = /\/api\/alerts\/[\d]+\/0\/4\/0/;
urlRegex.test('/api/alerts/1121212156/0/4/0'); // returns true
Hope that helps.
Related
I have a variable descriptions that is an Option[JsonArray] (JsonArray results from calling getJsonArray on a JsonObject). descriptions is a list of objects that I'm getting back as a response from a server. Each object has a structure like so:
{age: String,
number: Long,
link: String}
I'd like to loop through this JsonArray and edit the link field to a certain value that is returned from a function. I don't even need to edit it in place and can take a new array of objects. In JS, it might be as simple as descriptions.map(d => ({...d, link: someValue})) but I'm not sure how I need to transform the JsonArray to get this working in Scala. Any help is appreciated!
#mysl didn't provide necessary details as mentioned in the comments. So I'm going to speculate that the approach you've proposed didn't work and you want to understand why.
Most probably you've assumed that JsonArray would be mutated when you .map a lambda over it (which is the case for Javascript I guess). That's not true in Scala case. I.e. when you map a list over you've got another list. I.e. .map, as the name assumes, is just a way to map one collection to another.
So what you need to do is:
val originalJsonArray = ...
val updatedJsonArray = originalJsonArray.map { description =>
description.copy(link = description.link.replace("foo","bar"))
}
println(s"originalJsonArray=$originalJsonArray, updatedJsonArray=$updatedJsonArray")
I hope that helps, though I'm not sure I guessed your problem correctly.
I'm trying to look for specific keywords inside of text from a for each loop.
var text = "The lazy fox jumped over the brown dog."
var keywords = "fox,dog,sun";
If true, I want to do something with the text. If false, I want to ignore the text.
Does anyone know how to use an Array filter, Function, Select, Condition or inline code to check for this? If so, specific examples would be great.
By the way, I have a C# function that handles this extremely well in an ASP.net Core app.
UPDATE 1:
This doesn't work.
UPDATE 2:
The Condition is always false after the for each loop even after changing the settings and parallelism to 1.
Azure Logic App Condition does not work in loop if based on changing values
Thanks in advance!
There are so many ways to achieve what you need. Here are the 3 options that came to my mind within a minute.
The first one does use a For each loop, but I wouldn't recommend using it as it's not very efficient.
The For each parameter looks like this:
The Condition parameter looks like this:
The second option is much easier - no need for a loop, just filter the array straight away, then you can check whether it's empty or it has some items:
The Filter array parameters look as follows.
The split function is identical to the one used in option 1.
If you know JavaScript, you might decide to use regular expressions in inline code instead, e.g.:
Then you'd just need to check the output of the inline code. JavaScript code used in the example above:
var text = workflowContext.actions.Compose_text.outputs;
var keywords = workflowContext.actions.Compose_keywords.outputs;
return text.match(new RegExp("(" + keywords.split(",").join("|") + ")", "gi"));
My personal preference is option 2. However, please note that all 3 options above would find "sun" in text "The weather was sunny" even though there's no word "sun" in the text. If you do need "sun" to match only word "sun" - not "sunny", "asunder" or "unsung" - then go for option 3, just use a different, more complex regular expression.
One of the workaround would be use of Condition Connector. I have initialized the sentence in a string and then used Condition Connector which will be checking the conditions.
Finally, In the true section you can add the connectors accordingly.
Placing a Compose behind the for each loop and referencing the Output in the Condition is what finally worked for me. I used the toLower() function in my Compose. The Compose looks like this.
toLower(items('For_each_2')?['day']?['longPhrase'])
I'm working on someone else's code and I don't fully understand it yet. Besides, I'm fairly new to AngularJS.
They have a class that looks like this:
return vm.item[vm.function](request).$promise.then(function (data) {
...
});
When my vm.function has no parameters, it works perfectly. I just do
vm.function = "myFunction"
and myFunction gets called as expected.
However, now I need to call a function that has an "id" parameter. I have already tried
vm.function = "myFunction(0)"
vm.function = "myfunction({id:0})"
And even adding an "id" element to the "request" var, but no result so far.
How can I make this work?
vm.function is simply the name of the function, it says nothing of the parameters. Let's break down what's going on here.
vm.function = 'myFunction';
vm.item[vm.function](request)
translates to
vm.item['myFunction'](request)
which is equivalent to
vm.item.myFunction(request)
As you can see, it's already passing a request parameter. To add another, you'd simply do:
vm.item[vm.function](request, id)
Keep in mind when using this pattern that your dynamic function signatures must be compatible. If they begin to diverge (as you say, you're editing someone else's code) you should refactor to handle this in a different way.
I am trying to write an expects statement in Protractor that uses the or expected condition. However, the documentation does not have any examples of how to use 'or' or 'and' with these blocks.
I have tried doing
expect(myString).or.toEqual('a string').toEqual('another string')
expect(myString).toEqual('a string').or.toEqual('another string')
and just for kicks
expect(myString).toEqual('a string', 'another string')
This question has been asked previously but only a workaround was given.
I would like to actually use the or function that is built into Protractor as it should allow the message to read something like
Expected 'a totally different string' to be 'a string' or 'another string'
Examples are provided here: http://angular.github.io/protractor/#/api?view=ExpectedConditions. However, you're confusing the use of expected conditions, which is used for browser.wait and not expects.
You can always write a custom matcher. In this case, there is no need to write one, the one provided at Expect item in array would fit your use case. For jasmine 1.x:
this.addMatchers({
toBeIn: function(expected) {
var posibilities = Array.isArray(expected) ? expected : [expected];
return posibilities.indexOf(this.actual) > -1;
}
});
Usage:
expect(myString).toBeIn(["a string", "another string"]);
Just FYI, there is also a useful library of custom jasmine matchers: jasmine-matchers.
This is a bit of a hack, but it just helped me. I am posting it in case it would be useful to someone, not because I think it is the most elegant approach (and it may also be a "workaround"). It works if your strings are really different, and it works for strings, not more generally. For my case, I had to resolve the promise first.
myString.getText().then(function(text){
expect('a stringanother string'.search(text)).toBeGreaterThan(-1);
});
Of course the above would be quite happy to pass partial matches like 'n' or 'another' or nonsense like 'ngano'. None of those were going to happen in my case.
I notice that when I passed a parameter that is an array to $location.search(), it was encoded as in the following example
$location.path('/somePath').search('ids[]=', [1, 2, 3]);
becomes
/somePath?ds%5B%5D=1&ds%5B%5D=2&ds%5B%5D=3
Is there a way to avoid the url encoding?
Excuse the late reply, but I struck a similar predicament myself and thought I'd offer advice.
In short, if you intend on using $location.search you cannot avoid the URL being encoded.
If you take a look at the Angular source, location.js specifically, you'll notice that the functions return composed URLs (i.e. LocationHtml5Url) all rely on another function call named toKeyValue, which will encode all key-value pairs whenever they are set.
Furthermore, in the example use case you've provided, you don't need the equals inside your key. When $location.search is called with two parameters, they are treated as a key-value pair by Angular.
If you need to make use of the location URL after it has been encoded, you could always call decodeURIComponent.
Some years late, but I have found a way to bypass the URI encode made by the $location service: just rewrite the window.encodeURIComponent
var original = window.encodeURIComponent;
window.encodeURIComponent = function (str) {
return decodeURI(str);
};
$location.url('/somePath?ids=[1,2,3]');
window.encodeURIComponent = original;
It is not the best solution, but it works as intended.