Skip to content

Instantly share code, notes, and snippets.

View jonathantneal's full-sized avatar

Jonathan Neal jonathantneal

View GitHub Profile
@jonathantneal
jonathantneal / cache.js
Created July 1, 2014 18:39
Load and cache scripts and styles with localStorage
(function (NAME, LISTENER, HEAD) {
window[NAME] = function (src, node, loading) {
var
// prepare cache
key = NAME + ':' + src,
cache = localStorage[key] || '',
name = parseFloat(cache[0]) ? 'script' : 'style',
x, xhr;
// if cache exists
@jonathantneal
jonathantneal / IndieAuth.svg
Created July 3, 2014 00:06
IndieAuth logo
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
(function (NAME, SEPARATOR) {
var
ATTR = 'data-' + NAME,
SELECTOR = '[' + ATTR + ']';
function onupdate() {
// for all matching elements
Array.prototype.forEach.call(document.querySelectorAll(SELECTOR), function (element) {
var
// get data from attribute
@jonathantneal
jonathantneal / README.md
Created July 6, 2014 19:12
IndieJS Idea

IndieJS

Make a cookie with the name indiejs and the value of a URL to your site’s IndieJS file. Remember, the JavaScript could be generated by any framework, even PHP.

<script>
function setIndieJS(src) {
	'indiejs=' + src + ';expires=Fri, 31 Dec 9999 23:59:59 GMT;path=/';
}
@jonathantneal
jonathantneal / README.md
Created July 9, 2014 20:18
Local Phorkie Setup for Mac OSX

Local Phorkie Setup for Mac OSX

These instructions are intended to be used on Mac OSX Mountain Lion and Mavericks. They may also work for Yosemite, but have not been tested.


Installing Phorkie

This step copies Phorkie to your local Sites directory.

<!doctype html>
<title>scale</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
body { margin: 10em auto; max-width: 640px; }
#image { display: block; height: 0; overflow: hidden; padding-bottom: 75%; position: relative; }
#image { background-color: #999; border-radius: 5px; box-shadow: 0 0 0 10px #777; }
(function (toString, getArgsRe, splitArgsRe) {
Function.prototype.getArguments = function () {
return toString.call(this).match(getArgsRe)[1].split(splitArgsRe);
};
})(String.prototype.toString, /\(([^)]+)/, /\s*,\s*/);
@jonathantneal
jonathantneal / README.md
Last active August 29, 2015 14:05
Position Queries

Position Queries

A position query is a simple expression used to filter elements by their position on the screen.

An expression is made up of a property and a value. The property describes the measured edge of the element by using top, bottom, left, or right. The value describes the measured edge and position of the screen by adding before or after.

For example, the following query checks if the element is above the screen. It does this by checking if the bottom of the element comes before the top of the screen.

@jonathantneal
jonathantneal / EventStreams.example.js
Last active August 29, 2015 14:07
EventStreams example
// http://www.xanthir.com/b4PV0
var ctrlKeyStream = EventStream.listen(document, 'keydown').map(function (event) {
return event.ctrlKey;
});
ctrlKeyStream.forEach(function (event) {
// do something when a key down event fires that involves the CTRL key being pressed
});
@jonathantneal
jonathantneal / tests.js
Created November 8, 2014 22:58
Promise tests
it('has correct instance', function () {
expect(Promise).to.be.a(Function);
});
it('has correct argument length', function () {
expect(Promise.length).to.be(1);
});
describe('Section 2.1.2.1: When fulfilled, a promise: must not transition to any other state.', function () {
var promise, deferred;