Connected through VNC the keyboard language changes inside a virtualBox machine - keyboard

Hi all I'm having this problem and I cannot find a solution.
The problem:
When I connect to my server using VNC and after that I started a virtual machine from VirtualBox the keyboard of the virtual machine is changed and I cannot change it. If I type in the host I still have my original keyboard settings.
Trials:
I've checked this old thread and when I execute the next command:
LOG_KB_SECONDARY=1 VirtualBox -startvm <your VM name>
I get the following:
Attempting to match against "U.S. English"
Matches=47, seq=33
Attempting to match against "U.S. English, International (with dead keys)"
Matches=44, seq=31
...
Excluded more attempts
...
Detected layout is "U.S. English", matches=47, seq=33
Warning - keycode 17, keysym "0)" (0x30 0x29) was matched to scancode 11
Warning - keycode 18, keysym "1!" (0x31 0x21) was matched to scancode 2
Warning - keycode 19, keysym "2#" (0x32 0x40) was matched to scancode 3
Warning - keycode 20, keysym "3#" (0x33 0x23) was matched to scancode 4
Warning - keycode 21, keysym "4$" (0x34 0x24) was matched to scancode 5
Warning - keycode 22, keysym "5%" (0x35 0x25) was matched to scancode 6
Warning - keycode 23, keysym "6^" (0x36 0x5e) was matched to scancode 7
Warning - keycode 24, keysym "7&" (0x37 0x26) was matched to scancode 8
Warning - keycode 25, keysym "8*" (0x38 0x2a) was matched to scancode 9
Warning - keycode 26, keysym "9(" (0x39 0x28) was matched to scancode 10
Warning - keycode 27, keysym "-_" (0x2d 0x5f) was matched to scancode 12
Warning - keycode 28, keysym "=+" (0x3d 0x2b) was matched to scancode 13
Warning - keycode 29, keysym "[{" (0x5b 0x7b) was matched to scancode 26
Warning - keycode 30, keysym "]}" (0x5d 0x7d) was matched to scancode 27
Warning - keycode 31, keysym ";:" (0x3b 0x3a) was matched to scancode 39
Warning - keycode 32, keysym "'"" (0x27 0x22) was matched to scancode 40
Warning - keycode 33, keysym "`~" (0x60 0x7e) was matched to scancode 41
Warning - keycode 34, keysym ",<" (0x2c 0x3c) was matched to scancode 51
Warning - keycode 35, keysym ".>" (0x2e 0x3e) was matched to scancode 52
Warning - keycode 36, keysym "/?" (0x2f 0x3f) was matched to scancode 53
Warning - keycode 37, keysym "\|" (0x5c 0x7c) was matched to scancode 43
Warning - keycode 39, keysym "bB" (0x62 0x42) was matched to scancode 48
Warning - keycode 40, keysym "cC" (0x63 0x43) was matched to scancode 46
Warning - keycode 41, keysym "dD" (0x64 0x44) was matched to scancode 32
Warning - keycode 42, keysym "eE" (0x65 0x45) was matched to scancode 18
Warning - keycode 43, keysym "fF" (0x66 0x46) was matched to scancode 33
Warning - keycode 44, keysym "gG" (0x67 0x47) was matched to scancode 34
Warning - keycode 45, keysym "hH" (0x68 0x48) was matched to scancode 35
Warning - keycode 46, keysym "iI" (0x69 0x49) was matched to scancode 23
Warning - keycode 47, keysym "jJ" (0x6a 0x4a) was matched to scancode 36
Warning - keycode 48, keysym "kK" (0x6b 0x4b) was matched to scancode 37
Warning - keycode 49, keysym "lL" (0x6c 0x4c) was matched to scancode 38
Warning - keycode 50, keysym "mM" (0x6d 0x4d) was matched to scancode 50
Warning - keycode 51, keysym "nN" (0x6e 0x4e) was matched to scancode 49
Warning - keycode 52, keysym "oO" (0x6f 0x4f) was matched to scancode 24
Warning - keycode 53, keysym "pP" (0x70 0x50) was matched to scancode 25
Warning - keycode 54, keysym "qQ" (0x71 0x51) was matched to scancode 16
Warning - keycode 55, keysym "rR" (0x72 0x52) was matched to scancode 19
Warning - keycode 56, keysym "sS" (0x73 0x53) was matched to scancode 31
Warning - keycode 57, keysym "tT" (0x74 0x54) was matched to scancode 20
Warning - keycode 58, keysym "uU" (0x75 0x55) was matched to scancode 22
Warning - keycode 59, keysym "vV" (0x76 0x56) was matched to scancode 47
Warning - keycode 60, keysym "wW" (0x77 0x57) was matched to scancode 17
Warning - keycode 61, keysym "xX" (0x78 0x58) was matched to scancode 45
Warning - keycode 62, keysym "yY" (0x79 0x59) was matched to scancode 21
Warning - keycode 63, keysym "zZ" (0x7a 0x5a) was matched to scancode 44
Finished mapping keyboard, matches=47, entries=47 (excluding 102nd key)
I guess VirtualBox cannot detect the proper keyboard setting. When I execute the very same command in the server (without using VNC) I get a completely different output and the keyboard is correctly detected.
Interesting data:
Host: Ubuntu 14.04
Guest: Several ones (Lubuntu, Ubuntu 14.04, among others)
VirtualBox version: 5.0.8

