Free web-based currency rates fetcher script

<?php
 
function convert($from,$to,$amount) {
    $url = "https://www.google.com/search?q=".$from.$to;
    $request = curl_init();
    $timeOut = 0;
    curl_setopt ($request, CURLOPT_URL, $url);
    curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML
, like Gecko) Chrome/68.0.3440.106 Safari/537.36");
    curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);
    $response = curl_exec($request);
    curl_close($request);
 
    preg_match('~<span [^>]* id="knowledge-currency__tgt-amount"[^>]*>(.*?)</span>~si', $response, $finalData);
    return floatval((floatval(preg_replace("/[^-0-9\.]/","", $finalData[1]))/100) * $amount);
}
 
echo convert("USD", "GBP", "1");
?>

Check if database table column exists

SHOW COLUMNS FROM Tablename WHERE FIELD = "Fieldname";

Folder names uppercase or lowercase

Use all lowercase for technical / system or development related folders:

/srv/machine1/inbox
/srv/machine1/scripts

Use Capitalized names for personal, desktop-facing, or user-interface symlink folders:

/home/username1/Documents
/home/username1/Projects

Find and rename files uppercase to lowercase

find my_folder -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;

Find my pattern and rename

find ./ -type f -name '*_en-gb.json' -exec sh -c 'mv "$0" "${0%_en-gb.json}_en-uk.json"' {} \;

Git rollback to particular commit

Use gitk to find out which commit you want to rollback and do the following:

git reset --hard 53c309929253a2a

Read the content of zip archive without extraction

unzip -l archive.zip

Alter pdf file with Gimp

gimp document.pdf

1. click ‘Select All’ and open and edit it

2. When you are about to save, gimp can’t save multipages pdf directly. You’ll need to use an intermediate file format

3. Install ImageMagick

sudo apt-get install imagemagick

4. Save in Gimp
File -> Export -> document.mng

5. Export to pdf in a command line

convert -reverse document.mng document.pdf

Rename files in folder

for i in *.png; do mv "$i" "${i/.png/t.png}"; done

Fastest example to output image

$file = 'myimage.png';
$size = getimagesize($file);
 
$fp = fopen($file, 'rb');
 
if ($size and $fp)
{
    header('Content-Type: '.$size['mime']);
    header('Content-Length: '.filesize($file));
    fpassthru($fp);
}

git new branch

git checkout -b new_branch_name

git remove remote branch

git push origin --delete feature/login
git push origin :feature/login