Skip to content

Instantly share code, notes, and snippets.

View DanElliottPalmer's full-sized avatar
😶‍🌫️

Dan Palmer DanElliottPalmer

😶‍🌫️
View GitHub Profile
@DanElliottPalmer
DanElliottPalmer / gist:4483297
Last active December 10, 2015 19:48
Bumped into a problem with IE9 not being able to use appendChild() on the body. This little snippet helped fix it.
var fnAppendToBody = (function(){
var domBody = document.body;
try {
var d = document.createElement('div');
domBody.appendChild( d );
d.parentNode.removeChild( d );
} catch(e) {
domBody = document.documentElement.getElementsByTagName('body')[0];
@DanElliottPalmer
DanElliottPalmer / gist:5200778
Created March 19, 2013 22:35
Device orientation with Euler angles
<div class="label">Heading: <strong id="lblHeading">0</strong></div>
<div class="label">Attitude: <strong id="lblAttitude">0</strong></div>
<div class="label">Bank: <strong id="lblBank">0</strong></div>
<script type="text/javascript">
@DanElliottPalmer
DanElliottPalmer / gist:5252996
Created March 27, 2013 09:35
Check if we can use Google Earth plugin
//Check if Google API script is installed and
//check if Google Earth namespaace is there
if(!google || !google.earth){
return false;
}
//Check if plugin is supported or installed
if(!google.earth.isSupported() || !google.earth.isInstalled()){
return false;
}
//We can use it
@DanElliottPalmer
DanElliottPalmer / gist:5253015
Created March 27, 2013 09:39
Raphael - Animate a path being drawn. Example of usage at the bottom.
function AnimatePathString() {
this._ = {
"animating": false,
"tmrID": null
};
if (arguments.length >= 3) {
this.start.apply(this, arguments);
}
}
@DanElliottPalmer
DanElliottPalmer / CanvasPath.html
Created July 28, 2013 13:03
Trying to whip up an SVG path to canvas renderer. This version is fully tested and there are probably performance issues but it kind of works? JS bin example: http://jsbin.com/awepam/1/edit
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class=""> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
@DanElliottPalmer
DanElliottPalmer / ie-version.js
Created December 12, 2013 15:04
Detect IE in javascript Had issues with a CMS I use removing conditional statements in the page so figured this would be a way if I ever need to do it again. Taken from: http://abbett.org/post/a-guide-to-building-webapps-with-ie8-support
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
@DanElliottPalmer
DanElliottPalmer / index.html
Last active October 2, 2015 15:21
Image resize based on landscape proportions - http://jsbin.com/tigaw/2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h3>Landscape correct proportions</h3>
<div class="image__panel">
@DanElliottPalmer
DanElliottPalmer / gist:aa22a3c038d5f2ef94d2
Last active August 29, 2015 14:17
ES6 Map inheritance
/**
* I can do this
*/
function AwesomeArray(){
Array.call( this );
}
AwesomeArray.prototype = Object.create(Array.prototype);
var awesomeness = new AwesomeArray();
awesomeness.push("example");
@DanElliottPalmer
DanElliottPalmer / gist:6ed1b0534c8e15f1ea2e
Last active August 29, 2015 14:17
ValidatedMap - Example of what I wanted to do following this curiosity: https://gist.github.com/DanElliottPalmer/aa22a3c038d5f2ef94d2
class ValidatedMap {
clear(){
this._.clear();
}
constructor( _validationRules, _defaultValues ){
let validationRules = _validationRules || null;
let defaultValues = _defaultValues || [];
this._ = new Map();
@DanElliottPalmer
DanElliottPalmer / arnie_quotes.json
Last active August 29, 2015 14:25
Arnold Schwarzenegger quotes
[
"Oh, cookies! I can't wait to toss them.",
"I've seen a lot, but nothing would ever make me cut out my tongue.",
"If you yield only to a conqueror, then prepared to be conquered.",
"Why don't they just call him Girl George?",
"Can you hurry up. My horse is getting tired.",
"You've seen those movies where they say \"Make my day.\" or \"I'm your worst nightmare.\", well listen to this one. Rubber Baby Buggy Bumpers!",
"What killed the dinosaurs? The Ice Age!",
"If you drop your gun now, I promise I won't kill you.",
"That's for sleeping with my wife!",