Related

How do I know all valid positions for a King to move on chess board without going to the opposite side

So I have a chess board represented as an array of size 64 with top-left square being 0 and bottom-right square being 63. I have this function which gives all possible moves of King.
current_pos = i
arr = np.array([i-9, i-8, i-7, i-1, i+1, i+7, i+8, 1+9])
return arr
.
.
.
if selected position is in arr:
move king
Where i is the number of the square on which king currently is.
This works if the king is not on edges of the chessboard.
BUT if king is on the bottom-right square, that is number 63, the function gives bottom-left square that is number 56 as a valid position for a king to move.
Is there any efficient way to know that the king is going to the other edge and is not a valid move?
I'm having same problems with almost all my pieces where the function will allow piece to go on the other side of board but i figured king's movement was the simplest to ask.
A 1D list is way faster than a 2D 8x8 list so I like that you are using this approach.
The way this is handled is to use a 10x12 board where you have an extra 2 rows on bottom and top, and an extra column on the left and right:
Then in your generate move function you simple check if the square you are looking at is within the board. If it is not, you skip to the next square in your loop.
Please read more about it on https://www.chessprogramming.org/10x12_Board. It is also a great site for information about chess programming in general.
Here is one approach using table lookup.
Code
piece_offsets = {
'n': [-17, -15, -10, -6, 6, 10, 15, 17],
'b': [ -9, -7, 9, 7],
'r': [ -8, -1, 8, 1],
'q': [ -9, -8, -7, -1, 9, 8, 7, 1],
'k': [ -9, -8, -7, -1, 9, 8, 7, 1]
}
sqdist = [[0 for x in range(64)] for y in range(64)]
pseudo_legal = {
'n': [[] for y in range(64)],
'b': [[] for y in range(64)],
'r': [[] for y in range(64)],
'q': [[] for y in range(64)],
'k': [[] for y in range(64)],
}
def distance(sq1, sq2):
file1 = sq1 & 7
file2 = sq2 & 7
rank1 = sq1 >> 3
rank2 = sq2 >> 3
rank_distance = abs(rank2 - rank1)
file_distance = abs(file2 - file1)
return max(rank_distance, file_distance)
def print_board():
for i in range(64):
print(f'{i:02d} ', end='')
if (i+1)%8 == 0:
print()
def on_board(s):
return s >= 0 and s < 64
def init_board():
for sq1 in range(64):
for sq2 in range(64):
sqdist[sq1][sq2] = distance(sq1, sq2)
for pt in ['n', 'b', 'r', 'q', 'k']:
for s in range(64):
for offset in piece_offsets[pt]:
to = s + offset
if pt in ['k', 'n']:
if on_board(to) and sqdist[s][to] < 4:
pseudo_legal[pt][s].append(to)
else: # sliders
s1 = s
while True:
to1 = s1 + offset
if on_board(to1) and sqdist[s1][to1] < 4:
pseudo_legal[pt][s].append(to1)
s1 = to1
else:
break
def main():
init_board() # build sqdist and pseudo_legal_to tables
print_board()
print()
for pt in ['n', 'b', 'r', 'q', 'k']:
for s in [0, 63, 36]:
print(f'pt: {pt}, from: {s}: to: {pseudo_legal[pt][s]}')
print()
# pseudo_legal_sq = pseudo_legal['b'][61]
# print(pseudo_legal_sq)
main()
Output
00 01 02 03 04 05 06 07
08 09 10 11 12 13 14 15
16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31
32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47
48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63
pt: n, from: 0: to: [10, 17]
pt: n, from: 63: to: [46, 53]
pt: n, from: 36: to: [19, 21, 26, 30, 42, 46, 51, 53]
pt: b, from: 0: to: [9, 18, 27, 36, 45, 54, 63]
pt: b, from: 63: to: [54, 45, 36, 27, 18, 9, 0]
pt: b, from: 36: to: [27, 18, 9, 0, 29, 22, 15, 45, 54, 63, 43, 50, 57]
pt: r, from: 0: to: [8, 16, 24, 32, 40, 48, 56, 1, 2, 3, 4, 5, 6, 7]
pt: r, from: 63: to: [55, 47, 39, 31, 23, 15, 7, 62, 61, 60, 59, 58, 57, 56]
pt: r, from: 36: to: [28, 20, 12, 4, 35, 34, 33, 32, 44, 52, 60, 37, 38, 39]
pt: q, from: 0: to: [9, 18, 27, 36, 45, 54, 63, 8, 16, 24, 32, 40, 48, 56, 1, 2, 3, 4, 5, 6, 7]
pt: q, from: 63: to: [54, 45, 36, 27, 18, 9, 0, 55, 47, 39, 31, 23, 15, 7, 62, 61, 60, 59, 58, 57, 56]
pt: q, from: 36: to: [27, 18, 9, 0, 28, 20, 12, 4, 29, 22, 15, 35, 34, 33, 32, 45, 54, 63, 44, 52, 60, 43, 50, 57, 37, 38, 39]
pt: k, from: 0: to: [9, 8, 1]
pt: k, from: 63: to: [54, 55, 62]
pt: k, from: 36: to: [27, 28, 29, 35, 45, 44, 43, 37]

