Skip to content

Instantly share code, notes, and snippets.

View rotexdegba's full-sized avatar

Rotimi Ade rotexdegba

View GitHub Profile
@rotexdegba
rotexdegba / center-jquery-dialog.php
Last active April 27, 2024 10:01
Centering a JQuery Dialog
<script type="text/javascript">
//<![CDATA[
jQuery.noConflict();
jQuery(
function() {
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
//jQuery( "#dialog:ui-dialog" ).dialog( "destroy" );
jQuery( "#dialog-form" ).dialog({
autoOpen: false,
height: 600,
@rotexdegba
rotexdegba / dropdown-list-in-a-cell-phpexcel.php
Created November 21, 2013 18:25
How to add drop down list to a cell in PHPExcel
<?php
$objValidation = $objPHPExcel->getActiveSheet()->getCell("C$curr_row")->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION );
$objValidation->setAllowBlank(false);
$objValidation->setShowInputMessage(true);
$objValidation->setShowErrorMessage(true);
$objValidation->setShowDropDown(true);
$objValidation->setErrorTitle('Input error');
$objValidation->setError('Value is not in list.');
@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 / 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 / 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 / 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 / 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/