Skip to content

Instantly share code, notes, and snippets.


Dave Shepard kynatro

View GitHub Profile
kynatro / ie.js
Last active August 29, 2015 14:04
100% Reliable no UserAgent, JavaScript IE Detection
View ie.js
// IE version detection - 100% reliable since it depends on IE unique functionality
var ie = (function(){
// IE <= 9
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
kynatro / prevent-scroll.js
Last active August 29, 2015 14:05
Prevent Window Scroll
View prevent-scroll.js
;(function($, window, undefined){
// Prevent scrolling on a page
$(window).on('mousewheel keydown', function(event){
// Un-comment to only prevent scrolling when an arbitrary global is true
// if(window.preventScroll) return;
// Only prevent default on specific key presses (pageup, pagedown, end, home, left, up, right, down)
if(event.type == "keydown"){
if($.inArray(event.keyCode, [33, 34, 35, 36, 37, 38, 39, 40]) !== -1) event.preventDefault();
kynatro / cookies.js
Created September 29, 2014 17:23
Cookies as an Object (Major modern browsers and IE9+)
View cookies.js
document.cookie.split("; ").map(function(i){
return i.split("=");
}).reduce(function(o, v, i){
try {
o[v[0]] = JSON.parse(decodeURIComponent(v[1]));
} catch(e) {
o[v[0]] = decodeURIComponent(v[1]);
return o;
}, {});
kynatro / bootstrap-daterangepicker-initializer.js
Created March 13, 2015 16:31
Bootstrap Date-range Picker Initializer
View bootstrap-daterangepicker-initializer.js
* Simple initializer for bootstrap-daterangepicker.
* @copyright David Shepard 2015 (
* Abstracts the initialization requirements for Dan Grossman's bootstrap-daterangepicker
* ( This initializer needs Moment.js, jQuery, Bootstrap
* and the Bootstrap Date Range Picker libraries loaded to operate.
* To take advantage of this script, just add [data-toggle="daterangepicker"] to any element
kynatro / gist:8151845
Created December 27, 2013 19:56
Strip tags from string RegExp
View gist:8151845
kynatro / slugify.js
Last active January 1, 2016 13:39
Slugify phrases/camel-case
View slugify.js
function slugify(str){
return str.replace(/[^\w\d\s\-]+/g, "") // Strip invalid characters
.replace(/_+/g, "-") // Replace _ with -
.replace(/^[\s|\-]+|[\s|\-]+$/, "") // Trim whitespace
.replace(/(\s+)/g, ",") // Replace spaces with , for spliting
.replace(/([A-Z]+)/g, ",$1") // Add , between capitals for splitting
.replace(/^,/, "") // Trim off the first comma if one was added
.split(",") // Split it apart
.join("-") // Put it together
.replace(/-+/g, "-") // Get rid of serial -
kynatro / .editorconfig
Created June 15, 2016 04:34
Editor Config Example
View .editorconfig
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
kynatro /
Last active July 20, 2016 18:50
WordPress Upload Import

Import images from an old WordPress blog to a new server (or local environment)! This simple script uses wget to download the file and place it in a corresponding local wp-content/uploads folder.

Wait, but why?

WordPress' import script is really dumb when it comes to images - even if you have the box checked to "download and import attachments", it won't actually download any images placed in your post content. This script does the download portion, but and you'll need to update the database separately.


  1. Update the urls array with your list of URLs
  2. Execute the script from your WordPress root: ruby import-wp-uploads.rb
kynatro /
Last active November 23, 2016 22:42
Middleman Embedded SVG Ruby Helper

Embedded SVG Helper

A simple helper function that makes inline SVG embedding simple! Just add the asset_helpers.rb file to your Middleman project's helpers folder and it will automatically be loaded and made available to you in your templates. From there, simply call:

<%= embedded_svg("my-asset.svg") %>

And your SVG asset content will be embedded inline in your template. You can also pass the following options to the helper to add additional attributes to the SVG tag itself:

kynatro / app.jsx
Last active January 17, 2017 03:39
React + Redux Contrived Primer
View app.jsx
// Destructure the Provider component and connect method from the
// react-redux module. The component wraps your React application in
// the code necessary to work properly with state and prop updates
// from Redux. The connect method allows you to connect individual
// React components to Redux for Redux store to prop mapping.
import { Provider, connect } from 'react-redux'
// Destructure the createStore method from the core redux module
// This method allows you to create your global store to house all your
// state values and your reducers to update state values
import { createStore } from 'redux'