insert line break in the message in coffee script - coffeescript

i have a web app written in nodes/coffeescript, one of the coffee script code read data out of db then display message to the browser, it's a long message, i want to break it down by lines, but cannot get the line break work correctly, i tried:
<br>
\n
\n\n
neither of them works, here is my message in coffee script:
message = 'OK<br>'
message += 'last update at 12PM\n'
message += 'outdated\n\n'
callback null, {state: state, message: message}
thanks,

Related

Getting value from splunk search result to Email Alert Message

Im trying to get values from a splunk search into an email alert Message. My splunk search query used to trigger an alert is "resourceGroup="myResourceGroup" severity="Error" (simplified version). The output of the search looks like this
{
msg: Error encountered will getting details from API
resourceGroup: myResourceGroup
severity: Error
sourceContext: SystemContext
success: false
}
Q1: How do i get the msg value from the search result in my email alert? Below is a screen shot of splunk Alert Email Message Box?
Q2: Say i wanted to send msg and sourceContext, is there a way to insert ONLY these fields into a custom table?
.
The first step is to extract the fields you want to use in the alert. A simple way to do that (if not already done) is with rex.
resourceGroup="myResourceGroup" severity="Error"
| rex "msg: (?<msg>[^\n}+)"
| rex "sourceContext: (?<sourceContext>\S+)"
Then reference the fields within $ in the alert message.
Msg = $msg$
sourceContext = $sourceContext$

Outlook Addin Event handler clean up

I am having problems with the event handler in my office addin . Below is an example code i got from microsoft website to explain what i mean.
I have a manifest file that uses the on-send hook as well as a click-based event triggering.
My button calls appendMessageBodyOnClick and onsend i call appendMessageBodyOnSend. Both function primarily do the same thing. I never want to block sending emails regardless.
The problem is that the event object is not properly cleaned up i think.
Scenario 1
When i click my button ; which calls event.completed(), and then after i try to send the message, it says my app is blocking the message, but then when i try to send again it goes through.
Scenario 2
When i leave the subject empty and then send the message, as expected i am prompted that the subject is empty. If i cancel sending the message on this note and then click on my button, the message tries to send as though i clicked send.
I am supposing the is some sort or state clean up issue. What am i doing wrong here?
Function-File.js
function appendMessageBodyOnClick(event) {
// Append string to message body
event.completed();
}
// In the following example, the checkMessage function has
// been registered as an event handler for ItemSend.
function appendMessageBodyOnSend(event) {
// Append string to message body
event.completed({allowEvent = true});
}
Not sure if this will help, but I also have faced some seemingly inconsistent behavior while understanding how to signal that event is fully completed. Once I got my edge cases fixed, then it worked.
One suggestion: Appending string to message body should be an async function. Call the event.completed() from inside the callback function. (i.e: make sure when you are calling event.completed(), nothing else is pending -like another async result)
Something like the following:
Office.context.mailbox.item.body.setAsync("new body", function(asyncResult) {
// handle success and failure
event.completed()
});
Same would be for your scenario 2, make sure event.completed() is called at the very end.

Can we send an e-mail when protractor script fails, with email content as the error showing in the command prompt

I am using protractor cucumber frame work.I have a requirement of sending email when the test failed.I am able to send email from AfterAll function,when the test failed.But i am not able to catch the error from command prompt in order to specify it as the content of the mail.How can i do this?Thanks in advance.
You either need to find a jasmine reporter that already exists that sends emails or build yourself a custom one. The reporter will need a specDone() function that will include details like failed expectations and stacktraces from the test that was just completed. Check out the jasmine documentation for more details.
Here is the example code snippet from the docs:
specDone: function(result) {
console.log('Spec: ' + result.description + ' was ' + result.status);
for(var i = 0; i < result.failedExpectations.length; i++) {
console.log('Failure: ' + result.failedExpectations[i].message);
console.log(result.failedExpectations[i].stack);
}
}

Function within a loop

I'm trying to write a script for hubot to get player statistics for a game, however I am having some trouble with list comprehension.
Here's my code
listings = []
listings =
(for player in players
request "http://pwa.wp3.pl/curvefever/?player=" + player , (err, res, body)->
$ = cheerio.load(body)
msg.send "Hello, world!1"
{name: $('b').slice(0).eq(0).text().toLowerCase(), rank: parseInt($('td').slice(37).eq(0).text(),10)})
msg.send "Hello, world!2"
for player of listings
msg.send "Hello, world!3"
msg.send player.name + " " + player.rank
when running this I get "Hello, world!2" followed by several "Hello, world!1" and no "Hello, world!3" as listings is (presumably) empty.
The script works when I do msg.send instead of trying to capture the listings in an array, however I'd like to sort the listings based on rank too.
Several things are going in here.
First, you do not need to initialize listings as an array first.
Second, I think you're looking for for player in listings.
Third, and I think that's the most important point :
request sends an ajax request. Ajax requests are, by definition, asynchronous.
So what you actually push into your array is the result of "request" : probably nothing.
I'd recommend using a library such as async.js, a promise implementation, etc, or just a i = players.length that you decrement and check each time a request succeeds, to ensure your code awaits all results before it executes.

Editing Gateway Errors

How do you customize the Gateway Errors that pop up when a customer's credit card is declined.
Example would be "Payment transaction failed. Reason Gateway error: An error occurred during processing. Please try again."
We're using Authorize.net if that makes a difference. To clarify, we aren't looking to get rid of them, just modify the language in them.
Copy the file app/code/core/Mage/Paygate/Model/Authorizenet.php to local. Then find this (line 1334):
protected function _wrapGatewayError($text)
{
return Mage::helper('paygate')->__('Gateway error: %s', $text);
}
and replace with this:
protected function _wrapGatewayError($text)
{
if($text == 'This transaction has been declined.') {
$text = 'Custom message here.';
}
return Mage::helper('paygate')->__('Gateway error: %s', $text);
}
I know this is an old question, but I will leave this here for the future in case if someone runs into this.
The _wrapGatewayError() method already uses a helper to output the message, so why not just translate the message?
Create (or edit) your localization/translation file in app/design/frontend/{package_name}/{theme_name}/locale/en_US/translate.csv. You can check the active package_name and theme_name in System / Configuration / Design (under 'General').
Add the messages you are changing to that file in this format: "Old text - message you want to change", "New message".
In your case, it will be something like this:
"Payment transaction failed. Reason Gateway error: An error occurred during processing. Please try again.", "Your custom message"
How it works: whenever a helper is used to output the "Payment translation failed. ...", the system will find the translation file (translate.csv) and will change the message to your custom one.
Please don't modify core files. It creates a mess, interferes with patches, and makes debugging harder. You can extend them if you need to. See Overriding Magento blocks, models, helpers and controllers