## Update sales order immediately after inserted

I want to update the sales order right after it is inserted.

I want to reflect the change on the sales order conformation email also which is going to the customer.

So i have prepared the below code and inserted into \Magento\Sales\Model\Order\Email\Sender::checkAndSend

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();$  resource = $objectManager->get('Magento\Framework\App\ResourceConnection');$  connection = $resource->getConnection();$  sqlx = "SELECT * FROM sales_order ORDER BY entity_id DESC LIMIT 1";     $connection->query($  sqlx);     $resultx =$  connection->fetchAll($sqlx); foreach($  resultx as $resulx) {$  entityid  = $resulx['entity_id']; }$  sql = "SELECT * FROM sales_order_item WHERE order_id='$entityid'";$  connection->query($sql);$  results = $connection->fetchAll($  sql);     foreach($results as$  result)     {         $item_id =$  result['item_id'];         $fullopt =$  result['product_options'];         $needle = 'Shoe Size'; if (strpos($  fullopt, $needle) !== false){$  pieces = explode('Shoe Size","value":"', $fullopt);$  sizenum = explode('","option_id', $pieces[1]); if(strpos($  fullopt, '"value":"EU"') !== false) {                 $rsizenum1 =$  sizenum[0]+31;                 $finalque =$  pieces[0].'Shoe Size","value":"'.$rsizenum1.'","option_id'.$  sizenum[1];             }             else if(strpos($fullopt, '"value":"UK"') !== false) {$  rsizenum2 = $sizenum[0]-1;$  finalque = $pieces[0].'Shoe Size","value":"'.$  rsizenum2.'","option_id'.$sizenum[1]; } else{$  finalque = $fullopt; }$  upsql = "UPDATE sales_order_item SET product_options='$finalque' WHERE item_id='$  item_id'";             $connection->query($  upsql);         }     } 

The issue is that this dosent update the sales order emal which is goingout and also every time my order gets updated this is running again.

I only want this to run one time after order is inserted.

Anyone can give me a clue?

## Want to refactor working methods that return id of inserted row of query for country, city, and address tables

These are the 3 methods and I am just wondering what would be the right way to remove all the duplication? I want to use this example to learn how to do it to clean up the rest of my code. Please note that I am not allowed to use any external libraries or frameworks for this project outside of the standard java libraries. Thank you.

private void handleSaveButton() throws SQLException {     countryId = getCountryId();     cityId = getCityId();     addressId = getAddressId(); }  /**  *  * @return @throws SQLException  */ private long getCountryId() throws SQLException {     getConnection();     param = toTitleCase(countryTextField.getText());     System.out.println("country param: " + param);     String query = "insert into country (country) values (?)";     ps = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);     ps.setString(1, param);     try {         ps.executeUpdate();         rs = ps.getGeneratedKeys();         rs.next();         primaryKey = rs.getLong(1);         System.out.println("inserted country id: " + primaryKey);     } catch (SQLIntegrityConstraintViolationException e) {         ps = con.prepareStatement("select countryId from country where country = ?");         ps.setString(1, param);         rs = ps.executeQuery();         rs.next();         primaryKey = (long) rs.getInt(1);         System.out.println("existing country id: " + primaryKey);     } finally {         closeConnection(ps);     }     return primaryKey; }  /**  *  * @return @throws SQLException  */ private long getCityId() throws SQLException {     getConnection();     param = toTitleCase(cityTextField.getText());     System.out.println("city param: " + param);     String query = "insert into city (city, countryId) values (?, ?)";     ps = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);     ps.setString(1, param);     ps.setLong(2, countryId);     try {         ps.executeUpdate();         rs = ps.getGeneratedKeys();         rs.next();         primaryKey = rs.getLong(1);         System.out.println("inserted city id: " + primaryKey);     } catch (SQLIntegrityConstraintViolationException e) {         ps = con.prepareStatement("select cityId from city where city = ?");         ps.setString(1, param);         rs = ps.executeQuery();         rs.next();         primaryKey = (long) rs.getInt(1);         System.out.println("existing city id: " + primaryKey);     } finally {         closeConnection(ps);     }     return primaryKey; }  /**  *  * @return @throws SQLException  */ private long getAddressId() throws SQLException {     getConnection();     param = toTitleCase(addressTextField.getText());     System.out.println("address param: " + param);     String query = "insert into address (address, cityId, postalCode, phone) values (?,?,?,?)";     ps = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);     ps.setString(1, param);     ps.setLong(2, cityId);     ps.setString(3, postalTextField.getText());     ps.setString(4, phoneTextField.getText());     try {         ps.executeUpdate();         rs = ps.getGeneratedKeys();         rs.next();         primaryKey = rs.getLong(1);         System.out.println("inserted address id: " + primaryKey);     } catch (SQLIntegrityConstraintViolationException e) {         ps = con.prepareStatement("select addressId from address where address = ? and cityId = ?");         ps.setString(1, param);         ps.setLong(2, cityId);         rs = ps.executeQuery();         rs.next();         primaryKey = (long) rs.getInt(1);         System.out.println("existing address id: " + primaryKey);     } finally {         closeConnection(ps);     }     return primaryKey; } 

