Skip to content

Instantly share code, notes, and snippets.

View randolphledesma's full-sized avatar

Randolph Ledesma randolphledesma

  • Zylun
  • Cebu City
View GitHub Profile
@randolphledesma
randolphledesma / file.sh
Created August 28, 2019 03:14
Copy files on background process
yes | nohup cp -Rfav /home/sites/* /home/backup >> /tmp/cplog.log 2>&1&
@randolphledesma
randolphledesma / file.php
Created July 30, 2019 22:58
PHP: Validate if PDF
<?php
require("fpdf/fpdf.php");
require("fpdf/fpdi.php");
function is_pdf($file) {
try {
$pdf = new FPDI();
$pdf->setSourceFile($file);
} catch(Exception $e) {
return false;
@randolphledesma
randolphledesma / .htaccess
Created July 25, 2019 02:09
Block php or javascript
<FilesMatch "\.(?i:php|js)$">
Order allow,deny
Deny from all
</FilesMatch>
@randolphledesma
randolphledesma / file.sh
Created July 24, 2019 00:17
Find in content of PHP files
#!/bin/sh
find . -type f -name '*.php' -not -path "*/dev/*" -not -path "*/tickets/*" -not -path "*/admin/*" -not -path "*/includes/*" -not -path "*/vendor/*" | xargs egrep -n -i "(fwrite|move_uploaded_file|file_put_contents|fputs|fputcsv) *\("
@randolphledesma
randolphledesma / file.sh
Created July 9, 2019 05:17
Lint PHP files staged on git
#!/bin/sh
( ( (git diff --name-only origin/master $GIT_COMMIT ) | grep .php$ ) | xargs -n1 echo php -l | bash ) | grep -v "No syntax errors detected" && echo "PHP Syntax error(s) detected"
@randolphledesma
randolphledesma / file.php
Last active July 16, 2019 23:47
Sanitize Links
<?php
function fix_special_links($text) {
$fixed = $text;
$fixed = str_replace("/><br />", "/> <br>", $fixed);
$fixed = str_replace("/><br>", "/> <br>", $fixed);
$fixed = preg_replace("#\<http:\/\/(.*)(\/\>)+#i", "(http://$1)", $fixed);
$fixed = preg_replace("#\<https:\/\/(.*)(\/\>)+#i", "(https://$1)", $fixed);
return $fixed;
}
@randolphledesma
randolphledesma / docker.txt
Last active June 13, 2019 00:50
Docker Containers
docker run -d -p 1080:1080 -p 1025:1025 --name mailcatcher schickling/mailcatcher
docker run -d -p 1081:1080 -p 1026:1025 --name mailcatcher2 schickling/mailcatcher
@randolphledesma
randolphledesma / file.php
Last active May 16, 2019 00:08
PHP: Timezone Conversion
<?php
$timestamp='2019-05-16 07:56:00';
$format="Y-m-d H:i:s";
$from_timezone='Asia/Manila';
$to_timezone='America/Chicago';
$source_timezone = new DateTimeZone($from_timezone);
$destination_timezone = new DateTimeZone($to_timezone);
$datetime = new DateTime($timestamp, $source_timezone);
var_dump($datetime);
$offset = $destination_timezone->getOffset($datetime);
@randolphledesma
randolphledesma / script.php
Created May 12, 2019 22:55
PHP: Remove anchor tags on string
<?php
$str = "<a>bing.com</a>";
echo preg_replace('#<a.*?>([^>]*)</a>#i', '$1', $str)
@randolphledesma
randolphledesma / tz.js
Created April 23, 2019 03:43
Extract timezones
$(".LMgvRb").each(function(i, x){ var sql="INSERT INTO timezone (location, tz) VALUES ('" + $(x).attr("aria-label") + "','" + $(x).attr("data-value") + "')" });