Jade/Pug if else condition usage - node.js

I'm sending a date to a .jade file from my .js file using Node.js. When the #{date} field is false, it executes the else and print man as it's answer. What could be going wrong?
if #{date} == false
| #{date}
else
| man

If date is false, do you want to output the string 'man'?
If yes, your if and else statements are the wrong way around...
How about:
if date
= date
else
| man
or even:
| #{date ? date : 'man'}
or simply:
| #{date || 'man'}

Within if expression you write plain variable names, without #{...}
if date == false
| #{date}
else
| man

Your statement was backwards. For the syntax, You can use this style to work:
p Date:
if date
| date
else
| man
Its correct that you don't need the #{} within expression. I was not able to get the = to work, or other ways on the other answers.
Ternary Style
For Myself, I too was looking for the ternary operator to do this on one line. I whittled it down to this:
p Date: #{(date ? date : "man")}
Alternatively, you can use a var, which adds one more line, but is still less lines than OP:
- var myDate = (date ? date : "man")
p Date: #{myDate}
I was not able to get the following to work, as suggested in another answer.
| #{date ? date : 'man'}

Related

Generate hyperlink in Sharepoint

I have to generate an hyperlink in sharepoint based on sql table like this:
+----+----------------------------+
| ID | path |
+----+----------------------------+
| 1 | file://test/9932323.pdf |
+----+----------------------------+
| 2 | file://test/1653156423.pdf |
+----+----------------------------+
Actually there is this code to generate html link:
<asp:Label runat="server" id="ff1{$ID}" text="{$thisNode/#PATH}" />
I cannot modify SQL table (dinamically generated) but I have to substitute:
/test/ with /test.abc.local/
and
displayed text with filename only ("path" field substring after last '/')
How can I to that without creating new view or calculated fields?
I tried with:
<a href="{REPLACE($thisNode/#PATH),12,1,'.abc.local/')}"><asp:L ...
but with no success. (I'm really newbie in Sharepoint)
thanks
I'm not going to remove the previous answer because it still valid and it is pretty handy if somebody comes across the same issue, so the RegEx() expression you will have something like this:
/(file\:\/\/)/g
Using the expression above you can find the string you want, so the example below gives you all the LABELS on a page, and from there you can use the following:
.replace( new RegExp("/(file\:\/\/test)","gm"),"/test.abc.local")
Using the expression above you can find the string you want, so the example below gives you all the LABELS on a page, and from there you can use the following:
$('input[type=text]').each(
function(index)
{
console.log(' text: ' + $(this).val() + ' replace: ' + $(this).val().replace( new RegExp("(file\:\/\/test)","gm"),"/test.abc.local") );
}
);
If I understood your question correctly, I would strongly suggest you to use RegEx(), it is possibly the most handy thing ever created to handle string find/replacement.
You can put a JavaScript function to perform the RegEx() substitution on the page inside of a <script language="javascript"></script> , then on your <asp:label> you will replace the output for calling this function by passing the string #thisNode/#PATH to the JavaScript function you wrote, which will find and replace the substring for the desired output

HiveQL string function questions

I'm using HiveQL to run the below query.
The intention is that the case statement removes the last XX characters from the end of the domain, dependent on the suffix (.com, .co.uk).
This doesn't seem to work as there is no change to the strings in the 'domainnew' column in the output.
Can anyone advise how I would make this work?
I also then need to take the output of 'domainnew' and take only the characters to the right of the first '.' when reading from the right handside.
domain = mobile.domain.facebook.com
domainnew = mobile.domain.facebook
newcalc = facebook
Any advice on this would be brilliant!!
Thank you
select domain, catid, apnid, sum(optimisedsize) as bytes,
CASE domain
WHEN instr(domain, '.co.uk') THEN substr(domain,LENGTH(domain)-6)
WHEN instr(domain, '.com') THEN substr(domain,LENGTH(domain)-6)
ELSE domain
END as domainnew
from udsapp.web
where dt = 20170330 and hour = 04 and loc = 'FAR1' and catid <> "0:0" group by domain, catid, apnid sort by bytes desc;
with t as (select 'mobile.domain.facebook.com' as domain)
select regexp_extract(domain,'(.*?)(\\.com|\\.co\\.uk|)$',1) as domainnew
,regexp_extract(domain,'.*?([^.]+)(\\.com|\\.co\\.uk|)$',1) as new_calc
from t
;
+------------------------+----------+
| domainnew | new_calc |
+------------------------+----------+
| mobile.domain.facebook | facebook |
+------------------------+----------+

Asciidoctor parametetrized template

I am using asciidoctor using asciidoctor-maven-plugin. In my document (actually documentation), I have one block repeated many times. Is there any way to do include with parameters.
What I want in pseudocode, I can't find how to write it:
template:
=== HTTP request
include::{snippets}/{variable}/http-request.adoc[]
=== HTTP response
include::{snippets}/{variable}/http-response.adoc[]
Usage
include template[variable=customer]
Thanks.
I think you can redefine attributes. With this tree:
Folder
| main.adoc
| template.adoc
|
\---code
+---first
| http-request.adoc
| http-response.adoc
|
\---second
http-request.adoc
http-response.adoc
My main.adoc file looks like this:
:snippets: code
== First Chapter
:variable: first
include::template.adoc[]
== Second Chapter
:variable: second
include::template.adoc[]
== End
This is the end.
The previous example works, but I have the feeling that this is not exactly what you want.
If you are looking for a Macro example, have a look at this maven & java example: java-extension-example.

Pycassa: how to query parts of a Composite Type

Basically I'm asking the same thing as in this question but for the Python Cassandra library, PyCassa.
Lets say you have a composite type storing data like this:
[20120228:finalscore] = '31-17'
[20120228:halftimescore]= '17-17'
[20120221:finalscore] = '3-14'
[20120221:halftimescore]= '3-0'
[20120216:finalscore] = '54-0'
[20120216:halftimescore]= '42-0'
So, I know I can easily slice based off of the first part of the composite type by doing:
>>> cf.get('1234', column_start('20120216',), column_finish('20120221',))
OrderedDict([((u'20120216', u'finalscore'), u'54-0'),
((u'20120216', u'halftimescore'), u'42-0')])
But if I only want the finalscore, I would assume I could do:
>>> cf.get('1234', column_start('20120216', 'finalscore'),
column_finish('20120221', 'finalscore'))
To get:
OrderedDict([((u'20120216', u'finalscore'), u'54-0')])
But instead, I get:
OrderedDict([((u'20120216', u'finalscore'), u'54-0'),
((u'20120216', u'halftimescore'), u'42-0')])
Same as the 1st call.
Am I doing something wrong? Should this work? Or is there some syntax using the cf.get(... columns=[('20120216', 'finalscore')]) ? I tried that too and got an exception.
According to http://www.datastax.com/dev/blog/introduction-to-composite-columns-part-1, I should be able to do something like this...
Thanks
If know all the components of the composite column then you should the 'columns' option:
cf.get('1234', columns=[('20120216', 'finalscore')])
You said you got an error trying to do this, but I would suggest trying again. It works fine for me.
When you are slicing composite columns you need to think about how they are sorted. Composite columns sort starting first with the left most component, and then sorting each component toward the right. So In your example the columns would look like this:
+------------+---------------+------------+---------------+------------+----------------+
| 20120216 | 20120216 | 20120221 | 20120221 | 20120228 | 20120228 |
| finalscore | halftimescore | finalscore | halftimescore | finalscore | halftimescore |
+------------+---------------+------------+---------------+------------+----------------+
Thus when you slice from ('20120216', 'finalscore') to ('20120221', 'finalscore') you get both values for '20120216'. To make your query work as you want it to you could change the column_finish to ('20120216', 'halftimescore').

How can a text file be automated converted like this using tools in linux?

I have a text file with several lines.
I want to do the following:
1. Remove the first 14 characters. Leave the next 8 characters. Then delete everything on the line after that.
Then the file looks something like this.
20050013
AC040020
AC050024
At the beginning of each line, I want to add something like RAM[n] = 'h, where n keeps incrementing. I also want to add a ; at the end.
Then the file looks like this
RAM[0] = 'h20050013;
RAM[1] = 'hAC040020;
RAM[2] = 'hAC050024;
There has to be 10 entries in the file. So I add remaining entries and set them to 0. The file ends up like this:
RAM[0] = 'h20050013;
RAM[1] = 'hAC040020;
RAM[2] = 'hAC050024;
RAM[3] = 'h00000000;
RAM[4] = 'h00000000;
RAM[5] = 'h00000000;
RAM[6] = 'h00000000;
RAM[7] = 'h00000000;
RAM[8] = 'h00000000;
RAM[9] = 'h00000000;
I guess I could use a perl script or vi. How can this process be automated?
Have you read man sed?
Did you try doing it using awk ? awk has a lot of features but its a little tough to write as code the thing that you are exactly trying to do.
http://www.thegeekstuff.com/2010/01/awk-introduction-tutorial-7-awk-print-examples/
You can check this link for possible examples...
Use Awk.
{
printf("RAM[%d] = '%s;\n", NR - 1, $0)
}
(Put that in foo.awk, then run awk -f foo.awk on your data.)
This is very easy to do with AWK. Use substring and $NR

Resources