Skip to content

Instantly share code, notes, and snippets.

View cballou's full-sized avatar

Corey Ballou cballou

View GitHub Profile
@cballou
cballou / css3-font-face-bold-italic-support.css
Created March 24, 2012 21:29
CSS3 @font-face With Bold and Italic Support
/* normal case */
@font-face {
font-family: "DejaVu Sans";
src: url(‘path-to-font-directory/DejaVuSans.eot’);
src: local(‘☺’), url("path-to-font-directory/DejaVuSans.ttf") format("truetype");
}
/* bold */
@font-face {
font-family: "DejaVu Sans";
@cballou
cballou / fast-string-sort.php
Created March 24, 2012 21:38
A QUICK IMPLEMENTATION OF STRING SORT IN PHP
<?php
function sortString(&amp;$s) {
$s = str_split($s);
sort($s);
$s = implode($s);
}
// example usage prints:
// 1223344789aaaaadddefffffhhhiillllnnoorrsssuuuuwyy
$string = 'ouhlasfuywernhlasdfoulnarfiuyadf1234987234sdfailh';
@cballou
cballou / form-handler-example.php
Created March 24, 2012 21:47
SPF30 - A Spam Blocking/Prevention PHP Library
<?php
require_once('./spf30.php');
if (!empty($_POST)) {
try {
// this is an example of the form data before decryption
var_dump($_POST);
// run validation on the submitted email form
spam::validate($_POST);
@cballou
cballou / jquery-getMatchingClass-examples.js
Created March 25, 2012 11:56
The getMatchingClass plugin is useful for determing whether a singular matching element contains a particular <em><strong>partial class name</strong></em>. The idea behind the function is to allow for partial matching using a subset of jQuery selectors. h
// example one - remove class if a match is found at the beginning
$elem = $('#elemToMatch');
$.each($elem.getMatchingClass('*=classBeginsWith_'), function() {
$elem.removeClass(this);
});
// example two - perform an action if a match is found at the end
// note this is not a very good method for showing and hiding
// child elements and is only used as an example
$('#elemToMatch').click(function() {
@cballou
cballou / domain-name-finder-usage.sh
Created March 25, 2012 12:10
With the following simple snippet of code you will be able to generate a list of all available two word combinations for a supplied list of keywords. It can be ran from the command line and can output a txt file of all matching domains.
// output will go to domains_found.txt in the same directory
php -f domain-name-finder.php
// output will go to the file specified as well as domains_found.txt in the same directory
php -f domain-name-finder.php > my-output-file.txt
@cballou
cballou / example-FILES-array-fix-usage.php
Created March 25, 2012 12:57
Uploading Multiple Files in PHP – Fixing the Array Indices
<?php
// passed by reference
fixFilesArray($_FILES['fieldname']);
// all fixed
var_dump($_FILES['fieldname']);
@cballou
cballou / example-fbml-style.html
Created March 25, 2012 13:13
Overriding Facebook FBML Styling on a Canvas Page
<link rel="stylesheet" type="text/css" media="screen" href="http://www.yoursite.com/css/canvas.css?v=1.2" />
<div id="container">
<!-- AS AN EXAMPLE, WE'LL STYLE THE FB SHARE BUTTON -->
<fb:share-button class="url" href="http://www.your-site-url.com" />
</div>
@cballou
cballou / firebug-console-execution-time.js
Created March 25, 2012 13:23
Optimizing (and Debugging) Javascript With Firebug
console.time();
var str = '';
for (var i = 0; i < 1000; i++) {
str += i;
}
console.timeEnd();
@cballou
cballou / one-way-mysql.sql
Created March 25, 2012 13:33
Securing Your PHP Sessions with a Salt (old, use bcrypt)
CREATE TABLE `secure_login` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`email` VARCHAR(120) NOT NULL,
`password` VARCHAR(40) NOT NULL,
`session` VARCHAR(40) DEFAULT NULL,
`disabled` TINYINT(1) UNSIGNED DEFAULT 0,
`created_dt` DATETIME DEFAULT '0000-00-00 00:00:00',
`modified_ts` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_idx` (`email`)
@cballou
cballou / one-way-mysql.sql
Created March 25, 2012 14:17
Securing Your PHP Sessions with a Random Salt (old, use bcrypt)
CREATE secure_login (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`email` VARCHAR(120) NOT NULL,
`salt` VARCHAR(8) NOT NULL,
`password` VARCHAR(40) NOT NULL,
`session` VARCHAR(40) DEFAULT NULL,
`disabled` TINYINT(1) UNSIGNED DEFAULT 0,
`created_dt` DATETIME DEFAULT '0000-00-00 00:00:00',
`modified_ts` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),