How do I store an ArrayBuffer in MongoDB?

I'm trying to build an Electron React App that captures short videos of the screen but am unable to store videos (as part of a larger "Payload" object:
{video_buffer: xxx, time_stamp: 3456345 ...}
The videos are created in the renderer process via MediaStream and MediaRecorder API's then converted to Blob. Here is some sample code:-
let mediaRecorder = new MediaRecorder(videoStream);
mediaRecorder.start()
let chunks = []
mediaRecorder.ondataavailable = (event) => {chunks.push(event.data)}
mediaRecorder.onstop = async (event) => {
let blob = new Blob(chunks, {type: 'video/mp4'})
chunks = []
const buffer = await blob.arrayBuffer()
The buffer works when I convert to a URL and set it to the Video element src
let videoURL = URL.createObjectURL(blob)
The videos are short and occupy about 2.5MB max.
I can only send the buffer (or the URL) via IPC (not the Blob).
In the main process, I'm using Mongoose with the schema:
new payloadSchema = {video_buffer: {type: Buffer}}
but this doesn't work, presumably because buffer is an ArrayBuffer and not a Data View or TypedArray.
So I tried converting it to a Uint8Array TypedArray object:
const new_buffer = new Uint8Array(buffer)
but i get this error on saving:
video_buffer: CastError: Cast to Buffer failed for value "Uint8Array(2041510) [
[electron] 26, 69, 223, 163, 159, 66, 134, 129, 1, 66, 247, 129,
[electron] 1, 66, 242, 129, 4, 66, 243, 129, 8, 66, 130, 132,
[electron] 119, 101, 98, 109, 66, 135, 129, 4, 66, 133, 129, 2,
[electron] 24, 83, 128, 103, 1, 255, 255, 255, 255, 255, 255, 255,
[electron] 21, 73, 169, 102, 153, 42, 215, 177, 131, 15, 66, 64,
[electron] 77, 128, 134, 67, 104, 114, 111, 109, 101, 87, 65, 134,
[electron] 67, 104, 114, 111, 109, 101, 22, 84, 174, 107, 171, 174,
[electron] 169, 215, 129, 1, 115, 197, 135, 155, 112, 30, 237, 62,
[electron] 162, 245, 131, 129,
[electron] ... 2041410 more items
[electron] ]" at path "video_buffer"
I then tried to convert the Uint8Array into a hex encoded string then storing that as a buffer .
On querying MongoDB in Terminal it has stored the string:
const buff_to_hex_string = new_buffer.toString('hex')
Then save it via Mongoose as before : (Schema {type: Buffer})
This seemed to work with following output from MongoDB:
The output of the saved Payload Schema is:
video_buffer: Binary {
[electron] _bsontype: 'Binary',
[electron] sub_type: 0,
[electron] position: 9514868,
[electron] buffer: <Buffer 32 36 2c 36 39 2c 32 32 33 2c 31 36 33 2c 31 35 39 2c 36 36 2c 31 33 34 2c 31 32 39 2c 31 2c 36 36 2c 32 34 37 2c 31 32 39 2c 31 2c 36 36 2c 32 34 32 ... 9514818 more bytes>
Question: On retrieving the stored buffer object, what is the easiest way to convert it back into an ArrayBuffer so that I can play it in a video element ?
Do I need to convert backwards --> hex string --> Uint8Array --> ArrayBuffer ---> Blob ---> URL ?
I've tried lots of methods provided but none work.
Any help would be much appreciated.
Thanks.

Arranging a list to ouput equidistant points

I want to write a code that prints the first and last number within a list as well as 5 other points. The points have to be equidistant from each other as well. So the numbers outputted would be 25, 19, 29, 16, 20.
list_ = [25, 23, 14, 22, 19, 13, 12, 10, 28, 29, 11, 15, 18, 27, 16, 21, 20, 17, 24, 26]
Is this something you are looking for?
>>> size = len(lst)
>>> size // 5 # five elements starting with first one.
4
>>>
>>> for i in range(0, size, size//5):
print(lst[i])
25
19
28
18
20

numpy array saving to csv

I'm trying to save numpy array to csv file but there is a problem,
I use two different solution but they did not work
my numpy array looks like,
In[39]: arr[0]
Out[39]:
array([ array([[ 30, 29, 198, ..., 149, 149, 149],
[ 29, 29, 197, ..., 149, 149, 149],
[ 29, 29, 197, ..., 149, 149, 149],
...,
[ 63, 63, 96, ..., 105, 104, 104],
[ 63, 63, 96, ..., 106, 105, 105],
[ 77, 77, 217, ..., 217, 217, 217]], dtype=uint8),
list([0, 0, 0, 0, 0, 0, 0, 0, 0])], dtype=object)
Its shape is (1200, 2) numpy array and I want to save it to csv file,
with np.savetxt function
In[40]: np.savetxt("numpy_array.csv", arr, delimiter=',')
Traceback (most recent call last):
File "D:\Program files\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 1254, in savetxt
fh.write(asbytes(format % tuple(row) + newline))
TypeError: only length-1 arrays can be converted to Python scalars
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Program files\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-41-673bcc1d77a6>", line 1, in <module>
np.savetxt("numpy_array.csv", arr, delimiter=',')
File "D:\Program files\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 1258, in savetxt
% (str(X.dtype), format))
TypeError: Mismatch between array dtype ('object') and format specifier ('%.18e,%.18e')
with pandas
In[42]: df = pd.DataFrame(arr)
In[43]: df[:5]
Out[43]:
0 \
0 [[30, 29, 198, 198, 197, 197, 197, 197, 197, 1...
1 [[29, 29, 197, 197, 196, 196, 197, 197, 197, 1...
2 [[29, 29, 196, 196, 196, 196, 196, 196, 196, 1...
3 [[29, 29, 196, 196, 196, 196, 196, 196, 196, 1...
4 [[29, 29, 196, 196, 196, 196, 196, 196, 197, 1...
1
0 [0, 0, 0, 0, 0, 0, 0, 0, 0]
1 [1, 0, 0, 0, 0, 0, 0, 0, 0]
2 [1, 0, 0, 0, 0, 0, 0, 0, 0]
3 [1, 0, 0, 0, 0, 0, 0, 0, 0]
4 [1, 0, 0, 0, 0, 0, 0, 0, 0]
In[44]: df.to_csv("h.csv", index=False)
In[45]: a = pd.read_csv("h.csv", header=None,names =['input', 'output'])
In[46]: a[:5]
Out[46]:
input \
0 0
1 [[ 30 29 198 ..., 149 149 149]\r\n [ 29 29 1...
2 [[ 29 29 197 ..., 149 149 149]\r\n [ 29 29 1...
3 [[ 29 29 196 ..., 149 149 149]\r\n [ 29 29 1...
4 [[ 29 29 196 ..., 149 149 149]\r\n [ 29 29 1...
output
0 1
1 [0, 0, 0, 0, 0, 0, 0, 0, 0]
2 [1, 0, 0, 0, 0, 0, 0, 0, 0]
3 [1, 0, 0, 0, 0, 0, 0, 0, 0]
4 [1, 0, 0, 0, 0, 0, 0, 0, 0]
when I print "df[:5]", everything looks great, but after I saved it to csv then read it from csv, it looks awful, there are not commas between numbers and there are '\r\n' between list.
I want to see like "df[:5]" 's output after read csv file, how can I do it, what is the problem?
Your array is 2d, (1200, 2) with object dtype. Evidently the first column contains 2d arrays, and the 2nd column lists.
arr[0,0] is a 2d array
array([[ 30, 29, 198, ..., 149, 149, 149],
[ 29, 29, 197, ..., 149, 149, 149],
[ 29, 29, 197, ..., 149, 149, 149],
...,
[ 63, 63, 96, ..., 105, 104, 104],
[ 63, 63, 96, ..., 106, 105, 105],
[ 77, 77, 217, ..., 217, 217, 217]], dtype=uint8)
You could easily write in a csv format. For example:
In [342]: arr = np.array([[ 30, 29, 198, 149, 149, 149],
...: [ 29, 29, 197, 149, 149, 149],
...: [ 29, 29, 197, 149, 149, 149],
...: [ 63, 63, 96, 105, 104, 104],
...: [ 63, 63, 96, 106, 105, 105],
...: [ 77, 77, 217, 217, 217, 217]], dtype=np.uint8)
...:
...:
In [343]: np.savetxt('arr.txt', arr, delimiter=',', fmt='%4d')
produces a file that looks like:
In [344]: cat arr.txt
30, 29, 198, 149, 149, 149
29, 29, 197, 149, 149, 149
29, 29, 197, 149, 149, 149
63, 63, 96, 105, 104, 104
63, 63, 96, 106, 105, 105
77, 77, 217, 217, 217, 217
Read savetxt for more details on fmt.
But the full array is not compatible with the simple 2d layout of a csv file. Sure you could write something more complicated, but you couldn't load it with a csv reader like np.genfromtxt or np.loadtxt. Those expect the neat row and column layout with a well defined delimiter.
In [346]: data = np.genfromtxt('arr.txt',delimiter=',',dtype=None)
In [347]: data
Out[347]:
array([[ 30, 29, 198, 149, 149, 149],
[ 29, 29, 197, 149, 149, 149],
[ 29, 29, 197, 149, 149, 149],
[ 63, 63, 96, 105, 104, 104],
[ 63, 63, 96, 106, 105, 105],
[ 77, 77, 217, 217, 217, 217]])
The pandas df shows two columns, one with the arrays, the other with the lists. But in a column 0 appears to contain string representations of the 2d arrays, as indicated by the newline characters. Did you look at the h.csv file? Part of the reason for using csv is so people can read it, and other programs (like excel) can read it.
Make an array like your big one
In [349]: barr = np.empty((3,2), object)
In [350]: barr[:,0]=[arr,arr,arr]
In [351]: barr[:,1]=[[0,0,0] for _ in range(3)]
In [352]: barr
Out[352]:
array([[array([[ 30, 29, 198, 149, 149, 149],
[ 29, 29, 197, 149, 149, 149],
[ 29, 29, 197, 149, 149, 149],
[ 63, 63, 96, 105, 104, 104],
[ 63, 63, 96, 106, 105, 105],
[ 77, 77, 217, 217, 217, 217]], dtype=uint8),
list([0, 0, 0])],
[array([[ 30, 29, 198, 149, 149, 149],
...
[ 77, 77, 217, 217, 217, 217]], dtype=uint8),
list([0, 0, 0])]], dtype=object)
Write it %s format, the only one that will work with objects like this:
In [354]: np.savetxt('barr.txt',barr, delimiter=',',fmt='%s')
In [355]: cat barr.txt
[[ 30 29 198 149 149 149]
[ 29 29 197 149 149 149]
[ 29 29 197 149 149 149]
[ 63 63 96 105 104 104]
[ 63 63 96 106 105 105]
[ 77 77 217 217 217 217]],[0, 0, 0]
[[ 30 29 198 149 149 149]
[ 29 29 197 149 149 149]
[ 29 29 197 149 149 149]
[ 63 63 96 105 104 104]
[ 63 63 96 106 105 105]
[ 77 77 217 217 217 217]],[0, 0, 0]
[[ 30 29 198 149 149 149]
[ 29 29 197 149 149 149]
[ 29 29 197 149 149 149]
[ 63 63 96 105 104 104]
[ 63 63 96 106 105 105]
[ 77 77 217 217 217 217]],[0, 0, 0]
That is not a valid csv file. It is text, but with [] and varying line lengths, none of the standard csv file readers can handle it.
Saving that array as you did with pandas, I get:
In [364]: cat pdbarr.txt
0,1
"[[ 30 29 198 149 149 149]
[ 29 29 197 149 149 149]
[ 29 29 197 149 149 149]
[ 63 63 96 105 104 104]
[ 63 63 96 106 105 105]
[ 77 77 217 217 217 217]]","[0, 0, 0]"
"[[ 30 29 198 149 149 149]
[ 29 29 197 149 149 149]
[ 29 29 197 149 149 149]
[ 63 63 96 105 104 104]
[ 63 63 96 106 105 105]
[ 77 77 217 217 217 217]]","[0, 0, 0]"
"[[ 30 29 198 149 149 149]
[ 29 29 197 149 149 149]
[ 29 29 197 149 149 149]
[ 63 63 96 105 104 104]
[ 63 63 96 106 105 105]
[ 77 77 217 217 217 217]]","[0, 0, 0]"
Notice all the quotes - it's writing those component arrays and lists as strings. Again, not a valid csv.
Numpy itself has no 'save as csv'-function. Normally you save it through another package (like pandas or pickle).
What you see 'it looks awful' is the pandas format. Add arr = np.array(a)
and you have you numpy format again.

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '200'

select * from Employee where salary < All (200,500)
Getting error:
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '200'.

Resources