Skip to content

Instantly share code, notes, and snippets.

Avatar

James Musgrave jamesmusgrave

View GitHub Profile
View FloydSteinberg.html
<html>
<head>
<title>Dithering Test</title>
</head>
<body>
<canvas></canvas>
<script>
var canvas = document.getElementsByTagName("canvas")[0];
@jamesmusgrave
jamesmusgrave / widowFix.js
Created Nov 12, 2014
Angular Widow Fix Filter
View widowFix.js
(function() {
'use strict';
angular.module('webApp.filters')
.filter('widowFix', function() {
return function(input) {
if (input !== undefined) {
var wrapper= document.createElement('div');
View useful-terminal-commands.sh
#Fix a folder made as root
sudo chown -R $(whoami) .
#List files in single column
ls -R -1 .
@jamesmusgrave
jamesmusgrave / cachedjson.js
Last active Dec 27, 2015 — forked from kpuputti/gist:1040118
Cached JSON via jQuery
View cachedjson.js
var getCachedJSON = function (url) {
var deferred = new $.Deferred();
var cachedData = window.localStorage[url];
if (cachedData) {
log('Data already cached, returning from cache:', url);
deferred.resolve(JSON.parse(cachedData));
} else {
$.getJSON(url, function(data) {
log('Fetched data, saving to cache:', url);
window.localStorage[url] = JSON.stringify(data);
@jamesmusgrave
jamesmusgrave / pre-commit.sample
Last active Jan 3, 2016
Grunt on pre-commit
View pre-commit.sample
#!/bin/sh
# Pre-commit file needs to be executable so first
# chmod +x .git/hooks/pre-commit
# Fix your grunt path
PATH="/usr/local/bin:$PATH"
# Runs grunt default
echo "Running Grunt..."
View datewithtimezone.js
Date.prototype.stdTimezoneOffset = function() {
var jan = new Date(this.getFullYear(), 0, 1);
var jul = new Date(this.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
Date.prototype.dst = function() {
return this.getTimezoneOffset() < this.stdTimezoneOffset();
}
View iOS-iFrame fix
html,
body,
#doc {
height: 100%; // Passes through the height of the parent iframe element
}
#doc {
// Magic to prevent iOS growing the iFrame to fit the content.
// This container will mimic the behavior of the iframe on a desktop browser
-webkit-overflow-scrolling:touch;
overflow-y: scroll;
View easing.js
if ( settings.easing === 'easeInQuad' ) pattern = time * time; // accelerating from zero velocity
if ( settings.easing === 'easeOutQuad' ) pattern = time * (2 - time); // decelerating to zero velocity
if ( settings.easing === 'easeInOutQuad' ) pattern = time < 0.5 ? 2 * time * time : -1 + (4 - 2 * time) * time; // acceleration until halfway, then deceleration
if ( settings.easing === 'easeInCubic' ) pattern = time * time * time; // accelerating from zero velocity
if ( settings.easing === 'easeOutCubic' ) pattern = (--time) * time * time + 1; // decelerating to zero velocity
if ( settings.easing === 'easeInOutCubic' ) pattern = time < 0.5 ? 4 * time * time * time : (time - 1) * (2 * time - 2) * (2 * time - 2) + 1; // acceleration until halfway, then deceleration
if ( settings.easing === 'easeInQuart' ) pattern = time * time * time * time; // accelerating from zero velocity
if ( settings.easing === 'easeOutQuart' ) pattern = 1 - (--time) * time * time * time; // decelerating to zero velocity
if ( settings.easin
View mysqlbackup.sh
#!/bin/bash
function backupdb {
USER=$1
PASSWORD=$2
REMOTEIP=$3
OUTPUTDIR="/Volumes/Backup/MYSQL/$(date +%F)"
MYSQLDUMP="/usr/local/bin/mysqldump"
MYSQL="/usr/local/bin/mysql"