Skip to content

Instantly share code, notes, and snippets.

@jboesch
jboesch / map_obj_support.js
Created April 13, 2011 23:07
Backwards compat for versions of jQuery prior to 1.6 that want to use objects in jQuery.map
// Only load this in if the version of jQuery is prior to 1.6
if(parseFloat(jQuery.fn.jquery) < 1.6){
jQuery.map = (function(_oldmap){
return function(){
var elems = arguments[0],
length = elems.length,
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ((length > 0 && elems[0] && elems[length -1]) || jQuery.isArray(elems));
@jboesch
jboesch / ajax_complete_not_called.js
Created April 7, 2011 20:18
jQuery's complete is not being called when I have 400 headers set... weird.
/*
* So it seems my "complete" callback is never called when I have a header of 400 or 404 set. Any ideas?
*/
// My PHP file..
header("Content-Type: application/json");
header('HTTP/1.1 400 Bad Request');
$response = array(
'status' => 'error',
// 100x faster than Sizzle: https://github.com/jquery/sizzle
// 50x faster than Qwery: https://github.com/ded/qwery
function fastQueryQuicklySpeedyAndKingOfRapidness(selector){
if(!document.querySelectorAll){
alert('Sorry buddeh. Plz upgrade yur browsr to harness the real power of this awsome app i builded.');
return;
}
return document.querySelectorAll(selector);
@jboesch
jboesch / $.fn.outerHTML.js
Created March 27, 2011 07:11
$.fn.outerHTML method
/*
* Full example here: http://jsfiddle.net/jboesch26/3SKsL/1/
*/
$.fn.outerHTML = function(){
// IE, Chrome & Safari will comply with the non-standard outerHTML, all others (FF) will have a fall-back for cloning
return (!this.length) ? this : (this[0].outerHTML || (
function(el){
var div = document.createElement('div');
@jboesch
jboesch / spam_filter.php
Created February 24, 2011 22:11
Filtering out spam
if(isset($_POST['post_comment'])){
if(stristr('SEO', $_POST['message'])){
die('fuck off');
}
}
<?
// 1. Change the line at the bottom that detects YourLib::isLocal() to whatever you want to use for detecting if you're running locally. This just outputs the mail message if we are local.
// 2. Add <?= $this->Session->flash('email'); ?> to your default.ctp view. This is where the debug email will output to (if you're running locally)
// 3. Copy the below into a file called custom_email_component.php
// 4. Now in your controller or wherever, call it: public $components = array('CustomEmail');
// 5. Use exactly like you would the Email component, eg. $this->CustomEmail->to = '[email protected]'
/**
* The reason we're extending CakePHP's email component is because
* we don't want to repeat ourselves when sending mail. This allows us
* to plug in some defaults like "$from" and $this->delivery = 'debug' if
// Step 1: Include jQueryify bookmarklet from http://www.learningjquery.com/2006/12/jquerify-bookmarklet
// Step 2: Plug this into your console.
var total = [];
$('.cur_val[headers=gross]').each(function(){
var t = $.trim(this.innerHTML.replace('$', '').replace(',',''));
/* PayPal has two selectors of .cur_val[headers=gross] that point to the same amount.
We only want the one with a space in it, cause tht tells us whether or not it's CAD/USD */
if(t.indexOf(' ') > -1){
total.push(t);
}
@jboesch
jboesch / jQuery click() not triggered by change()
Created February 5, 2011 16:03
trigger('click') does not trigger a change() event in jQuery (bug)
jQuery version (does not work): http://jsfiddle.net/MLqS4/1/
Native version (works fine): http://jsfiddle.net/cq84C/1/
@jboesch
jboesch / removeClass_prefix.js
Created January 12, 2011 17:23
Allows you to removeClasses based on a wildcard
// http://jsfiddle.net/w5TnB/5/
// HTML
<div class="myclass ui-dialog ui-widget ui-blah something">
<a href="#">REMOVE ALL CLASSES WITH UI PREFIX</a>
</div>
// Regular jQuery
$('a').click(function(){
$(this).parent().removeClass('ui-* something');
return false;
<?
/**
* Some versioned URL's for cache busting when we push new changes up
* Only need the file name, paths will resolve appropriately in the
* $file_path variable
* Usage: <?= vurl('myfile.js'); ?>
*
* @param $file {String} The file - eg. 'file.js' or 'file.css'
* @param $type {String} We can optionally specify a type (probably not needed)
*/