How do I duplicate values in jq? - jq

I am trying to duplicate the values that I've received in jq.
For example: If I enter ".address", I get a value "Times Square, New York"
I want to duplicate it so that it gives me the values:
"Times Square, New York"
"Times Square, New York"
"Times Square, New York"
"Times Square, New York"

One way could be to create a stream of 4 arbitrary items, e.g. numbers using range, store them in a variable to not affect the context, and provide your output for each:
range(4) as $_ | .address
You can also use the comma operator , to manually compile your stream:
.address, .address, .address, .address

Related

Can't use "Times New Roman Bold" programmatically in Swift 5

I'm trying to use UIFont(name: "Times New Roman Bold", size: 30.0) at run time but it's returning nil
Here is my code -
lblHeader.font = UIFont(name: "Times New Roman Bold", size: 30.0)
But lblHeader is returning SFUI-Regular when I printed in the console.
I've tried following combination but no luck -
Times New Roman Bold
Times New Roman-Bold
Times New Roman-bold
Times New Roman bold
TimesNewRoman Bold
TimesNewRoman-Bold
I have found the answer here - iOS Fonts
But thanks to Rup for the help.
I hope this answer will help others.
Happy coding :)

Is there a way to get a "table like" appearance to my dropdown entries?

Using a fixed-width font (e.g. Consolas, Courier, etc), I am trying to
populate a dropdown menu (AjaxControlToolkit:DropDownList) that has 2
columns (in appearance). I have a product name and a category name
(neither of which I know until runtime). The appearance I'm looking
for is something like:
Chevy Cruz (gas)
Prius (hybrid)
Tesla Model S (electic)
My list can have over 300 entries and if I just append the category to the
product name, the menu is harder to read.
I've tried using a character array and copying in the category name at the
same index for each ListItem, but the spaces between disappear when the
dropdown list is opened. I've looked at the ListItem(Paragraph) constuctor
but it doesn't look to solve my problem to my understanding of it. I
haven't looked at the Telerik controls I have available because it
would mean a lot of coding changes.
I can't think of another AjaxControlToolkit control that might help.
string padding might be works for you
var _maxLengthOfProductName = 20; //number of space you need
var _productName = "Product Name";
var _type = "(type)";
var _ProductNameWithType = _productName.PadRight(_maxLengthOfProductName, ' ') + _type; //assign this to the dropdown item
_ProductNameWithType = _ProductNameWithType.Replace(" ", " ");
it will show
Product Name (type)

Ternary Search Tree Implementation in R

I'm trying to implement a ternary search tree in R.
Here's the logic I'm trying to implement:
A vector will be "tiered" by designating each level of the tree as the next 3^somepower of cells after the existing tier. So tier 1 will be the first cell, tier 2 will be cells 2-4, tier 3 will be cells 5-13, tier 4 will be cells 14-40, tier 5 will be cells 41-122, and so on.
I want my code to do the following:
1) Take a vector, and an object obj to insert in the tree. In practice obj will be a number.
2) If the slot I'm trying to go into is full, jump down to the next tier, according to the rules:
2a) If obj is < than the occupied cell, go down to the left cell in the next level, of the three-cell-block "directly below" it.
2b) If obj is == the occupied cell, go down to the center cell of the three-cell-block "directly below" it.
2c) If 'obj' is > the occupied cell, go down to the rightmost cell of the three-cell-block "directly below it".
I drew a diagram of what I want the output to be if I put in the numbers 34,42,15,24,16, 34,52,32,42,19,21,16,54,60,55. I included the code that does something, but I don't understand exactly what it's doing. I just know that it isn't doing what I want to do.
Thanks for your help.
Desired output:
My code:
put<-function(obj, Tree,pow=0,offset=1,arity=3)
{
level<-arity^pow
if (is.na(Tree[level])){
Tree[level+offset-1]<-obj
return(Tree)
} else {
if (obj<Tree[level]) {
put(obj,Tree,pow+1,offset=0)
} else {
if (obj == Tree[level]){
put(obj,Tree,pow+1,offset=1)
} else {
if (obj > Tree[level]){
put(obj,Tree,pow+1,offset=2)
}}}}
}
BeforeTree<-c(34,42,15,24,16,
34,52,32,42,19,21,16,54,60,55)
Tree<-NA
for (idx in 1:(length(BeforeTree)))
{Tree<-put(BeforeTree[idx],Tree)}
(Tree)

How to align 2 paragraphs side by side using Novacode DocX?

Using DocX I need to do something like this:
A long
text description.
Except I need the "1." to be a paragraph and the "A long text description" to be a paragraph. I cannot use a list for this.
late answer, but use a 2 column table with no visible borders
some code i hacked out of my current thing. this makes a table and populates the cells with the contents of my cells,
you'd just need to make a table, with 2 columns. and then iterate build a row with with cell[0] for the numeral, and cell[1] for the sentence
doc.InsertParagraph("Table Title: " + (component).SubTitle, false, SubtitleStyle);
var table = doc.AddTable(component.ColumnCount, component.RowCount);
int rowcount = 0;
foreach (DataCell datacell in component.TableData)
{
table.Rows[rowcount].Cells[0].Paragraphs.First().Append(rowcount+1);
table.Rows[rowcount].Cells[1].Paragraphs.First().Append(datacell.CellValue);
rowcount++;
}
doc.InsertTable(table);

qt - In QGraphicsScene how to catch a particular item

I have so many things in my QGraphicsScene. The situation is I am creating a chessboard, and is using Graphics scene. So the QGraphicsScene is having so many QGraphicsPixmapItems. Now In this how can I get the King.
Update:
In this QGraphicsScene, I am adding QGraphicsPixmapItems which are nothing but coins(board,king,queen,soldiers,etc). Now if I want to move a particular coin say King, then How can I get it. There are some methods like using iterators. But is there any way to find a particular QGraphicsPixmapItem by it's name.
When you say you need to get the King, how do you make the difference in your program between the white King and the black one ?
If you need to get a Pawn, how do you know which one ? Anyone ? The first one you can find in your items ?
I haven't thought a lot about it, but maybe what you can do is using a QMap. The key would be a enumeration of the different pieces and the value would be a pointer to the relevant QGraphicsItem. Something like this :
enum Piece_e {
KING,
QUEEN,
ROOK1,
ROOK2,
...
PAWN1,
PAWN2,
...
};
QMap<Piece_e, QGraphicsPixmapItem*> WhitePiecesItems;
QMap<Piece_e, QGraphicsPixmapItem*> BlackPiecesItems;
When you are creating your scene and instanciating your pieces, you'll fill the map :
...
WhitePiecesItem[KING] = new QGraphicsPixmapItem(QPixmap("whiteking_pic"));
WhitePiecesItem[PAWN1] = new QGraphicsPixmapItem(QPixmap("whitepawn_pic"));
...
BlackPiecesItem[QUEEN] = new QGraphicsPixmapItem(QPixmap("whitequeen_pic"));
BlackPiecesItem[PAWN1] = new QGraphicsPixmapItem(QPixmap("whitepawn_pic"));
...
When you need to find the object corresponding to the white king, you could do something like this :
QGraphicsPixmapItem* pItem = WhitePiecesItem[KING];

Resources