Skip to content

Instantly share code, notes, and snippets.

@hyperking
hyperking / djax + body class update
Last active August 29, 2015 13:56
updating body class with current page name for djax plugin
<script type="text/javascript">
var transition = function($newEl) {
// the pageTitle var assumes your title tag is formatted as " Site Name|Page Name "
// i perfer to use this method, otherwise landing page body class will show empty
var pageTitle = document.title.split('|')[1].toLowerCase().replace(/ /g,"-");
function updateBodyClass(){
$('body').removeClass().addClass(pageTitle);
}
var $oldEl = this; // reference to the DOM element that is about to be replaced
$newEl.hide(); // hide the new content before it comes in
@hyperking
hyperking / MiniCart JS cart widget + item counter & cart toggle button
Last active August 29, 2015 13:57
MiniCart JS Cart Widget and Item Counter
<html>
<head>
<meta charset="UTF-8">
<title>MiniCart JS</title>
</head>
<body>
<div id="cart">
<button class="showCart">Show Cart</button>
<div class="itemCount"></div>
<!-- paypal minicart will be added here after dom load -->
@hyperking
hyperking / function.php
Last active August 29, 2015 14:01
Wordpress JSON generator
function jsonGenerator(){
// Auto Generate Sitemaps after every new post
add_action("publish_post", "create_jsonfiles");
add_action("publish_page", "create_jsonfiles");
function create_jsonfiles() {
$postsForJson = get_posts(array(
'numberposts' => -1,
// 'orderby' => 'modified',
'post_type' => array('post','page'),
'order' => 'DESC' ));
@hyperking
hyperking / DropboxBackupDB.php
Created June 9, 2014 14:52
Back up DB to Dropbox
<?php
// Set the timezone so filenames are correct
date_default_timezone_set('Europe/London');
// Backup all files in public_html apart from the gz
$siteroot = "/path/to/backup";
$dropbox_email='dropbox@email'; //Dropbox username
$dropbox_pass='pass'; // Dropbox password
@hyperking
hyperking / SyncServerFoldertoDropbox.php
Created June 9, 2014 14:53
Remote Folder to Dropbox folder
<?php
// Set the timezone so filenames are correct
date_default_timezone_set('Europe/London');
// Backup all files in public_html apart from the gz
$siteroot = "/path/to/backup";
$dropbox_email='dropbox@email'; //Dropbox username
$dropbox_pass='pass'; // Dropbox password
@hyperking
hyperking / leaflet-ajax-links.js
Created June 17, 2014 21:27
Load Leaflet marker links with Ajax into a div container without page refreash
@hyperking
hyperking / form.html
Last active August 29, 2015 14:08
form validator
<h3>header</h3>
<form method="POST" id="myform" action="echo/html">
<label for="foo">First Name:</label>
<input type="input" id="foo">
<br>
<label for="bar">Last Name:</label>
<input type="input" id="bar">
<br>
<label for="baz">Email:</label>
@hyperking
hyperking / tableTojson.html
Created August 19, 2015 22:28
convert table element to json object
<table>
<thead>
<tr>
<th>Name</th>
<th>Hobby</th>
<th>Favorite Music</th>
</tr>
</thead>
<tbody>
<tr class="tabledata">
function donationformToJSON(){
var sections = $('td[class*="BBListingHeading"]');
collection = [];
sections.each(function(id,elem){
var section_name = $(elem).text();
var labels = $(elem).parents('tbody').find('label');
//compile dictionary for each form element
//separated by sections
jsonobject = {}
labels.each(function(id,lel){
@hyperking
hyperking / CRM designation parser
Last active November 9, 2015 14:25
How to structure BBCRM api designations response
CRMresponse = [{
"Values": ["Arboretum Development Fund", "Arboretum", "University of Hyper\\Ontario Agricultural College\\Arboretum", "7b5ced38-53f1-412d-8a2a-98b947f086db", "", "Arboretum Development Fund", "7b5ced38-53f1-412d-8a2a-98b947f086db"]
}, {
"Values": ["Dean's Innovation Fund", "College of Arts", "University of Hyper\\College of Arts", "1ea85925-c4a9-4c3e-81f5-228b21ab1ec8", "Focuses on meeting the overall needs of the College of Arts.", "College of Arts Dean's Innovation Fund", "1ea85925-c4a9-4c3e-81f5-228b21ab1ec8"]
}, {
"Values": ["College of Arts Student Assistance", "College of Arts", "University of Hyper\\College of Arts", "bc17fa75-16c6-4c6a-876c-ef0ba284ec6f", "", "College of Arts Student Assistance", "bc17fa75-16c6-4c6a-876c-ef0ba284ec6f"]
}, {
"Values": ["CBS Highest Priority", "College of Biological Science", "University of Hyper\\College of Biological Science", "0e0863fd-92e3-40e7-a832-0ca0afdaf850", "", "CBS Highest Priority", "0e0863fd-92e3-40e7-a832-0ca0afdaf850"]
},