How to set tty-clock output as background - background

I would like to set tty-clock output as background for my i3 setup.
I want to know how to display a command output as background.
Things I tried so far:
Running a script that supposedly would run tty-clock and take its screenshot with scrot once a minute and feh would set it as background.Problem: tty-clock would stay on without ever letting next command to run and scrot is a screenshot utility and it would capture whatever I am looking at. Or I would need to switch to that workspace every minute to run, shot, kill, set as background.
tty-clock && killall tty-clock
scrot ~/Pictures/Wallpaper/background.png
feh ~/Pictures/Wallpaper/background.png
save tty-clock output to a file which supposedly would be converted into image by convert (by imagemagick) and feh would set it as background.Problem: tty-clock output is more than just clock which I guess give information about characters' colors or place.
tty-clock | cat > ~/TEMP/tty-clock-output
tty-clock-output
[?1049h[22;0;0t[1;39r(B[m[4l[?7h[?1h=[39;49m[?25l[39;49m(B[m[H[2J[17;59H[H[2J[7;12H[17;59H
[64G[45m
[Z
[Z
[Z
[Z [49m(B[m[18d [45m [49m(B[m [45m
[67G [49m(B[m [45m
[67G
[49m(B[m[18;79H[45m [19;75H [49m(B[m [45m [49m(B[m [45m
[79G [49m(B[m [45m [21;75H [49m(B[m [45m [49m(B[m [45m
[79G [49m(B[m[18d [45m [49m(B[m [45m
[86G [49m(B[m [45m
[86G
[49m(B[m[22;66H [22;85H[92G[22;66H [22;85H[92G[22;66H [22;85H[92G[22;66H [22;85H[92G[22;66H [22;85H[92G[22;66H [22;85H[92G[22;66H [22;85H[92G[39;1H[?12l[?25h[?1049l[23;0;0t
[?1l>[?1049h[22;0;0t[1;39r(B[m[4l[?7h[?1h=[39;49m[?25l[39;49m(B[m[H[2J[17;59H[H[2J[7;12H[17;59H
[64G[45m
[Z
[Z
[Z
[Z [49m(B[m[18d [45m [49m(B[m [45m
[67G [49m(B[m [45m
[67G
[49m(B[m[18;79H[45m [19;75H [49m(B[m [45m [49m(B[m [45m
[79G [49m(B[m [45m [21;75H [49m(B[m [45m [49m(B[m [45m
[79G [49m(B[m[18d [45m
[86G
[86G [49m(B[m[22;66H [22;85H[92G[22;66H [22;85H[92G[39;1H[?12l[?25h[?1049l[23;0;0t
[?1l>

You don't need to invoke tty-clock at all: a script which sends the output of date (formatted to suit) to a text file, and then runs convert on that should do the trick. You'll need to spend some time playing with the convert parameters to get the desired look of course.

Related

Why is total_voter_count always = 1 in Telegram Bot Poll object?

Bot send poll in the bot chat(not in group). After user have chose answer(in my case, rated the movie) in the Poll, my Telegram Bot receive that json with Poll object info:
{'update_id': 684537001, 'poll': {'id': '5373079957893284661', 'question': 'Оцінити фільм "The Godfather"', 'options': [{'text': '10 point', 'voter_count': 1}, {'text': '9 point', 'voter_count': 0}, {'text': '8 point', 'voter_count': 0}, {'text': '7 point', 'voter_count': 0}, {'text': '6 point', 'voter_count': 0}, {'text': '5 point', 'voter_count': 0}, {'text': '4 point', 'voter_count': 0}, {'text': '3 point', 'voter_count': 0}, {'text': '2 point', 'voter_count': 0}, {'text': '1 point', 'voter_count': 0}], 'total_voter_count': 1, 'is_closed': False, 'is_anonymous': True, 'type': 'regular', 'allows_multiple_answers': False}}
Here, you can see that total_voter_count=1 . And it repeats even, if more than one user gave the answer. This is not good for me, because I want the users, after give the answer, to see how other users rated the movie. For example: 80% give 8 point and 20% give 6 point. How I can realize it by using Poll for Telegram Bots, without using only InlineKeyboardMarkup with callback_data. So I want the total_voter_count to increase after each user answer

Filling 1D arrays into 3D arrays vectorisation

I have a function init_tensor() which broadcasts a 2d matrix of dimension (N,N) into 3d block matrix of dim (M,N,N) so that there are M matrices of dimension NXN:
def init_tensor(input_state, sample_size):
return np.broadcast_to(input_state, (sample_size,)+input_state.shape)
So for example if I want to create 3 (4x4) matrices then I could do:
init_tensor(np.eye(4, dtype=complex), 3)
Out[462]:
array([[[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
[0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]],
[[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
[0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]],
[[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
[0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j],
[0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j]]])
The problem I have is that I have some arrays with dim (1,M) which I'd like to fill into the 3D array as its elements. For a simple case if M was 3 and I have:
lambda1 = [l11,l12,l13]
lambda2 = [l21,l22,l23]
lambda3 = [l31,l32,l33]
tau1 = [t11,t12,t13]
tau2 = [t21,t22,t23]
tau3 = [t31,t32,t33]
I'd like a vectorised way where I can fill them into the tensor such that it becomes:
array([[[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[ t11, l11, 0.+0.j, 0.+0.j],
[ t21, 0.+0.j, l21, 0.+0.j],
[ t31, 0.+0.j, 0.+0.j, l31]],
[[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[ t12, l12, 0.+0.j, 0.+0.j],
[ t22, 0.+0.j, l22, 0.+0.j],
[ t32, 0.+0.j, 0.+0.j, l32]],
[[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
[ t13, l13, 0.+0.j, 0.+0.j],
[ t23, 0.+0.j, l23, 0.+0.j],
[ t33, 0.+0.j, 0.+0.j, l33]]])
The depth of the tensor matrix will always be the same as the length of the 1D arrays, and the value of M can vary between 1 to 100.
You can use numpys advanced indexing to get this result:
import numpy as np
m = 3
n = 4
arr = np.ones((m, n, n), dtype=int)
lmbda = 10 * np.arange(1, (n-1)**2+1).reshape(n-1, n-1)
# lmbda = [[l11,l12,l13]
# [l21,l22,l23]
# [l31,l32,l33]]
# array([[10, 20, 30],
# [40, 50, 60],
# [70, 80, 90]])
tau = -10 * np.arange(1, (n-1)**2+1).reshape(n-1, n-1)
# array([[-10, -20, -30],
# [-40, -50, -60],
# [-70, -80, -90]])
arr[:, range(1, n), range(1, n)] = lmbda.T
arr[:, range(1, n), 0] = tau.T # arr[:, 1:, 0] = tau.T # alternative
# array([[[ 1, 1, 1, 1],
# [-10, 10, 1, 1],
# [-40, 1, 40, 1],
# [-70, 1, 1, 70]],
# [[ 1, 1, 1, 1],
# [-20, 20, 1, 1],
# [-50, 1, 50, 1],
# [-80, 1, 1, 80]],
# [[ 1, 1, 1, 1],
# [-30, 30, 1, 1],
# [-60, 1, 60, 1],
# [-90, 1, 1, 90]]])

awk to update file if value within range

I have a file2 with ~1400 $5 values before the - that are "unknown". What I am trying to do is use the text in $2 of file2 to update those "unknown" values in file1. In $1 of file1 there are a set of numbers that can be used to update the "unknown" if it in the range of $4 of file2. I am really not sure where to start but maybe the awk below is a start or there is probably a better way. Thank you :).
file1
`$1` `$2`
chr6:3224495-3227968 TUBB2B
chr16:89988417-90002505 TUBB3
file2
chr16 89985657 89986630 chr16:89985657-89986630 MC1R-2270|gc=63.5
chr16 89989779 89989898 chr16:89989779-89989898 unknown-2271|gc=73.9
chr16 89998969 89999097 chr16:89998969-89999097 unknown-2272|gc=57
chr16 89999866 89999996 chr16:89999866-89999996 unknown-2273|gc=55.4
chr16 90001127 90002222 chr16:90001127-90002222 unknown-2274|gc=63.9
chr17 1173848 1174575 chr17:1173848-1174575 BHLHA9-3|gc=78.7
desired output (unknown updated to TUBB3 because the TUBB3 because the $4 value is within the range of $1).
chr16 89985657 89986630 chr16:89985657-89986630 MC1R-2270|gc=63.5
chr16 89989779 89989898 chr16:89989779-89989898 TUBB3-2271|gc=73.9
chr16 89998969 89999097 chr16:89998969-89999097 TUBB3-2272|gc=57
chr16 89999866 89999996 chr16:89999866-89999996 TUBB3-2273|gc=55.4
chr16 90001127 90002222 chr16:90001127-90002222 TUBB3-2274|gc=63.9
chr17 1173848 1174575 chr17:1173848-1174575 BHLHA9-3|gc=78.7
awk
awk '
NR == FNR {min[$1]=$4; next}
{
for (id in min)
if ([id] = $5 && [id]) {
print $0, id
break
}
}
' file1 file2
edit:
awk -v OFS='\t' 'NR==FNR{split($1,a,/[:-]/)
rstart[a[1]]=a[2]
rend[a[1]]=a[3]
value[a[1]]=$2
next}
$5~/unknown/ && $2>=rstart[$1] && $3<=rend[$1]
{sub(/unknown/,value[$1],$5)}1' file1 file2 |
column -t > output
chr16 89985657 89986630 chr16:89985657-89986630 MC1R-2270|gc=63.5
chr16 89989779 89989898 chr16:89989779-89989898 unknown-2271|gc=73.9
chr16 89989779 89989898 chr16:89989779-89989898 TUBB3-2271|gc=73.9
chr16 89998969 89999097 chr16:89998969-89999097 unknown-2272|gc=57
chr16 89998969 89999097 chr16:89998969-89999097 TUBB3-2272|gc=57
chr16 89999866 89999996 chr16:89999866-89999996 unknown-2273|gc=55.4
chr16 89999866 89999996 chr16:89999866-89999996 TUBB3-2273|gc=55.4
chr16 90001127 90002222 chr16:90001127-90002222 unknown-2274|gc=63.9
chr16 90001127 90002222 chr16:90001127-90002222 TUBB3-2274|gc=63.9
chr17 1173848 1174575 chr17:1173848-1174575 BHLHA9-3|gc=78.7
awk to the rescue!
$ awk -v OFS='\t' 'NR==FNR{split($1,a,/[:-]/)
rstart[a[1]]=a[2]
rend[a[1]]=a[3]
value[a[1]]=$2
next}
$5~/unknown/ && $2>=rstart[$1] && $3<=rend[$1]
{sub(/unknown/,value[$1],$5)}1' file1 file2 |
column -t
chr16 89985657 89986630 chr16:89985657-89986630 MC1R-2270|gc=63.5
chr16 89989779 89989898 chr16:89989779-89989898 TUBB3-2271|gc=73.9
chr16 89998969 89999097 chr16:89998969-89999097 TUBB3-2272|gc=57
chr16 89999866 89999996 chr16:89999866-89999996 TUBB3-2273|gc=55.4
chr16 90001127 90002222 chr16:90001127-90002222 TUBB3-2274|gc=63.9
chr17 1173848 1174575 chr17:1173848-1174575 BHLHA9-3|gc=78.7
modifies the original spacing so piped to column -t for tabular format.

How to load a vector from memory with up-sample in Neon with C API

i'm new about Neon. I try find some instructions to do following operation:
int a[8] = {1,2,3,4,5,6,7,8};
int b[4] = {1,2,3,4};
int c[8] = {0};
for (int =0; i<8; i++)
c[i] = a[i] - b[i/2];
How can i Do that with arm neon, actually how can I load the array with upsample to Neon like {b[0],b[0],b[1],b[1],b[2],b[2],b[3],b[3]}
you can do this by extending b[] vector:
vld1.32 {q10, q11}, [ptrB]!
vld1.32 {q12, q13}, [ptrA]!
vld1.32 {q14, q15}, [ptrA]!
vshll.s32 q8, d20, #32
vshll.s32 q9, d21, #32
vshll.s32 q10, d22, #32
vshll.s32 q11, d23, #32
vsra.u64 q8, q8, #32
vsra.u64 q9, q9, #32
vsra.u64 q10, q10, #32
vsra.u64 q11, q11, #32
vsub.s32 q12, q12, q8
vsub.s32 q13, q13, q9
vsub.s32 q14, q14, q10
vsub.s32 q15, q15, q11
vst1.32 {q12, q13}, [ptrC]!
vst1.32 {q14, q15}, [ptrC]!
However, it's so much efficient when done with vld2 and vst2 when loading/storing a[] vector:
vld1.32 {q10, q11}, [ptrB]!
vld2.32 {q12, q13}, [ptrA]!
vld2.32 {q14, q15}, [ptrA]!
vsub.s32 q12, q12, q10
vsub.s32 q13, q13, q10
vsub.s32 q14, q14, q11
vsub.s32 q15, q15, q11
vst2.32 {q12, q13}, [ptrC]!
vst2.32 {q14, q15}, [ptrC]!

Rails ActiveRecord sum of users voted?

The result I want is simply the number of users voted for rateable_id = '3'?
Example: As you can see in my table rates, rater_id: 1 and rater_id: 8 have voted for rateable_id = 3. This makes 2 users.
My question is how to display that in view?
This is in my ranking_controller.rb:
class RankingController < ApplicationController
def index
#rankings = Rate.find(:all)
end
end
This is in my table rates:
- !ruby/object:Rate
attributes:
id: 11
rater_id: 1
rateable_id: 3
rateable_type: Bboy
stars: 5.0
dimension: foundation
created_at: 2014-02-25 09:33:23.000000000 Z
updated_at: 2014-02-25 09:33:23.000000000 Z
- !ruby/object:Rate
attributes:
id: 12
rater_id: 1
rateable_id: 3
rateable_type: Bboy
stars: 5.0
dimension: originality
created_at: 2014-02-25 09:33:24.000000000 Z
updated_at: 2014-02-25 09:33:24.000000000 Z
- !ruby/object:Rate
attributes:
id: 13
rater_id: 1
rateable_id: 3
rateable_type: Bboy
stars: 5.0
dimension: dynamics
created_at: 2014-02-25 09:33:25.000000000 Z
updated_at: 2014-02-25 09:33:25.000000000 Z
- !ruby/object:Rate
attributes:
id: 14
rater_id: 1
rateable_id: 3
rateable_type: Bboy
stars: 5.0
dimension: execution
created_at: 2014-02-25 09:33:26.000000000 Z
updated_at: 2014-02-25 09:33:26.000000000 Z
- !ruby/object:Rate
attributes:
id: 15
rater_id: 1
rateable_id: 3
rateable_type: Bboy
stars: 5.0
dimension: battle
created_at: 2014-02-25 09:33:27.000000000 Z
updated_at: 2014-02-25 09:33:27.000000000 Z
- !ruby/object:Rate
attributes:
id: 16
rater_id: 1
rateable_id: 5
rateable_type: Bboy
stars: 5.0
dimension: foundation
created_at: 2014-02-25 09:36:30.000000000 Z
updated_at: 2014-02-25 09:36:30.000000000 Z
- !ruby/object:Rate
attributes:
id: 17
rater_id: 1
rateable_id: 5
rateable_type: Bboy
stars: 5.0
dimension: originality
created_at: 2014-02-25 09:36:31.000000000 Z
updated_at: 2014-02-25 09:36:31.000000000 Z
- !ruby/object:Rate
attributes:
id: 18
rater_id: 1
rateable_id: 5
rateable_type: Bboy
stars: 5.0
dimension: dynamics
created_at: 2014-02-25 09:36:31.000000000 Z
updated_at: 2014-02-25 09:36:31.000000000 Z
- !ruby/object:Rate
attributes:
id: 19
rater_id: 1
rateable_id: 5
rateable_type: Bboy
stars: 5.0
dimension: battle
created_at: 2014-02-25 09:36:32.000000000 Z
updated_at: 2014-02-25 09:36:32.000000000 Z
- !ruby/object:Rate
attributes:
id: 25
rater_id: 8
rateable_id: 3
rateable_type: Bboy
stars: 1.0
dimension: foundation
created_at: 2014-03-04 14:06:46.000000000 Z
updated_at: 2014-03-04 14:06:46.000000000 Z
- !ruby/object:Rate
attributes:
id: 26
rater_id: 8
rateable_id: 3
rateable_type: Bboy
stars: 1.0
dimension: originality
created_at: 2014-03-04 14:06:49.000000000 Z
updated_at: 2014-03-04 14:06:49.000000000 Z
- !ruby/object:Rate
attributes:
id: 27
rater_id: 8
rateable_id: 3
rateable_type: Bboy
stars: 1.0
dimension: dynamics
created_at: 2014-03-04 14:06:51.000000000 Z
updated_at: 2014-03-04 14:06:51.000000000 Z
- !ruby/object:Rate
attributes:
id: 28
rater_id: 8
rateable_id: 3
rateable_type: Bboy
stars: 1.0
dimension: execution
created_at: 2014-03-04 14:06:53.000000000 Z
updated_at: 2014-03-04 14:06:53.000000000 Z
- !ruby/object:Rate
attributes:
id: 29
rater_id: 8
rateable_id: 3
rateable_type: Bboy
stars: 1.0
dimension: battle
created_at: 2014-03-04 14:06:54.000000000 Z
updated_at: 2014-03-04 14:06:54.000000000 Z
You could use it as below:
#raters_count = Rate.select(:rater_id).where(rateable_id: 3, rateable_type: 'Bboy' ).distinct.count
There are many ways to accomplish this.
One would be
#ranking_count = Rate.where(rateable_id: 3).pluck(:rater_id).uniq.count
Or this
#ratings = Rate.group("dimension, rateable_id").select("rateable_id, dimension, count(rater_id) as rate_count")
#=> SELECT rateable_id, dimension,count(rater_id) as rate_count FROM rates GROUP BY dimension, rateable_id
Then
#ratings.each do |rating|
rating.dimension
rating.rateable_id
rating.rate_count
end
Obviously modifiable to fit your needs but something like this should suffice. Also more flexible than your original question since your question differs from you code. Your question only wants to handle 1 rateable_id but your code loads all Rate so I answered based on retrieving all Rate objects with a method for rate_count based on dimension.
A more expansive method might be
#ratings = Rate.group("dimension, rateable_id, rateable_type").select("rateable_id, dimension,rateable_type, count(rater_id) as rate_count, avg(stars) as stars")
#=> SELECT rateable_id, dimension,rateable_type,count(rater_id) as rate_count, avg(stars) as stars FROM rates GROUP BY dimension, rateable_id,rateable_type
Then
#ratings.each do |rating|
rating.dimension
rating.rateable_id
rating.rateable_type
rating.rate_count
rating.stars
end
This will give you access to the number of ratings and the average number of stars based on a rates grouped by dimension, rateable_id and rateable_type
This should return something along these lines (psuedo) based on your output above
[<Rate dimension:"foundation",rateable_id:3,rateable_type:"Bboy",rate_count:2, stars:3>,
<Rate dimension:"originality",rateable_id:3,rateable_type:"Bboy",rate_count:2, stars:3>,
<Rate dimension:"dynamics",rateable_id:3,rateable_type:"Bboy",rate_count:2, stars:3>,
<Rate dimension:"execution",rateable_id:3,rateable_type:"Bboy",rate_count:2, stars:3>,
<Rate dimension:"battle",rateable_id:3,rateable_type:"Bboy",rate_count:2, stars:3>,
<Rate dimension:"foundation",rateable_id:5,rateable_type:"Bboy",rate_count:1, stars:5>,
<Rate dimension:"originality",rateable_id:5,rateable_type:"Bboy",rate_count:1, stars:5>,
<Rate dimension:"dynamics",rateable_id:5,rateable_type:"Bboy",rate_count:1, stars:5>,
<Rate dimension:"battle",rateable_id:5,rateable_type:"Bboy",rate_count:1, stars:5>]