Thursday, October 27, 2016

Oracle: insert or update

In this example, there is a table Employee, and the table has columns EmployeeId and PhoneNumber.

If for the employee 123, we want to add her number into the table, or update her number when she is already in the table, we can use this command:

MERGE INTO Employee e 
      USING dual ON (e.EmployeeId = 123)
       UPDATE SET e.PhoneNumber = '555-555-5555'
       INSERT (e.EmployeeId, e.PhoneNumber) 
              VALUES (123, '555-555-5555');

Saturday, September 10, 2016

How to fix the uncontrollable mouse when playing Minecraft on VMware Player

When playing Minecraft on VMware Player's guest OS, the game and the host OS both try to grab the mouse. Hence when you move the mouse, the scene of the game moves wildly.

One trick to fix that is to disconnect the mouse from the host OS so that only the game will control the mouse.

Step 1: before starting the VM image, change its settings: Hareware -> USB Controller -> Check the checkbox of Show all USB input devices.

Step 2: Starts the VM image. After it is booted, find in the top right corner the icon that represents the mouse. Right click it and choose to Connect (Disconnect from host).

Step 3: Enjoy the game.

Step 4: When finish playing, shut down the guest OS and the host OS will gain back the control of the mouse.

Tuesday, April 26, 2016

C++: Convert a string to its hex form

#include <sstream>
#include <iomanip>


std::string toHex(const std::string &input)
    std::stringstream ss;
    ss << hex;

    for (size_t i = 0; i < input.length(); i++)
        ss << setw(2) << setfill('0') 
           << (unsigned short)(input[i] & 0xff);

    return ss.str();
Get This <