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 / Timer.js
Created February 20, 2014 16:37
Timer.js - create a ticking timer like a digital clock. Code is still a little ad-hoc, but it is fully functional.
/*
Timer
@author Kevin Jantzer
@since 2013-11-27
*/
var Timer = function(opts){
@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 / 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 / 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 / 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 / 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 / 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 / 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 / README.md
Last active August 29, 2015 14:15
Backbone.js Attachment Uploader

The script uses Backbone Modal to display spinners and alerts

You must update apiURL to reflect your internal upload api.

If you wish to use the useImgur option, make sure to set imgurClientID (get it here http://api.imgur.com/)

Use:

var attachment = new Attachment({el: yourElement})
attachment.on('upload:success', function(resp, file, xhttp){
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management