Wednesday, September 30, 2015

How to backup a single MySQL database?

  1. Open the Command Prompt (Windows)/Terminal (Linux)
  2. Type the following command:

    mysqldump -u {username} -p{password} -h {host} {databaseName} > {backup-name}.sql
{username} is the login that has access to connect to the database
{password} is the login's password
{host} is the server name where it is the database
{databaseName} is the database name
{backup-name} is the name back up file name

Example:

I want to backup the BAZINGA database located at the TheBigBangTheory host with the user name Sheldon and password Cooper and save it on Meemaw.sql  file.

mysqldump -u Sheldon -pCooper -h TheBigBangTheory BAZINGA > Meemaw.sql

Source: https://www.linode.com/docs/databases/mysql/back-up-your-mysql-databases

Friday, September 18, 2015

Thursday, September 17, 2015

How to do foreach in Java

List<String> collection = new ArrayList<String>();

collection.add("Hello");
collection.add("World");

for(String item:collection)
{
System.out.println(item);
}

Wednesday, September 16, 2015

How to check how much RAM you have installed in Linux


  1. Open terminal
  2. Type

    free -mt
This command will output the memory in megabytes

How to move the Eclipse workspace to another folder


  1. Close Eclipse
  2. Open the OS file manager (Example: Windows Explorer for Windows and Nautilus for Linux)
  3. Move the workspace folder to the new location
  4. Open Eclipse
  5. In the menu bar, click File
  6. Mouse over Switch Workspace
  7. Click Other...
  8. Select the new workspace folder location
  9. Click OK

Monday, September 14, 2015

How to fix web sites cannot be started unless both the Windows Activation Service (WAS) and the World Wide Web Publishing Service (W3SVC) are running IIS Error

IIS Error


Fix
  1. Open command prompt and type:

    net start w3svc

  2. Open IIS
  3. Start the site again


How to execute any PowerShell script in your development machine


  1. Open PowerShell ISE
  2. In command pane type:

    Set-ExecutionPolicy Unrestricted

  3. In Execution Policy Change window, click Yes
ATTENTION! This is only recommended for development machines.

How to remove duplicate XML nodes using PowerShell

catalog.xml
<?xml version="1.0" encoding="utf-8"?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE><ARTIST>Bob Dylan</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>Columbia</COMPANY><PRICE>10.90</PRICE><YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Greatest Hits</TITLE><ARTIST>Dolly Parton</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>RCA</COMPANY><PRICE>9.90</PRICE><YEAR>1982</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR>
  </CD>
</CATALOG>

Code:
# Load XML file

$file = "catalog.xml"
$xml = [xml](Get-Content $file)

# Add the DuppieID attribute to the XML document

$i = 1
foreach($node in $xml.CATALOG.CD)
{  
    $node.SetAttribute("DuppieID", $i)
    $i++
}

# Parse the document and delete the duplicate nodes with the exception of the first occurrence

foreach($node in $xml.CATALOG.CD)
{  
    $duplicates = ($xml.CATALOG.CD | where {$_.TITLE -eq $node.TITLE})
   
    if($duplicates.length -gt 1)
    {
        for($i = 1; $i -lt $duplicates.length; $i++)
        {
            $element = $duplicates[$i]
            $nodeToRemove = $xml.SelectSingleNode("//CATALOG/CD[@DuppieID=" + $element.DuppieID + "]")
            $nodeToRemove.ParentNode.RemoveChild($nodeToRemove)
        }
    }
}

# Remove DuppieID attribute
   
foreach($node in $xml.CATALOG.CD)
{  
    $node.RemoveAttribute("DuppieID");
}

# Update the file

$xml.Save($file)

Source: http://klemmestad.com/2014/08/08/removing-duplicate-xml-nodes-using-powershell/

Wednesday, September 2, 2015

How to activate the tab auto-complete on a xrdp session in Xubuntu


  1. Open terminal
  2. Open the  ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml using a text editor
  3. Find the node

    <property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>

  4. Replace to

    <property name="&lt;Super&gt;Tab" type="string" value="empty"/>

  5. Save the file
  6. Restart the machine

How to find the largest files and folders in Linux


  1. Open terminal
  2. Type

    du -a /{folder} | sort -n -r | head -n {count}
{folder} is the starting location where you want to find the largest files and folders
{count} number of results you want to see

Example

Find the top 10 files of the whole file system
du -a / | sort -n -r | head -n 10

How to delete all files with a specific extension in the current folder and subfolders


  1. Open terminal
  2. Type the command

    find /{path}/ -type f -name "*.{extension}" -delete
{path} folder where the are the files that you want to delete
{extension} file extension that you want to delete

Example:

Delete all MPG files from /home/luizcgjr and its subfolders

find /home/luizcgjr/ -type f -name "*.mpg" -delete

Source: http://unix.stackexchange.com/questions/42020/how-can-i-delete-all-files-with-a-particular-extension-in-a-particular-folder

How to enable Remote Desktop connection on Xubuntu

  1. Open terminal
  2. Type the command

    sudo apt-get install xrdp

  3. Restart Xubuntu
  4. Once the machine is restarted, go to the machine where you want remote connect
  5. Open remote desktop client
  6. Connect to the machine where you installed the xrdp
  7. At the Login to xrdp window, select sesman-Xvnc for Module
  8. In username type the login that you use to logon to the machine locally
  9. In password type the login's password

  10. Click OK
Attention: this will create a new x Session and not mirror what are you current seeing in your remote machine. There are other solutions for that.