Skip to content

Instantly share code, notes, and snippets.

View richsilv's full-sized avatar

Richard Silverton richsilv

View GitHub Profile
@richsilv
richsilv / debounceWithArgs.js
Last active August 29, 2015 14:10
Mixin for Underscore.js to allow arguments to be passed with each function call. Designed for use with Meteor, but easy to use without either Meteor or Underscore.
// Underscore mixin to allow arguments to be passed to debounced functions.
// Useful for updating user doc on keyup (or similar) where doc update will invalidate
// many dependent computations, and so you only want to actually update it every so often.
// See below for example.
// Can also be used without Meteor (change Meteor.setTimeout to Timeout), and without
// underscore (just make debounceWithArgs a stand-alone function).
_.mixin({
debounceWithArgs: function(func, timeOutDuration) {
var timeOut,
@richsilv
richsilv / ReactiveObject.js
Last active August 29, 2015 14:10
Meteor Reactive Object
// initial - Initial value (must be an object)
// name - a name to help identify the object if you're using objectStore
// objectStore - a central store to push all initialised objects into (for debugging)
// maxInvalidate - the maximum number of times to invalidate computations which depend
// on this object. Avoids and helps diagnose infinite invalidation loops in testing.
//
// note that setting a sub-key on a key which is currently literal-valued will delete
// the existing value
ReactiveObject = function(initial, name, objectStore, maxInvalidate) {
@richsilv
richsilv / designer.html
Created November 2, 2014 17:43
designer
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../chart-js/chart-js.html">
<link rel="import" href="../paper-calculator/paper-calculator.html">
<link rel="import" href="../topeka-elements/avatars.html">
<link rel="import" href="../core-icon/core-icon.html">
<polymer-element name="my-element">
@richsilv
richsilv / MeteorSnippets.html
Last active August 29, 2015 14:02
Some simple utilities for interrogating a Meteor.js website in bookmarklet format.
javascript: (function() {
var getCollections = function() {
var collections = [];
for (var item in window) {
if (window[item] && window[item]['_collection']) collections.push(item);
}
return collections;
};
var getSubscriptions = function() {
var thisSub, subs = {};
@richsilv
richsilv / renderOnce.js
Last active August 29, 2015 13:56
A Meteor.js utility function to easily attach a function to a given template's "rendered" callback but only run it once, on the next render.
// Useful for occasions on which you know that an action will result in the re-rendering of a template
// (through invalidation) and you want to execute task(s) once the rendering is complete in response.
// Sometimes, you only need to execute these task(s) in response to that specific action, so it doesn't
// make sense to add the task(s) to the normal "rendered" callback and then test if they need to be executed
// every time the template is rendered.
renderOnce = function(template, oneTimeFunc, afterwards) {
// template: either a Meteor Template instance, or the string name of such an instance
// oneTimeFunc: the function you are attaching to the "rendered" callback to be run only once
// afterwards: set to true if you need the oneTimeFunc to be executed after the normal "rendered" callback,
// rather than before it
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh