Skip to content

Instantly share code, notes, and snippets.

rotexdegba / generate-backtrace-info-for-logging.php
Created Feb 7, 2014
This php code snippets generates a backtrace log string of method call stacks along a an inheritance hierarchy. Work in progress.
View generate-backtrace-info-for-logging.php
/// Generate Call Trace Info ///
$backtrace = debug_backtrace(~DEBUG_BACKTRACE_PROVIDE_OBJECT);
$backtrace_start_index = 1; //index to start reading from in the
//array returned by debug_backtrace
$class = "[\n";
rotexdegba /
Created Feb 11, 2014
How to Use Unique Indexes in MySQL and Other Databases - SitePoint

MySQL NULLs I say almost any database because MySQL has an odd quirk. NULL is treated as a unique value — which is why you cannot use comparisons such as value = NULL and need to use value IS NULL. Unfortunately, this also affects unique indexes and no logic has been implemented to fix it.

We can execute our original INSERT multiple times and a new record will be created each time because the extension field defaults to NULL and is considered to be unique:


(country, area, number)

(1, 234, 567890);

rotexdegba / php-password-hashing-demo.php
Last active Aug 29, 2015
PHP Password hashing demo.
View php-password-hashing-demo.php
function register($user, $password) {
$hash = password_hash($password, PASSWORD_BCRYPT);
$this->store($user, $hash);
function login($user, $password) {
$hash = $this->fetchHash($user);
rotexdegba / in-array-optimizations.php
Last active Aug 29, 2015
Alternative implementation of in_array using either isset or array_key_exists. This approach requires restructuring the original array.
View in-array-optimizations.php
//This isset optimization is not suitable for arrays that contains null values.
$a = array('a' => null);
isset($a['a']); // Will be FALSE
array_key_exists('a', $a); // Will be TRUE
$total = 10000;
$paragraph = 'this is a sentence. Crud! $$$$!';
rotexdegba / quickly-convert-xml-to-php-objects.php
Created Apr 9, 2015
How to Quickly Convert Xml Read into a SimpleXMLElement object into PHP Objects
View quickly-convert-xml-to-php-objects.php
$url = '';
$simplexmlelement_obj = simplexml_load_file($url);
$array_of_objects_from_xml = array();
if ($simplexmlelement_obj !== false) {
$xml_as_json = json_encode($simplexmlelement_obj);
$array_of_objects_from_xml = json_decode($xml_as_json);
rotexdegba / mem-consumption-tests.php
Created May 26, 2015
PHP Script to Benchmark Memory Consumtion on Common Array / Object / String Memory Consumption
View mem-consumption-tests.php
ini_set('memory_limit', '1024M');
function test(){
$index = 0;
//Case 1
$a = '';
#A program that computes the maximum integer value before
#python switches to using the long data type for a value
#There are 2 methods used here, one fast and the other takes a while to compute
import sys
def slow_solution():
rotexdegba /
Last active Dec 31, 2015
MySQL commands to create users via the mysql command line utility
# mysql --user=root --password=somepassword #connect to mysql as root or any other user that has the appropriate user creation permissions
# mysql> CREATE USER 'rotimi'@'localhost' IDENTIFIED BY 'password';
# mysql> GRANT ALL PRIVILEGES ON *.* TO 'rotimi'@'localhost' WITH GRANT OPTION;
# mysql> CREATE USER 'rotimi'@'%' IDENTIFIED BY 'password';
rotexdegba / handy-regexes.txt
Last active Dec 31, 2015
Useful regular expressions
View handy-regexes.txt
Remove spaces after last semi colon on each line of a php file.
relace with:
Remove spaces on blank lines
replace with:
rotexdegba / for-loop-replacement-of-foreach.php
Last active Apr 25, 2016
for loop replacement of foreach
View for-loop-replacement-of-foreach.php
for (reset($array); list($key, $value) = each($array);) {
echo $key;
echo $value;
echo $array[$key];
//You can add more initializations, conditions and incrementation statements
You can’t perform that action at this time.