Skip to content

Instantly share code, notes, and snippets.

View kdimatteo's full-sized avatar

Keith DiMatteo kdimatteo

View GitHub Profile
@kdimatteo
kdimatteo / gist:eeed7a8788c1544e72aa
Created October 22, 2014 17:10
Disallow force pushing to master
#!/bin/bash
# this file is ./git/hooks/pre-push
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo "y u do this? (You can not push to master)"
exit 1;
@kdimatteo
kdimatteo / gist:583927025c9197ace2fe
Created August 13, 2014 19:05
whats my ip address
curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
@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)){
/**
* 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 / 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');
@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 / 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 / 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: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: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