Skip to content

Instantly share code, notes, and snippets.

View shawn-crigger's full-sized avatar

Shawn Crigger shawn-crigger

View GitHub Profile
@shawn-crigger
shawn-crigger / 0_reuse_code.js
Created June 8, 2014 04:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@shawn-crigger
shawn-crigger / populate_empty_fields.php
Created June 26, 2014 16:45
Method to populate empty database fields, just some random ghetto superstar code.
<?php
/**
* Populates empty database fields, ghetto fix for not having default values.
*
* @param string $table Table name to grab fields from
* @param array $data Array of data to merge the default values into.
* @param object $db Reference to the database connection, yea I'm a ghetto superstar.
*
* @return array
@shawn-crigger
shawn-crigger / jquery.ajax.progress.js
Last active February 24, 2021 18:28 — forked from db/jquery.ajax.progress.js
Creating a jQuery File Upload Progress meter
(function addXhrProgressEvent($) {
var originalXhr = $.ajaxSettings.xhr;
$.ajaxSetup({
progress: function() { console.log("standard progress callback"); },
xhr: function() {
var req = originalXhr(), that = this;
if (req) {
if (typeof req.addEventListener == "function") {
req.addEventListener("progress", function(evt) {
that.progress(evt);
@shawn-crigger
shawn-crigger / chainSelects.js
Created October 9, 2014 15:02
jQuery Chained Selects Plugin
/**
* Handles chained select boxs
* @author Shawn Crigger
*/
;(function ( $, window, document, undefined ) {
// Create the defaults once
var chainSelects = "chainSelects",
self = null,
defaults = {
@shawn-crigger
shawn-crigger / listing_image.class.php
Created October 16, 2014 17:46
Using PDO::FETCH_CLASS like a Boss, straight object oriented masterbation lol.
<?php
/**
* Listing_Image is a sample class for demonstrating the PDO::FETCH_CLASS method, like a boss.
*
* Example usage:
*<code>
* $img = $q->fetch(PDO::FETCH_CLASS, "Listing_Image");
* echo $img->get_image_tag();
*</code>
@shawn-crigger
shawn-crigger / ga_tracking.js
Created October 19, 2014 18:49
Very nicely used Google Analytics tracking code.
$("a").click(function() {
var href, href_lower;
href = ($(this).attr("href") === undefined ? "" : $(this).attr("href"));
href_lower = href.toLowerCase();
if (href_lower.substr(-3) === "pdf" || href_lower.substr(-3) === "xls" || href_lower.substr(-3) === "doc") {
_gaq.push(["_trackEvent", "document", "download", href_lower.substr(-3), $(this).text()]);
_gaq.push(["_trackPageview", href]);
}
@shawn-crigger
shawn-crigger / jquery-img--rollover.html
Last active February 15, 2019 03:42
Quick and dirty image roll over
<img src="http://nonhover.jpg" alt="" class="roll-over" data-roll-over="http://hover.jpg" />
<script>
jQuery( "img.roll-over" ).hover( function() {
var old = $(this).attr('src');
var roll = $(this).data('roll-over');
$(this).attr('src', roll).data('roll-over', old);
}, function() {
var old = $(this).attr('src');
var roll = $(this).data('roll-over');
$(this).attr('src', roll).data('roll-over', old);
@shawn-crigger
shawn-crigger / footer.html
Created December 4, 2014 19:46
jQuery CDN with Fallbacks
@shawn-crigger
shawn-crigger / db.php
Created December 5, 2014 16:01
Singleton Class wrapper for $wpdb
<?php
class DB
{
/**
* Returns the *Singleton* instance of this class.
*
* @staticvar Singleton $instance The *Singleton* instances of this class.
*
@shawn-crigger
shawn-crigger / functions.php
Created December 8, 2014 22:35
Remove un-needed junk from WP head
<?php
remove_action('wp_head', 'wp_generator');
remove_action( 'wp_head', 'wlwmanifest_link');
remove_action ('wp_head', 'rsd_link');
remove_action( 'wp_head', 'wp_shortlink_wp_head');