Skip to content

Instantly share code, notes, and snippets.

@mllvzeth
mllvzeth / prepare & execute PDO SQL INSERT with placeholders
Last active July 28, 2021 02:59
simplified automatic PDO INSERT SQL time saver ⌛ by @Rami_jamleh; with revision by @Clair_Shaw
<?php
/**
* @Rami jamleh - http://php.net/manual/en/pdostatement.execute.php#111823
* @Clair_Shaw(Revision) - http://php.net/manual/en/pdostatement.execute.php#116901
* simplified $placeholder form
**/
$data = ['a'=>'foo','b'=>'bar'];
$keys = array_keys($data);
$fields = '`'.implode('`, `',$keys).'`';
//$placeholder = substr(str_repeat('?,',count($keys),0,-1));
@mllvzeth
mllvzeth / gist:6e9a3f44461edb337f932ae98ee41bb5
Created March 29, 2017 21:06
Runinng process with realtime output in PHP
//*
* http://stackoverflow.com/questions/1281140/run-process-with-realtime-output-in-php
*
//
$cmd = "ping 127.0.0.1";
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
@mllvzeth
mllvzeth / .gitignore
Created March 30, 2017 16:22 — forked from octocat/.gitignore
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@mllvzeth
mllvzeth / print_r2.php
Created April 5, 2017 21:58 — forked from Shelob9/print_r2.php
Make print_r() more readable. Found on http://us2.php.net/print_r
<?php
function print_r2($val){
echo '<pre>';
print_r($val);
echo '</pre>';
}
?>
@mllvzeth
mllvzeth / print_r2.php
Created April 5, 2017 21:58 — forked from Shelob9/print_r2.php
Make print_r() more readable. Found on http://us2.php.net/print_r
<?php
function print_r2($val){
echo '<pre>';
print_r($val);
echo '</pre>';
}
?>
@mllvzeth
mllvzeth / shuffle_assoc
Created April 6, 2017 18:20 — forked from Quinten/shuffle_assoc
shuffle an array while preserving keys
<?php
function shuffle_assoc($list) {
if (!is_array($list)) return $list;
$keys = array_keys($list);
shuffle($keys);
$random = array();
foreach ($keys as $key)
$random[$key] = $list[$key];
return $random;
@mllvzeth
mllvzeth / load-html-as-utf-8-php-hack.php
Created April 6, 2017 20:58
load HTML as UTF-8 using simple hack:
<?php
/**
* @mdmitry at gmail dot com
*
*/
$doc = new DOMDocument();
$doc->loadHTML('<?xml encoding="UTF-8">' . $html);
// dirty fix
@mllvzeth
mllvzeth / OpenWithSublimeText2.bat
Created April 14, 2017 15:54 — forked from mrchief/LICENSE.md
Add "Open with Sublime Text 2" to Windows Explorer Context Menu (including folders)
@echo off
SET st2Path=C:\Program Files\Sublime Text 2\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@mllvzeth
mllvzeth / jurchiks101phpgenerateCallTrace
Created April 25, 2017 18:29
PHP Error Handling - @jurchiks101's generateCallTrace()
<?php
/**
* jurchiks101_at_gmail_dot_com
* Can be found at http://php.net/manual/en/function.debug-backtrace.php#112238
*/
function generateCallTrace()
{
$e = new Exception();
$trace = explode("\n", $e->getTraceAsString());
// reverse array to make steps line up chronologically