Skip to content

Instantly share code, notes, and snippets.

View kjantzer's full-sized avatar
👨‍💻
Likely writing JavaScript

Kevin Jantzer kjantzer

👨‍💻
Likely writing JavaScript
View GitHub Profile
@kjantzer
kjantzer / backbone.getOrFetch.js
Last active August 29, 2015 14:12
Backbone Get or Fetch method
Backbone.Collection.prototype.getOrCreate = function(id){
var model = this.get.apply(this, arguments)
// if no model, fetch and add the requested model
if( !model ){
id = id instanceof Backbone.Model ? id.id : id;
var ModelClass = this.model || Backbone.Model;
@kjantzer
kjantzer / git-subtree.md
Last active September 22, 2015 17:29
Git Subtree Tips
@kjantzer
kjantzer / og.php
Last active August 29, 2015 14:11
Wordpress: Open Graph Tags
/*
Open Graph Tags
@author Kevin Jantzer
@since 2014-12-13
orginal code: https://wordpress.org/plugins/facebook-featured-image-and-open-graph-meta-tags/
Info
- http://ogp.me/
@kjantzer
kjantzer / shortcode-youtube.css
Created December 13, 2014 18:36
WordPress: YouTube shortcode
// http://embedresponsively.com/
.embed-container {
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
max-width: 100%;
height: auto;
margin-bottom: 1.5em;
}
@kjantzer
kjantzer / smart_split.php
Last active August 29, 2015 14:11
SmartSplit - requires underscore.js
function smart_split($str){
$vals = array();
if( preg_match("/,/", $str) ) // comma delimited
$vals = explode(',', $str);
else if( preg_match("/\t/", $str) )
$vals = explode("\t", $str);
else
$vals = explode("\n", $str);
foreach($vals as &$val){ $val = trim($val); }
@kjantzer
kjantzer / get-img-lightness.js
Created September 4, 2014 18:47
Get the average lightness of an image or area of an image – 0 being dark, 255 being light.
/*
Get Image Lightness
@img (string|<img>) image src string or img element
@areas (null|array) array of @areas to profile
@area = [x, y, w, h]
@callback (fn) callback with the lightness values
EXAMPLES:
getImageLightness('img.jpg', [[x, y, w, h]], callback)
@kjantzer
kjantzer / commit-msgs-since-last-tag.sh
Created September 2, 2014 15:24
Get a compiled list of commit messages since the latest tag. Make sure to change the `GIT_ROOT` variable.
#!/bin/bash
GIT_ROOT='/Users/{username}/Sites/my-git-repo/'
cd $GIT_ROOT
LAST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo $LAST_TAG
@kjantzer
kjantzer / smartquotes.js
Last active August 29, 2015 14:04
Smart Quotes – changes straight double and single quotes to curly, double dashes to em-dashes, and triple periods to ellipsis.
// http://stackoverflow.com/a/14890774/484780
smartQuotes = function(str){
return str = (str||'').replace(/\b'\b/g, "\u2019") // apostrophes
.replace(/'(?=[^>]*<)\b/g, "\u2018") // Opening singles
.replace(/\b([\.\?\!,]*)(?=[^>]*<)'/g, "$1\u2019") // Closing singles
.replace(/"(?=[^>]*<)\b/g, "\u201c") // Opening doubles
.replace(/\b([\.\?\!,]*)(?=[^>]*<)"/g, "$1\u201d") // Closing doubles
.replace(/\.\.\./g, "\u2026") // ellipsis
.replace(/--/g, "\u2014") // em-dashes
}
@kjantzer
kjantzer / import-db.sh
Last active August 29, 2015 14:03
Remote MySQL Database Import
#!/bin/bash
# Import Live Database
#
# This bash script will import the live catalog database into your local catalog db.
# You can choose to only dump the table structure, all the data,
# or you can specify exactly which tables you wish to import.
#
# Simply run `bash import-live-db.sh` and you will be prompted with what to do
#
@kjantzer
kjantzer / remove-wp-admin-header.php
Last active May 29, 2019 19:21
Globally remove default WordPress Admin Header. Courtesy of David Walsh (http://davidwalsh.name/remove-wordpress-admin-bar-css)
add_action('get_header', 'remove_admin_login_header');
function remove_admin_login_header() {
remove_action('wp_head', '_admin_bar_bump_cb');
}