## Min Cut Algorithm using Randomly inserted directions

I had a question about a different randomized min cut algorithm (I don’t think it is as efficient as Karger’s algorithm for larger sizes of min cuts but it is more efficient for smaller ones).

My idea for an algorithm was that given some graph, I would randomly assign directions to its edges (i.e. flip a coin and if tails assign an edge to the vertex and if it’s away, assign an edge from the vertex) (O(n) time). Then run Kosaraju’s algorithm (O(n) time) to find all the strongly connected components. Then, we count the number of edges that are connected to each strongly connected component to find the size of the min cut. We return the smallest number and then run the algorithm more times as we do with randomized algorithms.

The intuition behind this algorithm is that I want to find different partitions of the vertices of the graph and I can do this by finding different strongly connected components if I assign directions to the graph. The only partition I cannot create is that of vertices that do not share an edge. However, there is no need to have two such vertices to be in a partition together because we can just take one or the other and have a smaller min cut.

I need help with analyzing the success rate. In a successful run of this algorithm, all of the vertices in the smaller partition of the min cut form a cycle. If the partition contains $$m$$ vertices and $$j$$ edges. Then I think the probability that it is successful is $$\binom{j}{m}\frac{1}{2^{m-1}}$$, since we choose $$m$$ of the edges to form a cycle and set them to form the cycle, but I am not really sure. If $$k$$ is the size of the min cut, we also need to make sure that the min cut does not point to something else, so that is another $$\frac{1}{2^k}$$ probability. I am not completely sure about this either, because it is very dependent on the structure of the graph and I am not sure if I am analyzing this correctly.

Any help/pointers/guidance would be appreciated. Thank you!

## echo command works when manually executed but not when inserted as bash script

I’m using Ubuntu 19.04 and I have sound crackling over HDMI using AMD RX460 connected to my LG LED TV.

This probably has something to do with AMD GPU driver because I have the exact same problem on Windows 10 pro. On windows I have used AMD Adrenaline GUI to fix the problem by not letting the GPU go into p-State 0 (214 MHz, 0.8v). There I set the p-State 1 as minimum state and modified the frequency and voltage to match the p-State 0 ones. Probably p-State 0 apply some other power saving setting which is why setting the same frequency and voltage for p-state 1 does produce the same crackling in sound.

Now I’m trying to do the same thing on Ubuntu 19.04 but with amdgpu driver. I have created to files hdmi-audio-crack-fix and hdmi-audio-crack-fix.service as follow:

1- Placed hdmi-audio-crack-fix inside /usr/bin with proper permissions.

#!/bin/bash # This simple script disables pstate 0 for amdgpu to fix audio crackling over hdmi. # Then pstate 1 is modified to match pstate 0 voltage and frequency. # Also a little bit of undervolting is introduced. # Copy to /usr/bin/ and then copy .service file to /etc/systemd/system/  # Using Ubuntu echo located inside /bin instead of bash built-in echo amdgpu_echo="/bin/echo"  # Change amdgpu dpm performance level to manual $amdgpu_echo "manual" > /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0/power_dpm_force_performance_level # Disable pstate 0 as this is causing the crackling over hdmi$  amdgpu_echo "1 2 3 4 5 6 7" >  /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0/pp_dpm_sclk $amdgpu_echo "1 2 3 4 5 6 7" > /sys/class/drm/card0/device/pp_dpm_sclk # Now reduce pstate 1 clock to reduce temperature on idle$  amdgpu_echo "s 1 220 800" > /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0/pp_od_clk_voltage  # Undervolting gpu for highest pstates $amdgpu_echo "s 5 1138 992" > /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0/pp_od_clk_voltage$  amdgpu_echo "s 6 1172 1005" > /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0/pp_od_clk_voltage $amdgpu_echo "s 7 1212 1050" > /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0/pp_od_clk_voltage # Now sync new core/voltage table with GPU$  amdgpu_echo 'c' > /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0/pp_od_clk_voltage 

2- Placed hdmi-audio-crack-fix.service inside /etc/systemd/system/ and executed sudo systemctl enable hdmi-audio-crack-fix.service.

