PHP Page Generation Time Code Example Script

PHP Page Generation TimeWhen optimising a website, it’s common for people to measure the PHP page generation time because it is more reliable than the client measuring the total request time which includes network delay which is beyond the scope of the code.

I recently started updating a combined CRM/CMS that I initially developed for an online-only reseller business. Back then, this was how one would usually get microsecond-accurate PHP script generation times. The reason I’m posting this, is not because it’s an integral development for the language but because I see lots of people still recommending the following solution.

Continue reading

mysqldump diff MySQL Differential Backup Shell Script

mysqldump diffmysqldump diff is a shell script that I wrote to take some of the pain out of differential MySQL backups.

Download mysqldump diff

After changing the appropriate values, this will dump your database daily and create a unified diff patch so you’ll only need to keep the original mysqldump intact and patch files describing the subsequent differences between each future dump. It is a simple form of version control for MySQL database dumps without the overhead of managed methods. Although results will differ based on on the frequency of record-modification and the interval between backups, using this method on weekly backups (over a 2-month period), my patches were each roughly a tenth of the size of the original dump and of course, the benefits are exponential as time goes on while allowing you to increase the frequency many-fold while still saving space.

Continue reading

Origin is not allowed by Access-Control-Allow-Origin

Remote Origin Errors with JSONP and jQueryAre you self-harming because your browser is complaining about cross-domain, remote-origin XML requests? As annoying as it can be, the web would be a much nastier place without this restriction that limits what can be pulled from where. You’re probably seeing this exact message in the console/error log of your browser’s development tools:

Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin

Once you understand why you’re getting issues with this, it’s tiresome to always be re-writing this integral function so, like my other free web development resources on here, I’ve saved an example as a gist on GitHub with jQuery and PHP code which you are free to copy, clone or download then use without limitation!

Continue reading

ISO 3166-1 Country Codes MySQL Import Script

Probably like most, I’m sick of finding or formattingĀ  country-code lists into an acceptable format for importing into MySQL for every single project that’s nationally-aware. This time around, I exported ISO 3166-1 as numeric, alpha-2 and alpha-3 with the corresponding country names. I only ever use the alpha-2 format but I thought I’d include the rest for anyone that might want them. The alpha-2 codes fit perfectly with famfamfam flag icon set thusly:

echo "<img src='/images/flags/".strtolower($country['alpha-2']).".png'>";

Download iso-3166-1.sql

Brute Force TrueCrypt Volumes

Brute Force TrueCryptSomeone at work uses TrueCrypt and forgot their password for an encrypted volume which had some important, business-related files that were needed. This person relies on muscle memory for their passwords which has them employing alternating combinations of strings to create secure but forgettable password. To exemplify this method, the three strings “123″, “abc” and “!@#” could yield them a password of “abc!@#123″ or 26 other variations.

This person had no luck in trying everything that they could think of so I made a PHP and Bash script to automate the slow, brute force TrueCrypt volume with 100.000 password combinations to attempt. To save the web browser from a slow demise, I installed php5-cli and had Bash write the results – extremely quickly!
Continue reading