Skip to content

Instantly share code, notes, and snippets.

@codyogden
codyogden / distance-query
Created May 25, 2016 11:19
A hacked together query for finding nearest locations in a database. :oldlat & :oldlng are the center point, :dist is number of miles from center point.
SELECT *, ( 3959 * acos( cos( radians( :oldlat ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( :oldlng ) ) + sin( radians(:oldlat) ) * sin( radians( latitude ) ) ) ) AS distance FROM agency HAVING distance < :dist ORDER BY distance LIMIT :numb
/* jQuery plugin that tells if the element is in the viewport */
$.fn.inVP = function(){
var element = this.get(0);
var bounds = element.getBoundingClientRect();
return bounds.top < window.innerHeight && bounds.bottom > 0;
}
@codyogden
codyogden / USD-currency-locales.js
Last active August 30, 2016 13:05
USD Currency Locale Functions
// Show two decimal places, returns a string
VARIABLE.toFixed(2);
// Show as USD Currency
VARIABLE.toLocaleString( 'USD', { style: 'currency', currency: 'USD' } );
// Show as USD Currency with commas
VARIABLE.toLocaleString( 'en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 } );
// Hi matt!
@codyogden
codyogden / ready.js
Created August 30, 2016 15:44
ready() - You Might Not Need jQuery
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
@codyogden
codyogden / wp-theme-header.css
Last active April 20, 2018 18:17
WordPress Theme Header (CSS)
/*!
Theme Name: Starter Theme
Theme URI: https://starter.codyogden.com
Author: Cody Ogden
Author URI: https://codyogden.com
Description: A custom starter theme for WordPress.
Version: 0.0.1
License: MIT
Tags: one-column, two-column, accessibility
Text Domain: starter
@codyogden
codyogden / wp-plugin-header.php
Last active April 28, 2017 15:34
WordPress Plugin Header
<?php
/*
Plugin Name: Spalon Staff Plugin
Plugin URI: https://spalon.com
Description: A plugin to handle Spalon Montage staff profiles.
Version: 0.0.1
Author: Brandography
Author URI: https://brandography.com
Text Domain: spalon-staff
*/
@codyogden
codyogden / countItemInOjbect.js
Last active September 2, 2016 22:06
Return count of objects in array with a specific key & value.
var countItemInObject = function ( arr, item, search ) {
return arr.filter(function( obj ){
return obj[item] === search;
}).length;
};
@codyogden
codyogden / drawer-click-logic.js
Created September 3, 2016 20:00
jQuery logic for a menu drawer to slide in and slide out, if click outside of the drawer, it will slide out. (Uses CSS3 Trnsition / Classes)
// When the hamburger is clicked
$("MENUICON").on("click", function() {
// Add the show class to the menu
$("DRAWER").addClass("show");
// Add one event listener
$("DRAWER").one("mouseleave", function() {
// When the mouse leaves
@codyogden
codyogden / client-server-data-structure.js
Last active September 21, 2016 21:44
For a group project at Prime.
{
action: "start"
}
// Send back a true/false that a number is generated and the server is ready to play.
// What Client sends to server
{
action: "guess",

Keybase proof

I hereby claim:

  • I am codyogden on github.
  • I am codyogden (https://keybase.io/codyogden) on keybase.
  • I have a public key ASBe05VfUzPnzE2gQV2rT08JtPGW8JCGr1dl9ODvsHwsBQo

To claim this, I am signing this object: