Skip to content

Instantly share code, notes, and snippets.

View mrienstra's full-sized avatar

Michael Rienstra mrienstra

  • Olympic Peninsula, WA
View GitHub Profile
@mrienstra
mrienstra / README.md
Created February 2, 2012 22:09
Node.js 0.6.9: Notes on documentation for Cluster module.

I noticed that an example from the node.js documentation was behaving in an unexpected way. It is the second example for the Cluster module. You can see it on both of these pages:

First off, note that the nodemanual.org examples link to the Cloud9 IDE, which doesn't support the Cluster module -- it might be nice to note this to save a lot of people the trouble of finding it out for themselves.

The behavior I was seeing is that "numReqs" was increasing by 2: 0, 2, 4... instead of the expected 0, 1, 2...

On the node.js IRC channel, I was helped by bnoordhuis & AndreasMadsen.

@mrienstra
mrienstra / gist:1793969
Created February 10, 2012 23:27
First attempt at writing a .rst for three.js, in particular docs/api/renderers/CanvasRenderer.rst
CanvasRenderer - Renderer for Canvas
----------------------
.. ...............................................................................
.. rubric:: Constructor
.. ...............................................................................
.. class:: CanvasRenderer( parameters )
Renderer for Canvas
@mrienstra
mrienstra / director_example2.htm
Created February 17, 2012 21:26
Director Example #2
<!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:1905442
Created February 25, 2012 02:44 — forked from 4bu/gist:1472552
window.person = new Person;
var myCallback = function(personModel, enteredName) {
alert(‘Hello’ + enteredName);
};
person.bind('change:name', myCallback);
person.promptName();
@mrienstra
mrienstra / gist:1905551
Created February 25, 2012 02:57 — forked from 4bu/gist:1472559
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'));
}
});
@mrienstra
mrienstra / README
Created October 3, 2012 23:48
Demo of hacks to prevent scroll-triggered navigation
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
@mrienstra
mrienstra / Rearrange Desktop Icons.scpt
Last active January 11, 2024 15:51
Rearranges Desktop icons to flow from left to right, top to bottom.
-- 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).
/* ========================================================================
* 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)
* ======================================================================== */
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
}
};
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',
],