Skip to content

Instantly share code, notes, and snippets.

@davidrenne
davidrenne / Show Process List HTML
Created Oct 24, 2011
Show Process List HTML because pressing UP + ENTER in shell is annoying
View Show Process List HTML
<?php
$conn = mysql_connect('yourserver','yourusername','yourpassword');
echo "<html><head><META HTTP-EQUIV='Refresh' CONTENT='2; URL=".$_SERVER['PHP_SELF']."'><body>";
echo "<table><th>ID</th><th>DATABASE</th><th>QUERY</th><th>EXECUTION TIME</th><th>STATE</th>";
$res = mysql_query("show processlist");
while($row = mysql_fetch_assoc($res))
{
if (stristr($row['State'],"Has sent all binlog to slave"))
{
continue;
@davidrenne
davidrenne / gist:1330885
Created Nov 1, 2011
The most amazing mysql flags ever - multiple queries in one mysql_query
View gist:1330885
<?php
define('CLIENT_LONG_PASSWORD',1); /* new more secure passwords */
define('CLIENT_FOUND_ROWS',2); /* Found instead of affected rows */
define('CLIENT_LONG_FLAG',4); /* Get all column flags */
define('CLIENT_CONNECT_WITH_DB',8); /* One can specify db on connect */
define('CLIENT_NO_SCHEMA',16); /* Don't allow database.table.column */
define('CLIENT_COMPRESS',32); /* Can use compression protocol */
define('CLIENT_ODBC',64); /* Odbc client */
define('CLIENT_LOCAL_FILES',128); /* Can use LOAD DATA LOCAL */
define('CLIENT_IGNORE_SPACE',256); /* Ignore spaces before '(' */
@davidrenne
davidrenne / gist:1351309
Created Nov 9, 2011
Dumb script that will download a repository to your server
View gist:1351309
<?php
if (array_key_exists('user',$_REQUEST))
{
if (!is_dir($_REQUEST['repo']))
{
system("mkdir {$_REQUEST['repo']} && cd {$_REQUEST['repo']} && git init && git pull git://github.com/{$_REQUEST['user']}/{$_REQUEST['repo']}.git master");
}
else
{
@davidrenne
davidrenne / gist:1479507
Created Dec 15, 2011
Seriously Is It this much code to support case insensitive post/get keys? There has got to be a better way...
View gist:1479507
<?php
$caseInsensitivePosts = array('your_desired_cleaned_lower_case_post_var');
foreach($_GET as $k=>$v)
{
$lower = strtolower($k);
foreach ($caseInsensitivePosts as $requestVal)
{
if ($requestVal == $lower && $k !== $requestVal)
{
@davidrenne
davidrenne / gist:1903668
Created Feb 24, 2012
Nice utility to scan real-time all your php fatals and parse errors in production
View gist:1903668
Edit cron tab to point to this file and run php script every one minute:
*/1 * * * * php /yourpath/phpFatals.php web01
*/1 * * * * php /yourpath/phpFatals.php cron01
*/1 * * * * php /yourpath/phpFatals.php etcetc
Edit the below variables:
View dabblet.css
body {
font-family: helvetica;
}
li:nth-last-child(-n + 4) {
opacity: 0.6;
}
li:nth-last-child(-n + 3) {
opacity: 0.4;
@davidrenne
davidrenne / gist:2479283
Created Apr 24, 2012
Slave server DOWN management
View gist:2479283
<?php
//1. Create a file that contains your constants or paths of locations of files
//2. Update your database classes before they make a connection to look for this $contants['slave_on'] path. If file doesnt exist, only make a connection to your master server. Tweak the settings of the seconds_behind_master if 120 seconds is too much for your reporting of slave data.
//3. Create a monitoring script to ping this URL to see if the connection is "OK". Upon error it will unlink the file and recreate it once the slave's IO is back up
include('yourconstants.php');
$conn = mysql_connect('server','username','password');
$singleRow = mysql_query("SHOW SLAVE STATUS");
$row = mysql_fetch_array($singleRow);
View gist:2594907
<?php
//It turns out, that it takes more memory and same amount of time to have all your includes in one file. I thought that all the file I/O would be less with one huge compiled include file. This class will combine all your includes into one file.
//it could be useful to try to see all your includes top down. But over all is not meant for production
//Ended up using spl_autoload_register which took all my production includes from 40MB to 10MB and increased speed by 1 to 3 seconds
/*
implementation
@davidrenne
davidrenne / gist:3143568
Created Jul 19, 2012
Import Excel to Mysql using autoit.
View gist:3143568
;copy the top header columns. save as C:\import.csv and it will build the needed SQL to import
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $cTooltipClick
$clipBoardContents = ClipGet()
$array1 = StringExplode($clipBoardContents, @TAB, 0)
$cols = ""
$tableDef = "DROP TABLE IF EXISTS `development`.`import_tmp`; " & @CRLF & @CRLF & "CREATE TABLE `development`.`import_tmp` ("
@davidrenne
davidrenne / gist:3230999
Created Aug 1, 2012
json_encode_non_buggy
View gist:3230999
function json_encode_non_buggy($array, $return=false)
{
//fixes cases where json_decode will crap out.
foreach ($array as $k=>$v)
{
$array[$k] = str_replace(array("\t",'"'),array(" ","&quot;"), utf8_encode($v));
}
if($return)
{