Skip to content

Instantly share code, notes, and snippets.

@davidrenne
davidrenne / Show Process List HTML
Created October 24, 2011 22:00
Show Process List HTML because pressing UP + ENTER in shell is annoying
<?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 November 1, 2011 15:48
The most amazing mysql flags ever - multiple queries in one mysql_query
<?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 November 9, 2011 12:34
Dumb script that will download a repository to your server
<?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 December 15, 2011 02:07
Seriously Is It this much code to support case insensitive post/get keys? There has got to be a better way...
<?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 February 24, 2012 20:51
Nice utility to scan real-time all your php fatals and parse errors in production
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:
@davidrenne
davidrenne / dabblet.css
Created March 28, 2012 02:57 — forked from tylergaw/dabblet.css
Untitled
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 April 24, 2012 12:35
Slave server DOWN management
<?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);
@davidrenne
davidrenne / gist:2594907
Created May 4, 2012 13:50
AutoLoadMinifier
<?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 July 19, 2012 12:42
Import Excel to Mysql using autoit.
;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 August 1, 2012 21:40
json_encode_non_buggy
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)
{