Skip to content

Instantly share code, notes, and snippets.

@kynatro
kynatro / .editorconfig
Created June 15, 2016 04:34
Editor Config Example
[*]
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
@kynatro
kynatro / params.js
Last active August 9, 2018 20:47
URL Parameters as an object
// Could be any query string
var parameters = document.location.search;
var parametersObject = parameters
// Skip the "?" at the beginning of the string
.substr(1)
// Split into an array of individual parameters
.split("&")
// Split each parameter into an array of its key and value
.map(function(a){
@kynatro
kynatro / nginx.conf
Created June 1, 2015 16:22
nginx web font Content-Type specifications
location ~* \.(woff)$ {
add_header Content-Type "application/font-woff";
}
location ~* \.(otf)$ {
add_header Content-Type "application/font-sfnt";
}
location ~* \.(eot)$ {
add_header Content-Type "application/vnd.ms-fontobject";
}
location ~* \.(ttf)$ {
@kynatro
kynatro / bootstrap-daterangepicker-initializer.js
Created March 13, 2015 16:31
Bootstrap Date-range Picker Initializer
/**
* Simple initializer for bootstrap-daterangepicker.
*
* @copyright David Shepard 2015 (http://github.com/kynatro)
*
* Abstracts the initialization requirements for Dan Grossman's bootstrap-daterangepicker
* (http://www.daterangepicker.com/). 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
kynatro / cookies.js
Created September 29, 2014 17:23
Cookies as an Object (Major modern browsers and IE9+)
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
kynatro / prevent-scroll.js
Last active August 29, 2015 14:05
Prevent Window Scroll
;(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
kynatro / ie.js
Last active August 29, 2015 14:04
100% Reliable no UserAgent, JavaScript IE Detection
// 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]-->',
all[0]
@kynatro
kynatro / slugify.js
Last active January 1, 2016 13:39
Slugify phrases/camel-case
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
kynatro / gist:8151845
Created December 27, 2013 19:56
Strip tags from string RegExp
OriginalString.replace(/(<([^>]+)>)/ig,"")