Use common VirtualBox setup between users

I want to solve the following use case: my wife and me (= two separate linux users) want to use THE SAME VirtualBox Windows10 virtual machine. So my idea is to have all VirtualBox settings under the user “vmuser” and start VirtualBox always in the vmuser environment.

Then in the folder /home/vmuser all the VirtualBox settings are set up.

On every user desktop I added a desktop file “VirtualBox.desktop” with the content:

 [Desktop Entry]  Comment=  Exec=mate-terminal -- /bin/su vmuser -w QT_QPA_PLATFORM_THEME,DISPLAY,XDG_RUNTIME_DIR -c /usr/local/bin/  GenericName=Go virtual  Icon=virtualbox  MimeType=  Name=VirtualBox  Path=  StartupNotify=true  Terminal=true  TerminalOptions=  Type=Application  X-DBUS-ServiceName=  X-DBUS-StartupType=  X-KDE-SubstituteUID=false  X-KDE-Username=` 

Clicking on this icon then launches the file /usr/local/bin/ The “-w” is for not replacing existing environment variables. I use “mate-terminal” because it is starting faster on my machine compared to “gome-terminal” but your mileage may vary.

For some to me yet unknown reason (I think the issue is the /bin/sh at the beginning but it does not work without) I need to define the environment variables this way:


This solution works as expected despite some error messages during the start of VirtualBox in the extra console window:

Qt WARNING: QStandardPaths: wrong ownership on runtime directory /run/user/1000, 1000 instead of 1002 Qt WARNING: Qt: Session management error: None of the authentication protocols specified are supported 

The user runtime directory is under control of the user who clicks the desktop icon (id=1000) and the VirtualBox process starts under the vmuser (user id = 1002). Ok.

But does anybody know how to get rid of this?

Length of the longest common sub sequence bottom up python 3

Could I get some feedback on this code, I included a test case as well.

To my understanding it runs in O(m*v) where m is length str1 and v len str2.

def lcs(word1, word2):    x = len(word1)   y = len(word2)   return _lcs(word1, word2, x, y)  def _lcs(word1, word2, x, y):    matrix = [[-1]*(x) for val in range (0,y)]    for i in range(0, y):     for j in range(0, x):        if word1[j] == word2[i]:         if i-1 < 0 or j-1 < 0:           matrix[i][j] = 1          else:           matrix[i][j] = 1 + matrix[i-1][j-1]        else:         val1 = 0         val2 = 0         if i-1 >= 0:           val1 = matrix[i-1][j]         if j-1 >= 0:           val2 = matrix[i][j-1]         matrix[i][j] = max(val1,val2)    return matrix[y-1][x-1]  a = 'ABC' b = 'ABCD' print(lcs(a,b)) 

Design Pattern to use when you want apply some common functionality to some specific methods?

I am trying to figure out a design pattern to use(if any exists) to a situation where I would be re-doing some functionality across a bunch of classes. Below is a (simplified) overview of the problem I am facing:

I have some Java code to CREATE, UPDATE, DELETE Student objects, Professor object, & Staff objects. And every time such object is either created, deleted, or updated, I want to extract some information about the affected object(such as name, age, id) and notify an external service. So something like:

class StudentDAO {    public Student createStudent(Student studentToCreate) {        jdbcTemplate.update(INSERT_SQL, .....);        //===> extract some info of the student        //let external service know a student was created....    }    public Student deleteStudent(Student studentToDelete) {        jdbcTemplate.update(DELETE_SQL, .....);        //===> extract some info of the student        //let external service know a student was deleted....    }    //same thing for update }  class ProfessortDAO {    public Professor createProfessor(Professor professorToCreate) {        jdbcTemplate.update(INSERT_SQL, .....);        //===> extract some info of the professor        //let external service know a Professor was created....    }    public Student deleteProfessor(Professor professorToDelete) {        jdbcTemplate.update(DELETE_SQL, .....);        //===> extract some info of the professor        //let external service know a professor was deleted....    }    //same thing for update }  //repeat for Staff 

The example is bit contrived but assume that Student, Professor, Staff share no inheritance hierarchy. Is there a way to achieve this functionality without copying and pasting the logic for extracting the info and sending it in all the DAO classes for CREATE, DELETE, UPDATE methods ?

Common Travel Area – No UK Visa

So just something I’ve been wondering…

If someone is granted entry to ROI but has no UK visa, are they allowed to travel to NI due to the CTA? I have a Bolivian friend wanting to travel and he can enter ROI without a visa, just an outward ticket, but he wants to visit NI while there. I know that he could just drive up and most likely no-one would even notice, but my question is would that actually be legal? I don’t understand the CTA at all.

Thanks in advance!

Is code obfuscation common in FOSS?

I am a learner of FOSS licensing, security and privacy. I ask this question because one of the arguments persuading users to use or switch to FOSS is the fact that since the code is open, an expert can review the code for a security issues and hence FOSS is good for security. However, I had this doubt whether code obfuscation is common in FOSS and whether that would be an impediment while reviewing FOSS source code. Has anyone encountered the issue that I mentioned? Also, I’m not sure whether FOSS licensing says anything about it explicitly. Any thoughts?

Find the common ancestor between two nodes of a tree

import unittest from Tree import * from list2BST import *   def traverse_DFS(root, target_node_value, hash_route):     # print('looking at node ' + str(root.value))     if root.value == target_node_value:         # print('found node ' + str(target_node_value))         hash_route[root.value] = 1         return 1     else:         if root.left_child:             left_result = traverse_DFS(root.left_child, target_node_value,                                        hash_route)             if left_result == 1:                 hash_route[root.value] = 1                 return 1         if root.right_child:             right_result = traverse_DFS(root.right_child, target_node_value,                                         hash_route)             if right_result == 1:                 hash_route[root.value] = 1                 return 1   common_ancestor = None   def hash_check_DFS(root, target_node_value, hash_route):     global common_ancestor      if root.value == target_node_value:         if root.value in hash_route:             print('Found a common ancestor ' + str(root.value))             if common_ancestor is None:                 common_ancestor = root.value         return 1     else:         if root.left_child:             left_result = hash_check_DFS(root.left_child, target_node_value,                                          hash_route)             if left_result == 1:                 if root.value in hash_route:                     if common_ancestor is None:                         print('Found a common ancestor ' + str(root.value))                         common_ancestor = root.value                 return 1          if root.right_child:             right_child = hash_check_DFS(root.right_child, target_node_value,                                          hash_route)              if right_child == 1:                 if root.value in hash_route:                     if common_ancestor is None:                         print('Found a common ancestor ' + str(root.value))                         common_ancestor = root.value                 return 1   def find_common_node(Tree, node1, node2):     global common_ancestor      print('Running the common ancestry finder')      # First run DFS v1 with Hash     hash_route= {}      print('This value of node1 is ' + str(node1))     traverse_DFS(Tree.root, node1, hash_route)      print(hash_route)      common_ancestor = None     hash_check_DFS(Tree.root, node2, hash_route)     if common_ancestor:         return common_ancestor     else:         return None   class Test(unittest.TestCase):      def test_basic_odd_case(self):         array = [1, 4, 5, 8, 11, 15, 18]         result_tree = BinaryTree(insert_list_BST(0, array))         result_node = find_common_node(result_tree, 1, 18)         self.assertEqual(result_node, 8)      def test_basic_even_case(self):         array = [1, 4, 5, 8, 11, 15, 18, 20]         result_tree = BinaryTree(insert_list_BST(0, array))         result_node = find_common_node(result_tree, 1, 8)         self.assertEqual(result_node, 5)   if __name__ == '__main__':     unittest.main() 

Here is my code in python for a program that will find a common ancestor between two nodes in a particular tree. This is a question from Cracking the Coding Interview that I decided to implement on my own. No one has talked about the solution that I implemented above.

Basically, I do a DFS (depth-first search) of the tree for the first node (Time: O(n) and Space: O(1)) and then I get the recursive callbacks to add the path to a hashmap (Time: O(logn) Space: O(n)). The second time around while using DFS for the second node, once I find it – I check with the hashmap till a collision occurs, indicating the lowest common ancestor.

My Tree class is here, while my list2BST function is here. I am looking for feedback on a couple of things:

  • Performance of code and how it could possibly be improved.
  • My coding style and the readability of said code.

Permutation to maximise strings’ common prefix

Is there a good algorithm for finding a permutation which, applied to all the strings in a set, maximises the weight of those with a common fixed length prefix.

Given a set $ S=\{(s,w)\}$ of pairs of fixed length bit strings and weights and an integer k find a permutation p of {1..k} and bit string v of length k to maximise

$ $ \Sigma \{ w_i | (s_i,w_i)\in S\land s_i[p(1)]=v[1] \land s_i[p(2)]=v[2]\land…s_i[p(k)]=v[k] \} $ $

I can think of an obvious greedy algorithm where we

  1. pick the index i and value v which maximises the weights of the strings with $ s[i]=v$
  2. delete position i from all strings.
  3. Repeat until we’ve chosen k bits.

Is it possible to do better?

The problem I’m trying to solve is a compression one where the bits in the data can be reordered and each compressed item can be either the original or the suffix from the original which is concatenated with a common prefix when decompressed.

I need to find a reordering and prefix which maximises the number of items which can use the second form. If p is the permutation and v the prefix

Compression for s:

sp = permute(p, s). If sp[1..k]=v then      # Does the permuted s have the prefix v     return sp[k+1..n]   # Compressed case else      return sp           # Uncompressed case 

Decompression for s:

if len(s)=k then      su = concat(v,s) # Compressed case, add the prefix. else     su = s  # Uncompressed case output inverse_permutation(p, su) 

How common are creatures capable of doing magical damage in 5e?

I’ve been thinking about homebrewing some things. One of the benefits that I’ve been considering is a resistance to non-magical damage (for example, for a sort of Rage-lite feat), or perhaps immunity (for a sort of door-barring spell). I thought this was a neat idea, because it gives the DM the ability to override it if they need (give important baddies magic weapons), but also gives it a high cost (the party gets to loot a magic weapon if they have to contend with someone who cancels this advantage.)

But, thinking about it, there might be a lot of monsters with magical attacks available. Or maybe attacks from non-humanoid, non-beasts are magical by default or something. If either of those were the case, that benefit doesn’t do anything in most cases. So, How common are magical attacks (including ranged/melee/spell, in terms of quantity of monsters in released sources (Monster manual, Volo’s guide, Mordenkainen’s Tome, etc.)?

A good answer would give a general idea of whether this benefit would apply often enough to be useful in the way I hoped (enemies that are unaffected are generally special) (e.g. “As a DM, I find that nearly all/very few of the monsters I use have a way of doing magical damage”), but the best answer would have actual numbers.

I’d love to have a nice table that just lists out these things (like something that says by CR ranges, here’s how many have no magical attacks, here’s how many whose attacks count as magical, and here’s how many have spells, or whatever categories make the most sense), but I don’t know if there are databases that tabulate information like that (Could a search for “counts as magical for the purposes of overcoming resistance”, or the like, work?). Perhaps a random sampling of a more manageable number of monsters could be considered representative?

Suffix-automaton Largest common substring of multiple strings

Can anyone help with understanding how to solve “Largest common substring of multiple strings” problem with usage of Suffix-automaton?

I’ve found this a really good article about SA . But unfortunately it’s pretty hard to understand how it works for multiple strings without a code snippet.

As I see it should be done in a way:

  1. for each state of string Si find a path which leads to delimiter Di (but each state of string Si has such path)

  2. then include only chars from which there is a path to all delimiters (each char from the first string, but none from the last)

Seems like I’m definitely missing something in the explanation.

Any help is appreciated)

how to find total paths in a graph which have only one vertex common with a given path

Assume i have a undirected graph without cycles G and i am provided with pair of nodes (a,b) .

how can i find the total number of paths in the graph that do not share any edge with the given path and have only one vertex common with the given path.

P.S -here the given is path from a to b

For example : i have following graph : enter image description here

and given value of (a,b) is (4,5) then paths that satisfy above condition are (1,1), (1,3), (2,2), (2,6), (4,4),(5,5) totalling to 6