Are there alternatives to template literals in Bixby? - bixby

apparently template literals are not supported in the IDE (i get an illegal character warning when I enter the backtick). Is there an alternative? I have the following lengthy expression that I want to include as part of a restdb query:
"_created":{"$gt":{"$date":"$yesterday"}}"
Is there an alternative to painstakingly constructing this as a series of escapes and concatenations? This is what I have right now.
const dateexp = `"_created":{"$gt":{"$date":"$yesterday"}}"`
if (searchTerm) {
const regexterm = "\{\"\$regex\": "
const searchterm = searchTerm
var q1 = "{\"active\" : true, \"_tags\": " + regexterm + "\"" + searchterm + ", " + dateexp +
"\"}}"
console.log("q1 is", q1)

I found a trick that made this considerably easier -- I used the Rhino Online editor at jdoodle.com -- https://www.jdoodle.com/execute-rhino-online/
This sped up the trial & error considerably and I arrived at
var q2 = "{\"active\" : true, \"_tags\": " + regexterm + "\"" + searchterm + "\"\}, " + "\"_created\" : {\"\$gt\" : \{\"\$date\" :\"\$yesterday\"\}\}}"
A console editor in the Bixby IDE would be great!
PS - it helps to learn that in Rhino there is no console.log, but there is a print().

This doesn't help you right now, but the Bixby engineering team is hard at work on the "next generation" of javascript runtime environment for capsule code. I can't say much more than this, but rest assured that in the future, you will have a first-class, modern javascript development experience as a bixby capsule developer.
source: I work on the bixby developer tools team.

Related

Adding a "+" to a " " in node.js for a movie api

I know this will be a simple question. I am new coding and still have a lot to learn. I am running a movie API with node. As you know API's searches cannot have spaces " " and need a plus sign "+" in order to search a string. Example when I search Die Hard on the terminal it comes back as a movie called Die and does not recognize "Hard". If I search it as Die+Hard I will get the movie I am looking for. How do I add that plus sign without having the user write the plus sign in the search? Thank you for your help.
var axios = require("axios");
movieName = (process.argv[2]);
var queryUrl = "http://www.omdbapi.com/?t=" + movieName + "&y=&plot=short&apikey=...";
To replace all instances of a space in a string (let's call it str) with +:
str.replace(/ /g, "+");
To replace all instances of any whitespace characters with a +:
str.replace(/\s/g, "+");
For more information, see the MDN docs on String.prototype.replace().
var movieName = process.argv.slice(2).join("+");
this took care of it. Thank you for the help.

The new line code "\n" and/or #NewLine does not add new line to field

I'm getting document history, adding "\n" and existing document history. Code executes without any error. But when I see it in web everything on one line. In notes client, document history is shown as one line of activity.
Tried with #Newline and same issue.
What I'm doing wrong?
Thanks in advance.
Here is sample code:
var myvar="\n"
var h=getComponent("docHistory1").getValue();
var msg="Stage 2 - LAB Manager approved and completed check. Send to Chemist: " + unm + " + dt1;
document1.setValue("DocHistory", h + myvar + msg);
document1.save();
Use a Multiline Edit Box xp:inputTextarea instead of a Computed field xp:text and set it to Read only readonly="true".
As an alternative you could still use a Computed field replacing all '\n' with '<br />' and setting escape="false".
Just to give an alternative solution, you could use a style on the computed text component with "white-space:pre" (or pre-line or pre-wrap, see this for the differences) and that would preserve the newlines in the content.

Alternative to CONTAINS method?

Giving the string below with "server type" separated by comma:
string serverTypeList = "DB, IIS, CMDB";
//server.Type in the loop below should have value of "MDB"
My problem is that in this scenario it will return TRUE because "MDB" string is inside the serverTypeList.
I need it to return TRUE only if it matches a type of "MDB" and not "CMDB":
...
from site in SiteManager.Sites
from server in site.Servers
where
serverTypeList.Contains(server.Type)
select new Server()
{ ID=server.ID, SiteName=site.Name }
...
How can I change the code above?
Thank you
(", " + serverTypeList + ", ").Contains(", " + server.Type + ", ")
is one standard way to handle this. I'm not clear on the language you're using, so I don't know the exact syntax you would need, but the general idea is to ensure that the term appears between delimiters by forcing delimiters before and after the list string.

Jade variable rendering inside tag specifications

I have a Jade page like so:
table
th Site Name
th Deadline
th Delete Transaction
- if (transactions != null)
each item in transactions
tr
td= item.item_name
td
span(id='countdown' + item.timeout + ')= item.timeout
td
span(style='cursor: pointer;', onclick='deleteTransaction("=item.uniqueId")')= "X"
button(id='confirmButton', onclick='confirm();')Confirm
As you can see in both the span attribute I try to put a local variable in two different ways and it doesn't work. Concerning the first way, I receive a token ILLEGAL error, while the second simply writes in my JavaScript something like deleteTransaction("=item.uniqueId");. I know the answer is something really stupid, but again and again Jade doc (even if it has improved) doesn't help me.
Thanks
To quote the docs:
Suppose we have the user local { id: 12, name: 'tobi' } and we wish to create an anchor tag with href pointing to "/user/12" we could use regular javascript concatenation:
a(href='/user/' + user.id)= user.name
Ergo:
span(id='countdown' + item.timeout)= item.timeout
// ...
span(style='cursor: pointer;', onclick='deleteTransaction("' + item.uniqueId + '")')= "X"
Quoting again:
or we could use jade's interpolation, which I added because everyone using Ruby or CoffeeScript seems to think this is legal js..:
a(href='/user/#{user.id}')= user.name
And so:
span(style='cursor: pointer;', onclick='deleteTransaction("#{item.uniqueId}")')= "X"
As a general tip that you'll use every day of your programming life: balance your quotes. Just like brackets and parentheses, every quotation mark must either open a new quotation or close an already-open quotation (of the same kind, i.e. double-quotes close double-quotes, single-quotes close single-quotes). To borrow your code:
span(id='countdown' + item.timeout + ')= item.timeout
// ^
// |
// What's this guy doing? ---------+
Even though Jade is a templating language and perhaps not a "real" programming language this rule, just as in HTML (also not a programming language), will serve you well.

Lua string.match() problem

I want to match a few lines for a string and a few numbers.
The lines can look like
" Code : 75.570 "
or
" ..dll : 13.559 1"
or
" ..node : 4.435 1.833 5461"
or
" ..NavRegions : 0.000 "
I want something like
local name, numberLeft, numberCenter, numberRight = line:match("regex");
But I'm very new to the string matching.
This pattern will work for every case:
%s*([%w%.]+)%s*:%s*([%d%.]+)%s*([%d%.]*)%s*([%d%.]*)
Short explanation: [] makes a set of characters (for example the decimals). The last to numbers use [set]* so an empty match is valid too. This way the number that haven't been found will effectively be assigned nil.
Note the difference between using + - * in patterns. More about patterns in the Lua reference.
This will match any combination of dots and decimals, so it might be useful to try and convert it to a number with tonumber() afterwards.
Some test code:
s={
" Code : 75.570 ",
" ..dll : 13.559 1",
" ..node : 4.435 1.833 5461",
" ..NavRegions : 0.000 "
}
for k,v in pairs(s) do
print(v:match('%s*([%w%.]+)%s*:%s*([%d%.]+)%s*([%d%.]*)%s*([%d%.]*)'))
end
Here is a starting point:
s=" ..dll : 13.559 1"
for w in s:gmatch("%S+") do
print(w)
end
You may save these words in a table instead of printing, of course. And skip the second word.
#Ihf Thank you, I now have a working solution.
local moduleInfo, name = {};
for word in line:gmatch("%S+") do
if (word~=":") then
word = word:gsub(":", "");
local number = tonumber(word);
if (number) then
moduleInfo[#moduleInfo+1] = number;
else
if (name) then
name = name.." "..word:gsub("%$", "");
else
name = word:gsub("%$", "");
end
end
end
end
#jpjacobs Really nice, thanks too. I'll rewrite my code for synthetic reasons ;-) I'll implement your regex of course.
I have no understanding of the Lua language, so I won't help you there.
But in Java this regex should match your input
"([a-z]*)\\s+:\\s+([\\.\\d]*)?\\s+([\\.\\d]*)?\\s+([\\.\\d]*)?"
You have to test each group to know if there is data left, center, right
Having a look at Lua, it could look like this. No guarantee, I did not see how to escape . (dot) which has a special meaning and also not if ? is usable in Lua.
"([a-z]*)%s+:%s+([%.%d]*)?%s+([%.%d]*)?%s+([%.%d]*)?"

Resources