Skip to content

Instantly share code, notes, and snippets.

View rotexdegba's full-sized avatar

Rotimi Ade rotexdegba

View GitHub Profile
@rotexdegba
rotexdegba / generate-backtrace-info-for-logging.php
Created February 7, 2014 20:38
This php code snippets generates a backtrace log string of method call stacks along a an inheritance hierarchy. Work in progress.
<?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
rotexdegba / unique-indexes-mysql.md
Created February 11, 2014 17:26
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:

INSERT INTO phone

(country, area, number)

(1, 234, 567890);

@rotexdegba
rotexdegba / php-password-hashing-demo.php
Last active August 29, 2015 13:56
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
rotexdegba / quickly-convert-xml-to-php-objects.php
Created April 9, 2015 20:04
How to Quickly Convert Xml Read into a SimpleXMLElement object into PHP Objects
<?php
$url = 'http://some-server.com/some-file.xml';
$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
rotexdegba / mem-consumption-tests.php
Created May 26, 2015 21:45
PHP Script to Benchmark Memory Consumtion on Common Array / Object / String Memory Consumption
<?php
ini_set('memory_limit', '1024M');
function test(){
$index = 0;
//Case 1
$a = '';
@rotexdegba
rotexdegba / mysql-command-line-user-creation.sh
Last active December 31, 2015 18:09
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';
# mysql> GRANT ALL PRIVILEGES ON *.* TO 'rotimi'@'%' WITH GRANT OPTION;
@rotexdegba
rotexdegba / handy-regexes.txt
Last active December 31, 2015 18:09
Useful regular expressions
Remove spaces after last semi colon on each line of a php file.
find:
;[^\S\n]+$
relace with:
;
---------------------------------------------------------------------------------------
Remove spaces on blank lines
find:
^[^\S]+$
replace with:
@rotexdegba
rotexdegba / remove-old-linux-kernels.sh
Last active September 9, 2016 22:37
remove old linux kernels in a debian flavored linux distro like ubuntu, mint, etc.
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
@rotexdegba
rotexdegba / phpword-view-template-for-promis2.0.php
Created July 5, 2017 22:23
phpword-view-template-for-promis2.0
<?php
$phpword_writer_wrapper = new \Promis2\PhpWordWriterWrapper();
// New Word document
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Do stuff with $phpWord
// ............
// ............