Skip to content

Instantly share code, notes, and snippets.

Michael Rienstra mrienstra

Block or report user

Report or block mrienstra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mrienstra
mrienstra / unregisterServiceWorkers.js
Created Feb 4, 2018
Unregister service workers, verbose
View unregisterServiceWorkers.js
navigator.serviceWorker.getRegistrations().then(function (registrations) {
if (!registrations.length) {
console.log('No serviceWorker registrations found.')
return
}
for(let registration of registrations) {
registration.unregister().then(function (boolean) {
console.log(
(boolean ? 'Successfully unregistered' : 'Failed to unregister'), 'ServiceWorkerRegistration\n' +
(registration.installing ? ' .installing.scriptURL = ' + registration.installing.scriptURL + '\n' : '') +
View export_postprocess.js
const replace = require('replace-in-file'); // https://www.npmjs.com/package/replace-in-file
const path = require('path');
const scriptName = path.basename(process.argv[1]);
const options = {
files: [
'out/*.html',
'out/**/*.html',
],
View script_tag.js
window.Attribution = window.Attribution || [];
window.Attribution.methods = ["trackSubmit", "trackClick", "trackLink", "trackForm", "pageview", "identify", "group", "track", "ready", "alias", "page", "once", "off", "on"];
window.Attribution.factory = function(e) {
return function() {
var t = Array.prototype.slice.call(arguments);
t.unshift(e);
window.Attribution.push(t);
return window.Attribution
}
};
View ratchetSliderSetPage.js
/* ========================================================================
* ratchetSliderSetPage
* ========================================================================
* Compatible with gh:twbs/ratchet v2.0.2
* https://github.com/twbs/ratchet/blob/v2.0.2/js/sliders.js
* http://goratchet.com/components/#sliders
* Licensed under MIT (https://github.com/twbs/ratchet/blob/master/LICENSE)
* ======================================================================== */
@mrienstra
mrienstra / Rearrange Desktop Icons.scpt
Last active Aug 11, 2019
Rearranges Desktop icons to flow from left to right, top to bottom.
View Rearrange Desktop Icons.scpt
-- https://gist.github.com/mrienstra/8330528
-- Based on http://www.tuaw.com/2012/12/24/applescript-desktop-icon-race/
-- Inspired by http://namesakecomic.com/comic/happy-new-year-from-namesake/#comment-1182035013
-- Rearranges Desktop icons to flow from left to right, top to bottom.
-- To have this run automatically every time files are added or removed from the Desktop, set this script to run as a Desktop "Folder Action". (See https://developer.apple.com/library/mac/documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_folder_actions.html )
-- This is currently a rough proof-of-concept. It has only been tested with OS X 10.8.5 (Mountain Lion).
@mrienstra
mrienstra / README
Created Oct 3, 2012
Demo of hacks to prevent scroll-triggered navigation
View README
The first approach use several layers. It takes advantage of the fact that you cannot trigger a "back" unless BODY's "scrollLeft" is 0. The disadvantage to this approach is the appearance of an additional horizontal scrollbar. There may also be some subtle side-effects to using "position: fixed".
1. The HTML element acts as a container for the BODY element, and uses "overflow: scroll".
2. The BODY element is 2 pixels wider than the page, so it can scroll 1px in either direction when its "scrollLeft" is 1 (neutral position).
3. We bind to the "onscroll" event of the window, and reset BODY's "scrollLeft" to 1.
4. The content is inside a DIV, which uses "position: fixed" so it doesn't jump around when the BODY is scrolling.
The second approach uses the hash / history stack. Rather than trying to stop a "back" or "forward", we simply "buffer" the history stack so that we can detect any changes and return to our neutral position.
1. When we load the page, we change the hash to "#previous", then "#neutral", then
View gist:1905551
var PersonModel = Backbone.Model.extend();
var PersonView = Backbone.View.extend({
initialize: function () {
this.model.bind('change:name', _.bind(this.render, this));
},
render: function () {
$('body').html(this.model.get('name'));
}
});
View gist:1905442
window.person = new Person;
var myCallback = function(personModel, enteredName) {
alert(‘Hello’ + enteredName);
};
person.bind('change:name', myCallback);
person.promptName();
View director_example2.htm
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A Gentle Introduction 2</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://raw.github.com/flatiron/director/master/build/director-1.0.7.min.js"></script>
<script>
$('document').ready(function(){
//
@mrienstra
mrienstra / gist:1793969
Created Feb 10, 2012
First attempt at writing a .rst for three.js, in particular docs/api/renderers/CanvasRenderer.rst
View gist:1793969
CanvasRenderer - Renderer for Canvas
----------------------
.. ...............................................................................
.. rubric:: Constructor
.. ...............................................................................
.. class:: CanvasRenderer( parameters )
Renderer for Canvas
You can’t perform that action at this time.