Skip to content

Instantly share code, notes, and snippets.

#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():
if data.startswith("hello secret", 0) :
if data == "hello secret lemmetalk\n":
s.send("client authenticated\n")
# store the fact that this client has been authenticated in another list
# which keeps track of authenticated clients
# define this list at the top near where you defined the list for select sockets
s.send("client not authenticated\n")
rotexdegba / center-jquery-dialog.php
Last active Oct 3, 2018
Centering a JQuery Dialog
View center-jquery-dialog.php
<script type="text/javascript">
function() {
// a workaround for a flaw in the demo system (, ignore!
//jQuery( "#dialog:ui-dialog" ).dialog( "destroy" );
jQuery( "#dialog-form" ).dialog({
autoOpen: false,
height: 600,
rotexdegba / dropdown-list-in-a-cell-phpexcel.php
Created Nov 21, 2013
How to add drop down list to a cell in PHPExcel
View dropdown-list-in-a-cell-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->setErrorTitle('Input error');
$objValidation->setError('Value is not in list.');
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 / 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! $$$$!';
You can’t perform that action at this time.