How to mount and unmount remote directory

Mounting

mkdir ~/remoteDir
ssh-keygen -t rsa
ssh-copy-id -i .ssh/id_rsa.pub user@hostname
sudo apt install sshfs
sshfs user@hostname:/ ~/remoteDir

Unmounting

fusermount -u ~/remoteDir

Apt sources.list to add or remove deb installation repositories

vi /etc/apt/sources.list

Simple php based mysql query script

<?php
 
$dbname = 'dbname';
$dbuser = 'user';
$dbpass = 'pass';
$dbhost = 'hostname';
 
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SELECT 1,2,3,4 FROM yourtable";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
  $tblCnt++;
  echo $tbl[0]."<br />\n";
  echo $tbl[1]."<br />\n";
  echo $tbl[2]."<br />\n";
  echo $tbl[3]."<br />\n";
}
 
if (!$tblCnt) {
  echo "There are no tables<br />\n";
} else {
  echo "There are $tblCnt tables<br />\n";
}

How-to detach running process from terminal

If your job is running in terminal do

bg -- Move running process to background --
jobs -- list the jobs in background and get id of the job you want to detach --
disown %1 -- use job id from previous query for detaching from the terminal --

Mysql show full list of processes in memory

SHOW FULL PROCESSLIST;

Php Nearest Match

function getNearestMatch($number, $candidates) {
 
	$candidates = is_array($candidates) ? $candidates : array($candidates);
 
	$size = count($candidates);
	if ($size > 0) {
		//absolute difference between 0th element and input value
		$diff = abs($candidates[0] - $number);
		//element closest to input value
		$ret = $candidates[0];
		//loop through the rest of the array
		for ($i = 1; $i < $size; $i++) {
			$temp = abs($candidates[$i] - $number);
			if ($temp < $diff) {
				//set new difference and closest element
				$diff = $temp;
				$ret = $candidates[$i];
			}
		}
		return $ret;
	} else {
		return NULL;
	}
 
    }

Yahoo finance rates convert (for educational purposes only)

<?php
class Rates {
	function Convert($amount,$from,$to){
		$url="http://adsynth-ofx-quotewidget-prod.herokuapp.com/api/1";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, '{"method":"spotRateHistory","data":{"base":"'.$from.'","term":"'.$to.'","period":"week"}}');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
		curl_setopt($ch, CURLOPT_REFERER, "https://widget-yahoo.ofx.com/");
		$html = curl_exec ($ch);
		curl_close ($ch);
		$veri=json_decode($html,true);
		return $veri["data"]["CurrentInterbankRate"]*$amount;
	}
}
$kur = new Rates();
echo $kur->Convert(1, 'USD', 'GBP');

Apply and revert patch

# Test before apply
patch -p1 --dry-run > /path/to/some.patch
# Apply patch
patch -p1 > /path/to/some.patch
# Revert
patch -p1 -R > /path/to/some.patch

Creating patch

git format-patch -1 SHA5

Convert mp4 to mp3

ffmpeg -i wombsounds.mp4 -f mp3 -ab 192000 -vn wombsounds.mp3