Skip to content

Instantly share code, notes, and snippets.

View Mint704_Assignment1.py
#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
#Usage:
#python Mint704_Assignment1.py
import sys
def slow_solution():
View test.py
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
else:
s.send("client not authenticated\n")
s.close()
@rotexdegba
rotexdegba / center-jquery-dialog.php
Last active Oct 3, 2018
Centering a JQuery Dialog
View center-jquery-dialog.php
<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 Nov 21, 2013
How to add drop down list to a cell in PHPExcel
View dropdown-list-in-a-cell-phpexcel.php
<?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 Dec 31, 2015
MySQL commands to create users via the mysql command line utility
View mysql-command-line-user-creation.sh
# 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 Dec 31, 2015
Useful regular expressions
View handy-regexes.txt
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 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
<?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 Feb 11, 2014
How to Use Unique Indexes in MySQL and Other Databases - SitePoint
View unique-indexes-mysql.md

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 Aug 29, 2015
PHP Password hashing demo.
View php-password-hashing-demo.php
<?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 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
<?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.