Skip to content

Instantly share code, notes, and snippets.

View mildfuzz's full-sized avatar

John Farrow mildfuzz

View GitHub Profile
@mildfuzz
mildfuzz / gist:1118296
Created August 1, 2011 15:02
MetaBox class
<?php
$MF_MetaFields; //global defined to store meta ID's
class MetaBox{
protected $options = array(); //for storing all options
protected $id; //unique string ID for naming field
protected $title; //Box Title
protected $posttype; //Array (list, of, post, types) to attach to
protected $context;//Optional. normal, or side
protected $priority = "low";//optional
@mildfuzz
mildfuzz / MF_Query.php
Created September 23, 2011 10:44
Forces pagintation where pagination fails in Wordpress
<?php
class MF_Query extends WP_Query{
private $page_link = "page";
function __construct(array $args){
if(!array_key_exists('posts_per_page',$args)) $args['posts_per_page'] = 10;
if(array_key_exists('page_link',$args)) $this->page_link['page_link'];
$args['offset'] = (isset($_GET[$this->page_link])?($_GET[$this->page_link]-1)*$args['posts_per_page']:0);
parent::query($args);
@mildfuzz
mildfuzz / gist:1250187
Created September 29, 2011 07:31
Calendar Class
<?php
class Mf_calendar{
private $post_type = "post";
private $prefix;
private $posts = array();
private $month;
private $year;
private $first_day;
@mildfuzz
mildfuzz / geolocal.js
Created October 24, 2011 12:30
geoLocal JS
var scripts = {};
var w3cGeo = {};
w3cGeo.api = '95b5c8ffb1d0891fe5a1eed66ce0d2d5';
var gLocalSearch = new GlocalSearch();
google.load("search", "1");
google.load("maps", "2", {"callback" : w3cGeo.mapsLoaded});
@mildfuzz
mildfuzz / plugins.js
Created September 21, 2012 15:12
My Library
/*
A collection of useful scripts
*/
//Collect all form data into a string
$.fn.getFormData = function(){
var str = "";
var areas = $(this).find('input').not('input[type=submit]').not('input[type=button]').add($(this).find('textarea')).add($(this).find('select'));
areas.each(function(i){
@mildfuzz
mildfuzz / facebook_test_user.js
Created October 3, 2012 14:00
Fetch Test Facebook User
var APP_ID = prompt("Input your App Id");
var APP_SECRET = prompt("Input your App Secret");
$.ajax({
url: "https://graph.facebook.com/oauth/access_token?client_id="+APP_ID+"&client_secret="+APP_SECRET+"&grant_type=client_credentials",
type: "GET",
success: function(data){
window.location = "https://graph.facebook.com/"+APP_ID+"/accounts/test-users?installed=false&locale=en_UK&permissions=read_stream&method=post&access_token="+data.replace('access_token=','');
}
})
@mildfuzz
mildfuzz / isCreditCard.js
Created October 11, 2012 09:14
isCreditCard.js
String.prototype.isCreditCard = function()
{
//Credit - https://sites.google.com/site/abapexamples/javascript/luhn-validation
var luhnArr = [[0,2,4,6,8,1,3,5,7,9],[0,1,2,3,4,5,6,7,8,9]], sum = 0;
this.replace(/\D+/g,"").replace(/[\d]/g, function(c, p, o){
sum += luhnArr[ (o.length-p)&1 ][ parseInt(c,10) ];
});
return (sum%10 === 0) && (sum > 0);
};
@mildfuzz
mildfuzz / isCVV.js
Created October 11, 2012 09:40
Detect if a string input is a valid CVV Credit Card Security number
String.prototype.isCVV = function(){
return (this.length >= 3 && this.length <=4) && Number(this) ? true : false
}
@mildfuzz
mildfuzz / toggleHTML.js
Created October 16, 2012 12:46
toggleHTML.js
$.fn.toggleHTML = function(a,b){
//toggles two HTML values of given object, defaults to A unless equal to A
$(this).html(($(this).html() == a ? b : a));
}
@mildfuzz
mildfuzz / getobjectbyattribute.js
Created October 17, 2012 14:30
getObjectByAttribute
Array.prototype.getObjectByAttribute = function(value, attribute){
var catcher = [], i = 0;
while(!catcher && this[i]){
if(this[i].attribute == value){
catcher.push(this[i]);
}
i++;
}
return catcher.length == 1 ? catcher[0] : catcher.length ? catcher : false;
}