Skip to content

Instantly share code, notes, and snippets.

View kdimatteo's full-sized avatar

Keith DiMatteo kdimatteo

View GitHub Profile
@kdimatteo
kdimatteo / datepicker.js
Created June 4, 2013 17:43
Backbone-Forms implementation of Bootstrap DatePicker
/**
* Bootstrap Datepicker
*
* Quick editor to create a Bootstrap style datepicker (instead of multiple of dropdowns)
* @see: https://github.com/eternicode/bootstrap-datepicker/
* @usage: takes 2 schema options, dateFormat and defaultValue
schema: {
MyDate: {
@kdimatteo
kdimatteo / String Truncate
Created October 25, 2013 15:20
Truncate a string without spitting on a word, and without any trailing punctuation from the original string. (PHP)
function str_truncate($string, $length) {
$bogus = array(",", ".", "?", "!", ";", "/", "$", "%", "*", "&", "#", "+", "=");
if (strlen($string) > $length) {
$string = substr($string, 0, ($length -3));
$string = substr($string, 0, strrpos($string, ' '));
if(in_array(substr($string, -1), $bogus)){
$string = substr($string, 0, strlen($string)-1);
}
$string .= "...";
}
@kdimatteo
kdimatteo / gist:7239451
Last active December 27, 2015 00:39
Apache: Force IE out of compatibility mode from the server
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge"
# "mod_headers" can't match based on the content-type, however, we only
# want to send this header for HTML pages and not for the other resources
<FilesMatch "\.(appcache|crx|css|cur|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svgz?|ttf|vcf|webapp|webm|webp|woff|xml|xpi)$">
Header unset X-UA-Compatible
@kdimatteo
kdimatteo / gist:7378000
Created November 8, 2013 21:30
IIS: Force IE out of compatibility mode
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=10" />
</customHeaders>
</httpProtocol>
</system.webServer>
@kdimatteo
kdimatteo / gist:7378011
Created November 8, 2013 21:31
PHP: force IE out of compatibility mode
header('X-UA-Compatible: IE=edge,chrome=1');
@kdimatteo
kdimatteo / gist:8228162
Last active February 17, 2017 12:02
JS Math.fastCeil for performance
/**
* 90% faster that native Math.ceil()
* http://jsperf.com/math-ceil-v-math-fastceil
*/
Math.fastCeil = function (n) {
var t = ~~n;
return t === n ? n : (n > 0) ? (t + 1) : (t - 1)
};
@kdimatteo
kdimatteo / postMessage-xdomain.js
Created January 17, 2014 19:47
Cross-Frame & Cross-Domain with postMessage
/**
* parent document (e.g., modal containing an iframe tag)
*/
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
// Listen to message from child window
@kdimatteo
kdimatteo / warn on max chars
Last active August 29, 2015 13:57
Warn if an input's length is close to it's max
// bind the listener and config via data-attributes
// <textarea data-maxwarn="true" data-maxchars="20" data-warnclass='too-many-characters'></textarea>
$(document).on('keyup', '[data-maxwarn=true]', function(e){
var tf = $(e.target);
var max = tf.data('maxchars');
if(tf.val().length > max - 10){
tf.data('hitmax', 'true');
/**
* Enable route to __noSuchMethod__ when unknown method calling.
*
* @param {Object} obj Target object.
* @return {Object}
*/
function enableMethodMissing(obj) {
var functionHandler = createBaseHandler({});
functionHandler.get = function(receiver, name) {
@kdimatteo
kdimatteo / gist:10985171
Created April 17, 2014 13:53
Ember Image Cache with ActiveModelSerializer
//todo: memory hit with this loop?
//todo: check for valid file names (or use a "cacheThisKey" setting in the model?)
DS.ActiveModelSerializer.reopen({
createImageCaches: function(hash){
window.imageCache = window.imageCache || [];
var imageKeys = ['url', 'photo_url', 'image_url', 'image'];
for(var k in hash){
if(imageKeys.contains(k)){