This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/local/bin/bash | |
DB=$2 | |
HOST=$1 | |
TABLE=$5 | |
USER=$3 | |
PASS=$4 | |
MYSQLDUMP=$(which mysqldump) | |
MYSQLDUMP_OPTS=" --no-create-db --add-locks --add-drop-table --extended-insert --verbose" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function running() { | |
// check if already running, quit if so | |
exec("ps auxww | grep running.php | grep -v grep", $ps); | |
if (count($ps) > 1) { | |
echo "Already running!\n"; | |
return; | |
} | |
sleep(60); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Find unused functions in a legacy project that are safe to remove | |
* | |
* @author: Vijay Mahrra <[email protected]> | |
*/ | |
$folder = 'legacy'; | |
$cmd = "grep -aRi 'function ' $folder/*"; | |
exec($cmd, $results); | |
$removeable = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// script to parse mac address db at | |
// https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf | |
$data = file('vendors.txt'); | |
foreach ($data as $line) { | |
if (preg_match("/^#.*/", $line)) { | |
continue; | |
} elseif (preg_match("/([A-F0-9]+:[A-F0-9]+:[A-F0-9]+)\s+[^#]+#\s+(.+)/i", $line, $matches)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$filename = 'report_period_' . date('Y-m-d', $time) . '.csv'; | |
$file = sys_get_temp_dir() . '/' . $filename; | |
$fp = fopen($file, 'w'); | |
foreach ($csvData as $r) { | |
fputcsv($fp, $r); | |
} | |
fclose($fp); | |
$size_in_bytes = filesize($file); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cards = [ | |
'MasterCard0' => '5555555555554444', | |
'MasterCard1' => '5105105105105100', | |
'Visa0' => '4111111111111111', | |
'Visa1' => '4012888888881881', | |
'Visa2' => '4929000005559', | |
'Visa3' => '4929000000014', | |
'Visa4' => '4929000000022', | |
'Visa5' => '4222222222222', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
/** | |
* url_resolve.php - CLI script for resolving url | |
* | |
* @author Vijay Mahrra <[email protected]> | |
* @copyright (c) Copyright 2018 Vijay Mahrra | |
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html) | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('VERBOSE', 1); | |
define('DEBUG', 1); | |
//----------------------------------------------------------------------------- | |
// required commands check | |
$commands = get_commands([ | |
'find' => 'System command: find', | |
'curl' => 'https://curl.haxx.se', | |
'wget' => 'https://www.gnu.org/software/wget/' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://www.youtube.com/watch?v=M3_xnTK6-pA?t=44m18s | |
// http://eddmann.com/posts/implementing-and-using-memoization-in-php/ | |
//$memoize = function ($function) { | |
function memoize($function) { | |
return function () use ($function) { | |
static $cache = []; | |
$args = func_get_args(); | |
$key = md5(serialize($args)); | |
if (empty($cache[$key])) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Implement a memoization function to cache results of expensive function calls. | |
$timer = function ($function) { | |
// Create an array to store cached results based on function arguments. | |
$cache = []; | |
// Return a closure that wraps the original function. | |
return function (...$args) use ($function, &$cache) { | |
// Generate a unique key for the cache based on function arguments. |