Skip to content

Instantly share code, notes, and snippets.

View rotexdegba's full-sized avatar

Rotimi Ade rotexdegba

View GitHub Profile
@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 / common-ubuntu-software-i-use.md
Last active September 28, 2017 20:31
A list of applications I normally use on my Ubuntu or Mint Desktop Machines.
@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 / download-full-copy-of-website-via-wget.sh
Last active August 14, 2019 16:43
How to download a full copy of a website for offline reading via wget
wget --wait=20 --mirror --convert-links --page-requisites --no-parent -U Mozilla http://www.website.com/
# OR
wget --wait=20 --mirror --convert-links --adjust-extension --page-requisites --no-parent -U Mozilla http://www.website.com/
@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 / in-array-optimizations.php
Last active September 9, 2022 01:12
Alternative implementation of in_array using either isset or array_key_exists. This approach requires restructuring the original array.
<?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
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 / 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 / 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 / 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: