PlantUML port position in component diagram - plantuml

Here is my code and how it is rendered
#startuml
skinparam componentStyle rectangle
component A1 {
port P1
[E1]
[E2]
[E1] -r-> [E2]
[E2] -r-> P1
}
component A2 {
port P2
[E1] as e
P2 -r-> e
}
P1 -r-> P2
#enduml
How to make P1 and P2 are on the vertical edges of A1 and A2 respectively?
Thanks.

Try with left to right direction and remove the explicit direction on the arrows.
left to right direction
skinparam componentStyle rectangle
component A1 {
port P1
[E1]
[E2]
[E1] --> [E2]
[E2] --> P1
}
component A2 {
port P2
[E1] as e
P2 --> e
}
P1 --> P2

Related

Import data from different columns and paste in rows using google sheet

I've this data, but my problem is to concatenate the information into lines, cause works on the way
First will the the COl A til COl D to filter where we have mismatches between A and D, but also take where on Col D has text. But I already build this part.
And do the same with the Col E til Col H.
A B C D E F G H
2020-04-30 BA BU fsdf 2020-04-30 G X
2020-04-30 BU BA 2020-04-30 L Z
2020-04-29 BA BU 2020-04-29 H W
2020-04-29 BU BA 2020-04-29 G Q dfdf
2020-04-28 BA BU sdfsdfs 2020-04-28 L W dfdf
2020-04-28 AA BA 2020-04-28 H AA
2020-04-25 AA BA 2020-04-25 G X fd
2020-04-22 BU BA sdfsdfs 2020-04-22 L Z
2020-04-19 AA BU 2020-04-19 H W d
2020-04-19 AA BA 2020-04-19 G Q
2020-03-27 BA AA sdfsdf 2020-03-27 L W
2020-03-27 BA AA 2020-03-27 H AA dfdf
2020-03-26 BU AA 2020-03-26 G X
2020-03-18 BA AA 2020-03-18 L Z
2020-03-18 AA BU 2020-03-18 H W
My problem is cause I want to the same from Col E til Col H but pasting below the previous information. I'd like to have on this way:
2020-04-30 BA BU fsdf
2020-04-28 BA BU sdfsdfs
2020-04-22 BU BA sdfsdfs
2020-03-27 BA AA sdfsdf
2020-04-29 G Q dfdf
2020-04-28 L W dfdf
2020-04-25 G X fd
2020-04-19 H W d
2020-03-27 H AA dfdf
I alreaby built the script in two ways but I cound't do on a way that I can concatenate or do something like that.
=filter(importrange("xx","Database!$A:$D"),importrange("xx","Database!$B:$B")<>importrange("xx","Database!$C:$C"),istext(importrange("xx","Database!$D:$D")))
query(importrange("xx","Database!$A:$AA50"),"SELECT Col1,Col4 WHERE (Col2<>Col3 and Col4 is not null)")
try:
=QUERY({IMPORTRANGE("xx", "Database!A:D");
IMPORTRANGE("xx", "Database!E:H")},
"select Col1,Col4
where Col2<>Col3
and Col4 is not null", 0)

Erratic behavior with NULL '\0' when printing combinations of letters

My intention with this code is to print all possible combinations between the letters of the alphabet, **including single letters.**I wrote this part of a program from CS50x course (week 2 - crack)
I include the use of '\0' in order to get as well the single letters. It all works well until it starts working on the uppercase letters, after then it will skip '\0' once every two loops. The result is I am missing half of single uppercase letters and I have no idea why it acts this way.
This is an extract of the result I get (this part is correct, notice single letters 'g', 'h', 'i' all get printed):
Blockquote fZ g ga gb gc gd ge gf gg gh gi gj gk gl gm gn go gp gq gr gs gt gu gv gw gx gy gz gA gB gC gD gE gF gG gH gI gJ gK gL gM gN gO gP gQ gR gS gT gU gV gW gX gY gZ h ha hb hc hd he hf hg hh hi hj hk hl hm hn ho hp hq hr hs ht hu hv hw hx hy hz hA hB hC hD hE hF hG hH hI hJ hK hL hM hN hO hP hQ hR hS hT hU hV hW hX hY hZ i ia ib ic
But after a while it starts skipping letters (it prints 'W' and 'Y' but not 'X')
Blockquote VZ W Wa Wb Wc Wd We Wf Wg Wh Wi Wj Wk Wl Wm Wn Wo Wp Wq Wr Ws Wt Wu Wv Ww Wx Wy Wz WA WB WC WD WE WF WG WH WI WJ WK WL WM WN WO WP WQ WR WS WT WU WV WW WX WY WZ Xa Xb Xc Xd Xe Xf Xg Xh Xi Xj Xk Xl Xm Xn Xo Xp Xq Xr Xs Xt Xu Xv Xw Xx Xy Xz XA XB XC XD XE XF XG XH XI XJ XK XL XM XN XO XP XQ XR XS XT XU XV XW XX XY XZ Y Ya
This is the original code:
int main(void)
{
char abc[52] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char xyz[3];
char null = '\0';
for (int i = 0; i < 52; i++)
{
xyz[0] = abc[i];
xyz[1] = null;
printf("%s ", xyz);
for (int j = 0; j < 52; j++)
{
xyz[1] = abc[j];
printf("%s ", xyz);
}
}
printf("\n");
}'''
With
xyz[1] = abc[j];
you overwrite the null terminator you just set.
Better to initialize the whole array to zero (the null terminator)
char xyz[3] = { '\0' };
Then you don't need to explicitly set a null terminator a second time for the inner loop.
OK, so I moved on to the next week of the course and they introduced an IDE which I used to try on this. As #Weather Vane points out, it works perfectly this time. So I assume the code was not entirely wrong, just somehow the previous sandbox on which I was compiling and running the program may be the problem here. Thanks to all who posted!

Remove elements from an array in bash

So I just need to remove matching pairs in an array. My array consists of a deck of cards. If an element is a pair, for example if the array $sortedHand is: SA DA C9 C8
Because their is a pair of aces in spades and diamonds. I need to remove it from the array $sortedHand
So then the new variable maybe $removedHand would only contain C9 C8. Hope you understand
#!/bin/bash
declare -a cards=(null SA HA DA CA SK HK DK CK SQ HQ DQ CQ SJ HJ DJ CJ ST HT DT CT S9 H9 D9 C9 S8 H8 D8 C8 S7 $
declare -a sortedHand
for i
do
hand+=' '${cards[i]}
done
set -- $(printf "%d\n" "$#" | sort -n)
for i
do
sortedHand+=' '${cards[i]}
done
echo The hand is $hand
echo Sorted hand $sortedHand
Edit I have added code
#!/bin/bash
declare -a cards=(null SA HA DA CA SK HK DK CK SQ HQ DQ CQ SJ HJ DJ CJ ST HT DT CT S9 H9 D9 C9 S8 H8 D8 C8 S7 $
for i
do
hand+=' '${cards[i]}
done
set -- $(printf "%d\n" "$#" | sort -n)
for i
do
sortedHand+=' '${cards[i]}
done
echo The hand is $hand
echo Sorted hand $sortedHand
for((i=0; i -le ${#hand}; ++i))
do
for((j=0; j -le ${#hand}; ++j))
do
if [ $i == $j ]
then continue
fi
if [ ${hand[i]:1:1} == ${hand[j]:1:1} ]
then continue 2
fi
done
sortedHand+=' '${hand[i]}
done
echo Remaining cards $sortedHand
This is the output I get
turtle.sh 1 2 5 10
The hand is SA HA SK HQ
Sorted hand SA HA SK HQ
./turtle.sh: line 23: ((: i -le 12: syntax error in expression (error token is "12")
Remaining cards SA HA SK HQ
Help please
Another Edit
#!/bin/bash
declare -a cards=(null SA HA DA CA SK HK DK CK SQ HQ DQ CQ SJ HJ DJ CJ ST HT DT CT S9 H9 D9 C9 S8 H8 D8 C8 S7 $
for i
do
hand+=' '${cards[i]}
done
set -- $(printf "%d\n" "$#" | sort -n)
for i
do
sortedHand+=' '${cards[i]}
done
echo The hand is $hand
echo Sorted hand $sortedHand
for((i=0; i-le${#sortedHand}; ++i))
do
for((j=0; j-le${#sortedHand}; ++j))
do
if [ $i == $j ]
then continue
fi
if [ ${sortedHand[i]:1:1} == ${sortedHand[j]:1:1} ]
then continue 2
fi
done
remainingHand+=${hand[i]}
done
echo Remaining cards $remainingHand
The outcome of above code
turtle.sh 1 2 5 10
The hand is SA HA SK HQ
Sorted hand SA HA SK HQ
Remaining cards
Thanks for all your help
Also tried your exact code
turtle.sh 1 2 5 10
The hand is SA HA SK HQ
Sorted hand SA HA SK HQ
Remaining cards SA HA SK HQ
Loop through hand and loop through hand again from the current index of the outer loop.
Compare the second letter of the elements and add index to sortedHand if no matches were found.
That would look like this:
cards=(null SA HA DA CA SK HK DK CK SQ HQ DQ CQ SJ HJ DJ CJ ST HT DT CT S9 H9 D9 C9 S8 H8 D8 C8 S7)
for i in $# # $# are all passed arguments, if this gives issues try putting quotes around it
do hand+=(cards[i])
done
for((i=0; i < ${#hand[#]}; ++i)) # C style loop, uses i and <, not $i and -le.
do
for((j=0; j < ${#hand[#]}; ++j)) # ${#hand[#]} is the number of elements in the array hand.
do
if [ $i == $j ]
then continue
fi
if [ ${hand[i]:1:1} == ${hand[j]:1:1} ]
then continue 2
fi
done
sortedHand+=(${hand[i]})
done
echo ${hand[#]} # ${hand[#]} is the array in string representation.
echo ${sortedHand[#]}
To delete an element from an array, use the unset command (with quotes to avoid pathname expansion):
#!/bin/bash
declare -a cards=(null SA HA DA CA SK HK DK CK SQ HQ DQ CQ SJ HJ DJ CJ ST HT DT CT S9 H9 D9 C9 S8 H8 D8 C8 S7 $)
echo "${cards[#]}" # null SA HA DA CA SK HK DK CK SQ HQ DQ CQ SJ HJ DJ CJ ST HT DT CT S9 H9 D9 C9 S8 H8 D8 C8 S7 $
unset 'cards[1]'
echo "{cards[#]}" # null HA DA CA SK HK DK CK SQ HQ DQ CQ SJ HJ DJ CJ ST HT DT CT S9 H9 D9 C9 S8 H8 D8 C8 S7 $

How to reshape 1D RGB to 2D RGB image in Matlab?

Suppose I have 1D RGB array of the following structure:
I = [r1 r2 ... rN; g1 g2 ... gN; b1 b2 ... bN];
where
N = H*W;
ans H and W are height and width of the picture respectively.
How to reshape it to colored image format HxW, which is represented by 3D matrix so that
I2(1,1,1) = r1
I2(1,1,2) = g1
I2(1,1,3) = b1
I2(2,1,1) = r2
I2(2,1,2) = g2
I2(2,1,3) = b2
...
I2(H,W,1) = rN
I2(H,W,2) = gN
I2(H,W,3) = bN
(if I am correct thinking that normal 1D -> 2D reshape works by columns)
UPDATE
This reshaping can be done the following way
R = I(1,:);
R = reshape(R,H,W);
G = I(2,:);
G = reshape(G,H,W);
B = I(3,:);
B = reshape(B,H,W);
I2 = cat(3, R, G, B);
Can it be done shorter, with one reshape call for example?
I think that what you're looking for is: reshape(I', H, W, 3)

Kill a process group

I have a process tree as P1 ⟶ P2 ⟶ P3 ⟶ P4 ⟶ P5 (so P2 is child for P1 and P3 is child for P2 and so on).
Process P1 and P2 belong to same process group.
Process P3 and P4 and P5 belong to other process group.
In process P1, we know the process group of P3, P4 and P5 (it is the value P3) and we are sending the SIGKILL to this process group. using kill(-P3, SIGKILL).
The expectation is this will kill P3, P4 and P5 but not P2 but the observation is that P2
also got killed.
I have a two questions here:
Why is P2 getting killed?
What would be the exit status of P2 we will be getting in P1.

Resources