Skip to content

Instantly share code, notes, and snippets.

<?php
$iterations = 10000;
$msg = "
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc at dolor eget quam vehicula gravida. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean et lectus vitae dui viverra euismod. Vivamus eu magna eros, at accumsan est. Sed massa est, sodales vitae eleifend sed, placerat eu diam. Quisque vel risus nibh, at euismod massa.
Morbi sed augue neque. Suspendisse id tristique odio. Praesent bibendum scelerisque dolor ut placerat. Proin ut augue et dui hendrerit gravida eu a dolor. Pellentesque at enim elit. Mauris ac mauris elit. Maecenas tempor augue et libero dictum eu imperdiet nunc pharetra. Aliquam tempus euismod felis eget hendrerit. Curabitur eu fringilla neque. Aenean ut nisl magna, ac tincidunt tellus. Morbi erat turpis, egestas ac blandit nec, consectetur ut mauris. Nulla id ipsum eu diam vestibulum posuere sed vitae ante. Donec urna nunc, tincidunt id aliquet ut,
@meghuizen
meghuizen / .htaccess
Last active December 13, 2015 22:49
Secure .htaccess
# Secure htaccess
### If you run a webserver other than Apache, consider:
### github.com/h5bp/server-configs
# Install APC for caching
# command line: pecl install apc
# For installing a debugger/profiler:
# command line: pecl install xdebug-beta
<?php
mt_srand(1361152757.2);
for ($i=1; $i < 25; $i++) {
echo mt_rand(), PHP_EOL;
}
@meghuizen
meghuizen / CsrfToken.php
Created March 12, 2013 20:32
Anti CSRF
<?php
/**
* See for more info: http://blog.ircmaxell.com/2013/02/preventing-csrf-attacks.html
*/
abstract class CsrfToken {
private static $_currentToken;
private static $_tokenLifetime = 3600; // could be a nice addition
@meghuizen
meghuizen / random-key.php
Last active December 14, 2015 20:58
Generate strong random keys (can be used for encryption)
<?php
/**
* Random key generator example.
*
* See: http://timoh6.github.io/2013/11/05/Secure-random-numbers-for-PHP-developers.html
* https://github.com/ircmaxell/random_compat
*
* Code a simplified and modified version of the RandomLib of https://github.com/ircmaxell/RandomLib
* From the File RandomLib/lib/RandomLib/Generator.php the function generateString
@meghuizen
meghuizen / php-encryption.txt
Last active December 14, 2015 21:29
php encryption stuff
* https://github.com/jmhobbs/K3-Encryption/blob/master/classes/kohana/encryption.php
* http://blog.djekldevelopments.co.uk/?p=334
* https://gist.github.com/meghuizen/5147425
* https://bugs.php.net/bug.php?id=62453&edit=1
* http://php.net/manual/en/function.hash-pbkdf2.php
* http://www.itnewb.com/tutorial/Encrypting-Passwords-with-PHP-for-Storage-Using-the-RSA-PBKDF2-Standard
* http://timoh6.github.io/2013/11/05/Secure-random-numbers-for-PHP-developers.html
* https://github.com/ircmaxell/random_compat
@meghuizen
meghuizen / escape-attrs.js
Created April 18, 2013 08:44
Escape HTML attributes using JavaScript
/**
* Escapes HTML attributes using JavaScript
*/
function escapeHtmlAttr(attr) {
var cdiv = document.createElement('div');
cdiv.setAttribute('abc', attr);
return cdiv.outerHTML
.substr(10, cdiv.outerHTML.length - 18);
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@meghuizen
meghuizen / openssl-example.php
Created May 24, 2013 07:20
OpenSSL Example
<?php
// Create the keypair
$res=openssl_pkey_new();
// Get private key
openssl_pkey_export($res, $privatekey);
// Get public key
$publickey=openssl_pkey_get_details($res);

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.