Skip to content

Instantly share code, notes, and snippets.

View cballou's full-sized avatar

Corey Ballou cballou

View GitHub Profile
@cballou
cballou / caterpillar-example-usage.php
Created November 10, 2012 11:58
Examples of using the Caterpillar cURL Multi-Get PHP Crawler
<?php
require_once('./caterpillar.php');
// set configuration params
$config = array(
'crawlUrl' => 'http://www.url-to-crawl.co',
'dbUser' => 'username',
'dbPass' => 'password',
'dbName' => 'database',
'dbHost' => 'localhost'
@cballou
cballou / new-csshook-template.js
Created November 3, 2012 11:19
Creating jQuery CSS3 Vendor Prefix Mixins with $.cssHooks
(function($) {
if ( !$.cssHooks ) {
throw("jQuery 1.4.3+ is needed for this plugin to work");
return;
}
function styleSupport( prop ) {
var vendorProp, supportedProp,
capProp = prop.charAt(0).toUpperCase() + prop.slice(1),
prefixes = [ "Moz", "Webkit", "O", "ms" ],
@cballou
cballou / php-ftp-download-auto-resume.php
Created September 25, 2012 10:57
Download a file via FTP with auto-resume functionality in case of any disconnects.
<?php
/**
* Copyright (C) <2012> <Corey Ballou>
* @author Corey Ballou <http://www.craftblue.com>
* @license MIT License
*/
/**
* Handles FTP download of a remote file and stores it in a local file.
*
@cballou
cballou / Komodo-IDE-7-CSS-Tidy.js
Created September 7, 2012 11:06
Komodo IDE 7 CSS Tidy with PHP
/**
* A Komodo IDE / Edit macro for tidying up files. New addition for CSS.
*
* @author Corey Ballou http://coreyballou.com <only added CSS modification>
*
* Credit to the original unknown author of this macro:
* http://community.activestate.com/forum/format-document-script
*/
komodo.assertMacroVersion(3);
if (komodo.view.scintilla) {
@cballou
cballou / determine-dictionary-word-metaphone.php
Created July 16, 2012 13:19
Creating a MySQL DB table for Implementing Metaphone Dictionary Lookups
<?php
/**
* The below code will calculate the metaphone value for every word in the MySQL dictionary we
* just created and update the table accordingly. This code is nothing fancy, but gets the
* job done. Sorry I didn't use PDO :)
*/
// specify your MySQL connection settings
define('HOST', 'localhost');
define('USERNAME', 'your_username');
@cballou
cballou / php-mysql-like-query-dos-attack-example.php
Created July 5, 2012 17:36
PHP MySQL LIKE Query DoS Attack Example
<?php
// client side: assume user has maliciously used the following values in a form search input field and submitted
$field = '<input type="text" name="query" value="%slow_your_db" />';
// server-side: assume retrieval of form search input value
$search_term = !empty($_GET['query']) ? $_GET['query'] : NULL;
// try to escape the input before querying, but we fail to escape the qualifier
// and it remains "%slow_your_db"
$search_term = mysql_real_escape_string($search_term);
@cballou
cballou / php-clean-string.php
Created May 24, 2012 17:43
Clean a string pasted from an unknown source (i.e. Microsoft Word) that might have invalid UTF-8 chars
<?php
function clean($value, $escape = true, $quotes = true)
{
$a = array(
'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë',
'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø',
'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å',
'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò',
'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā',
'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č',
@cballou
cballou / relative-position.js
Created May 11, 2012 14:12
Implementing relative positioning with jQuery Tools Tooltip Plugin
// assumes you have a parent container with relative positioning
$('a.my_tooltip').tooltip({
effect: 'fade',
relative: true,
predelay: 300,
onBeforeShow: function() {
var
config = this.getConf(),
$tip = this.getTip();
@cballou
cballou / example-secure-hash-class-usage.php
Created April 21, 2012 19:35
Secure PHP Authentication Revisited - Using bcrypt
<?php
/**
* The code below shows example usage of the SecureHash class for
* encrypting a password. In terms of additional usage, you should
* store the resulting encrypted password in addition to the salt
* in your db.
*/
// load the class
$secure = new SecureHash();
@cballou
cballou / box-model-sizing-fix-example.css
Created April 10, 2012 12:20
The below code fixes the box model for the given block level elements, meaning that
/* the following div will remain at 100% width even with padding applied */
div.padded {
width: 100%;
padding: 20px;
}