Skip to content

Instantly share code, notes, and snippets.

View codescribblr's full-sized avatar

Jonathan Wadsworth codescribblr

View GitHub Profile
@codescribblr
codescribblr / swipe.js
Created September 18, 2014 17:44
Adds the ability to handle swipe events.
//Example Usage
$('#selector').each(function(){
swipedetect(this, function (swipedir){
// swipedir contains either "none", "left", "right", "top", or "down"
if (swipedir =='left') {
$("#selector").parent().find('.next').click();
}
if (swipedir =='right') {
$("#selector").parent().find('.prev').click();
}
@codescribblr
codescribblr / bitly.php
Created August 24, 2014 02:10
Using bit.ly v3 api to shorten a url with php.
/* make a URL small */
function make_bitly_url($url,$access_token) {
//create the URL
$bitly = 'http://api-ssl.bitly.com/v3/shorten?access_token='.$access_token.'&longUrl='.urlencode($url);
//get the url
//could also use cURL here
$response = file_get_contents($bitly);
$json = @json_decode($response,true);
@codescribblr
codescribblr / hamburger.css
Created June 24, 2014 20:14
Hamburger Icon for mobile nav
#hamburger span, #hamburger span:before, #hamburger span:after {
cursor: pointer;
border-radius: 1px;
height: 5px;
width: 35px;
background: white;
position: absolute;
display: block;
content: '';
}
@codescribblr
codescribblr / jquery.validate.bootstrap.js
Created April 15, 2014 13:48
Using jQuery.validate() with bootstrap 3 styles
// override jquery validate plugin defaults
$.validator.setDefaults({
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
@codescribblr
codescribblr / Util.class.php
Last active August 29, 2015 13:58
Helper Functions
<?php
class Util {
function __construct(){
}
public static function log($action, $message="", $logfile=false) {
$logfile = ($logfile) ? $logfile : $_SERVER['DOCUMENT_ROOT'].'/logs/log'.date("Y-m-d").'.log';
$new = file_exists($logfile) ? false : true;
if($handle = fopen($logfile, 'a')) { // append
$timestamp = strftime("%Y-%m-%d %H:%M:%S", time());
@codescribblr
codescribblr / animations.css
Created April 2, 2014 16:00
This is a list of animations that use css3. Easily animate an element by adding an .animated class and a .{animation-name} class.
//Animations
.animated {
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: 0.5s;
-moz-animation-duration: 0.5s;
-ms-animation-duration: 0.5s;
@codescribblr
codescribblr / box_arrow.css
Created April 2, 2014 15:57
This css allows you to create an arrow off of a box element to give it the chat bubble effect.
.dropdown-menu {
top:90px;
left:30px;
padding:10px;
background-color: #ebebeb;
border: 1px solid #c4c4c4;
border-radius: 5px;
}
.dropdown-menu:before {
content: ' ';
//Convert start time from local time to GMT since WP Cron sends based on GMT
$start_time_gmt = strtotime( get_gmt_from_date( date( 'Y-m-d H:i:s', $start_time ) ) . ' GMT' );
//Set reminder time for three days before event start time
$time_prior_event = 3 * 24 * 60 * 60; //3 days * 24 hours * 60 minutes * 60 seconds
$reminder_time = $start_time_gmt - $time_prior_event;
//Remove existing cron event for this post if one exists
//We pass $post_id because cron event arguments are required to remove the scheduled event
wp_clear_scheduled_hook( 'wi_send_reminder_email', array( $post_id ) );
@codescribblr
codescribblr / modify_cron_schedules.php
Created March 17, 2014 16:23
Modifies cron schedule in Wordpress allowing you to add custom schedules. From http://wp.smashingmagazine.com/2013/10/16/schedule-events-using-wordpress-cron/
add_filter( 'cron_schedules', 'wi_add_weekly_schedule' );
function wi_add_weekly_schedule( $schedules ) {
$schedules['weekly'] = array(
'interval' => 7 * 24 * 60 * 60, //7 days * 24 hours * 60 minutes * 60 seconds
'display' => __( 'Once Weekly', 'my-plugin-domain' )
);
/*
You could add another schedule by creating an additional array element
$schedules['biweekly'] = array(
'interval' => 7 * 24 * 60 * 60 * 2
//On plugin activation schedule our daily database backup
register_activation_hook( __FILE__, 'wi_create_daily_backup_schedule' );
function wi_create_daily_backup_schedule(){
//Use wp_next_scheduled to check if the event is already scheduled
$timestamp = wp_next_scheduled( 'wi_create_daily_backup' );
//If $timestamp == false schedule daily backups since it hasn't been done previously
if( $timestamp == false ){
//Schedule the event for right now, then to repeat daily using the hook 'wi_create_daily_backup'
wp_schedule_event( time(), 'daily', 'wi_create_daily_backup' );