Skip to content

Instantly share code, notes, and snippets.

View detain's full-sized avatar
💯
Da Vinci of Linux, Van Gogh of Code, [self proclaimed, but legit]

Joe Huss detain

💯
Da Vinci of Linux, Van Gogh of Code, [self proclaimed, but legit]
View GitHub Profile
@detain
detain / mytop.sh
Last active August 16, 2020 13:59
mytop (Monitor mysql process list with top like screen updates and adiditonal stats like cpu/io usage)
#!/bin/bash
# mytop.sh - (Monitor mysql process list with top like screen updates and adiditonal stats like cpu/io usage)
#
# Sample Output:
#
# CPU Usage 3.29% user 1.60% system 3.37% io wait 0.00% steal 91.59% idle
# Up 17 days 10 hours Load Avg 0.43 0.36 0.35 Processes 1(running) 408(total) Last PID 17825
# +----------+------+-----------+----+---------+------+-------+------------------+
# | Id | User | Host | db | Command | Time | State | Info |
# +----------+------+-----------+----+---------+------+-------+------------------+
<?php
$files = explode(' ', './scripts/map_sql_to_api.php ./scripts/whmcs_import.php ./scripts/map_everything_to_my.php ./scripts/whmcs_import2.php ./phpunit/class_tests/db_mdb2Test.php ./phpunit/class_tests/db_PDOTest.php ./phpunit/class_tests/db_mysqlTest.php ./phpunit/class_tests/db_mysqliTest.php ./include/preconfig.functions.inc.php ./include/accounts/accounts.inc.php ./include/dns/pdns.functions.inc.php ./include/db/class.db_mdb2.functions.inc.php ./include/functions.inc.php ./monitord.php ./monitord_new.php');
foreach ($files as $file)
{
echo "Working on file $file\n";
$txt = file_get_contents($file);
$regex = '/([\s]+)(\$[\w\[\]\'_]+) = new db;\n[\s]+\$[\w\[\]\'_]+->Host = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Database = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->User = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Password = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Type = ([^;]+);/m';
if (preg_match($regex, $txt))
{
$txt = preg_replace($regex, '\1\2 = new db(\4, \5, \6, \3);\1\2->Type = \
@detain
detain / index.html
Created May 18, 2014 08:42
A Pen by Joe Huss.
<!--
12 Dec 2013:
Plunker went down, got unstable, and the embedded preview failed.
So I'm putting up the same demo here temporarily.
Unfortunate that CodePen cannot have multiple files, so code here looks a bit messy,
not that I intend it to be, but putting this up is priority.
I'll clean this up when I have time...
-->
@detain
detain / is_url.php
Created September 28, 2014 05:28
URL detection and split it into parts, each part is optional minus the hostname.
<?php
function is_url($text)
{
if (preg_match('/((?P<protocol>[a-z]{3,6}):\/\/)?((?P<userpass>[a-z]+:[a-z]+|[a-z]+)@)?(?P<hostname>[a-z0-9.-]+\.[a-z]{2,6})(:(?P<port>[0-9]+))?(?P<path>\/.)?/i', $text, $matches))
{
$ret = array();
foreach ($matches as $key => $value)
{
if (!is_numeric($key) && $value != '')
{
@detain
detain / openvz_cpu_usage.sh
Created October 18, 2014 23:54
OpenVZ CPU Usage Totals Per VPS Per CPU/Core
#!/bin/bash
# CPU Usage Totals Per VPS Per CPU/Core
# Written by Joe Huss <detain@interserver.net>
# - This is just way better than anything else out there for gathering this info
# Screenshots of it here:
# http://forum.interserver.net/forum/threads/script-get-openvz-cpu-usage-totals-per-vps-per-cpu-core.4859/
IFS="
";
debug=0;
if [ -e ~/.cpu_usage.last.sh ]; then
@detain
detain / xml2array.php
Created October 21, 2014 00:49
xml2array() works great, mirrored from http://www.bin-co.com/php/scripts/xml2array/
<?php
/**
* xml2array() will convert the given XML text to an array in the XML structure.
* Link: http://www.bin-co.com/php/scripts/xml2array/
* Arguments : $contents - The XML text
* $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the tag values - this results in a different array structure in the return value.
* $priority - Can be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance.
* Return: The parsed XML in an array form. Use print_r() to see the resulting array structure.
* Examples: $array = xml2array(file_get_contents('feed.xml'));
* $array = xml2array(file_get_contents('feed.xml', 1, 'attribute'));
@detain
detain / get_rpmbuild_dir.sh
Created October 21, 2014 13:27
Getting the correct RPM directory for compiling [for scripting purposes]
rpmdir="$(grep "^%_topdir" /usr/lib/rpm/macros | sed -e s#"^.*%{getenv:HOME}"#"${HOME}"#g -e s#"^.*%{_usrsrc}"#"/usr/src"#g)";
Vagrant.configure(2) do |config|
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
end
end
@detain
detain / gist:c0e135bd64c0ec805487
Created September 17, 2015 20:37
Changes since we last updated Observium
Changelogs
August 2015 ( 131 commits )
r6802 to 6933
Device Support
Added support for DDN SFA devices
Added support for user/device license graphs for Mitel devices
Added support for Rittal CMC devices including water flow rate sensors
Added support for failover status sensors on Cisco ASAs
Added support for Netgear ReadyDATA OS temperature and fanspeed sensors from READYDATAOS-MIB
Added support for Netgear ReadyNAS temperature and fanspeed sensors from READNAS-MIB
@detain
detain / Interactive Customer Feedback Form (For a pet store).markdown
Created January 9, 2016 01:42
Interactive Customer Feedback Form (For a pet store)