[Unit] Description=Temporarly fix for amdgpu HDMI audio crackling  [Service] Type=oneshot ExecStart=/usr/bin/hdmi-audio-crack-fix  [Install] WantedBy=multi-user.target 

Everything works as expected but the following line doesn’t seem to have any effects and the GPU still goes to p-State 0:

$amdgpu_echo "1 2 3 4 5 6 7" > /sys/devices/pci0000:64/0000:64:00.0/0000:65:00.0/pp_dpm_sclk  or $  amdgpu_echo "1 2 3 4 5 6 7" >  /sys/class/drm/card0/device/pp_dpm_sclk 

The problem is when I execute this command manually through terminal using the following command it works properly:

sudo su - echo "1 2 3 4 5 6 7" >  /sys/class/drm/card0/device/pp_dpm_sclk 

## cdc-acm driver cannot be inserted

i ve been trying to configure the proxmark3 easy for my linux box. as i insert the the pm3 in the usb port it is supposed to show a “CDC-ACM” when i type the dmesg command..this does not happen ..so i installed a cdc acm module from git hub but when i try to run the install.sh it says “unable to insert the module” i think this is because the module is for an older version of kali linux kernel and i am running kali linux 4.19.0 kernel..it would be great if someone could link a resource for the required module.

i tried to use the pm3 for my windows box which also does not detect the proxmark 3 when i insert it…PLZ I REALLY NEED HELP!!!!!!

## How to remove borders around inserted images in Google Docs?

I’m trying to have a background image taking full height and full width of my document (which is set with all four margins equal to zero).

Annoyingly though, Google docs adds very small left and top margins to inserted images, with apparently no way to remove these (how disappointing of Google if there’s no work around, you would expect such arbitrary limitation from Microsoft but not from them).

I cannot find a way to remove these blank spaces, so I can’t have my image reach all edges of my page. Any suggestion?

## Inserted drawings blurry when compared to adjacent text in Google Docs

Creating and inserting a new drawing via the inbuilt Drawing tool (Insert > Drawing > New) in Google Docs results in images of noticeably lower resolution when compared to adjacent text, both within the app and when a document is downloaded as a PDF:

The figure is noticeably ‘blurry’. Is there any procedure or workaround that would allow for the image to be sharper than this?

## How to prevent audacious from scanning newly inserted media?

Whenever I inserted a USB mass storage device, a small black popover window in the bottom right would appear, showing the filesystem label and a mount icon. When clicking it, Audacious would start, scan the medium and create a playlist.

It may be that this is limited to my Lubuntu 18.10 and does not happen in stock Ubuntu. It may also be that this only starts to happen in a Lubuntu session after having started the Nautilus filemanager.

Anyway, how can I stop this behavior? I’d like to see the normal LXQt popup asking what to do, with an option being “open in file manager”.

## How to prevent audacious from scanning newly inserted media?

Whenever I inserted a USB mass storage device, a small black popover window in the bottom right would appear, showing the filesystem label and a mount icon. When clicking it, Audacious would start, scan the medium and create a playlist.

It may be that this is limited to my Lubuntu 18.10 and does not happen in stock Ubuntu. It may also be that this only starts to happen in a Lubuntu session after having started the Nautilus filemanager.

Anyway, how can I stop this behavior? I’d like to see the normal LXQt popup asking what to do, with an option being “open in file manager”.

## Use JSOM to retrieve id of newly inserted item

I am using JSOM and would like to retrieve the id of the newly inserted item. I’ve tried a few things and nothing has worked.

var clientContext = new SP.ClientContext();     var oList = clientContext.get_web().get_lists().getByTitle('Travel Request Memos');      var itemCreateInfo = new SP.ListItemCreationInformation();     var oListItem = oList.addItem(itemCreateInfo);          oListItem.set_item('Title', 'Title field');         oListItem.set_item('From', 'from field');         oListItem.set_item('Subj', 'subject field');         oListItem.set_item('To', 'to field');         oListItem.set_item('Guidance1', guidance1);         oListItem.set_item('Guidance2', guidance2);         oListItem.set_item('Guidance3', guidance3);         oListItem.set_item('Guidance4', guidance4);         oListItem.set_item('Guidance5', guidance5);               oListItem.update();      clientContext.load(oListItem);     clientContext.executeQueryAsync(     Function.createDelegate(this, this.onAddSucceeded),     Function.createDelegate(this, this.onAddFailed)     );     //alert(oListItem.get_Id());   <-- caused an error }  function onAddSucceeded(sender, args) {     \$  ("#divResult").html("Item successfully added!"); } function onAddFailed(sender, args) {     alert('Request failed. ' + args.get_message() +     '\n' + args.get_stackTrace()); }