Skip to content

Instantly share code, notes, and snippets.

View richsilv's full-sized avatar

Richard Silverton richsilv

View GitHub Profile
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
@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
@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 / 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 / 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 / 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 / methods.js
Last active August 29, 2015 14:13
Demo of the difference in `this` in Meteor methods depending on whether the call was from client or server
var calledFromServer;
Meteor.methods({
'getThis': function() {
return this;
},
'getThisServer': function() {
return calledFromServer;
}
@richsilv
richsilv / generateNINO.js
Last active August 29, 2015 14:18
National Insurance Number generator
function generateNINO(style) {
var group1 = '';
var group2 = '';
var group3 = '';
var group4 = '';
var group5 = '';
var randomArrayIndex = '';
var notAllowed = new Array('GB', 'BG', 'NK', 'KN', 'TN', 'NT', 'ZZ');
var firstAllowed = new Array('A', 'B', 'C', 'E', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z');
var secondAllowed = new Array('A', 'B', 'C', 'E', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z');
@richsilv
richsilv / randomCode.js
Last active August 29, 2015 14:18
Random code generator (numbers and letters) of prescribed format (e.g. Postcode, NI number)
var randomLetter = function() {return String.fromCharCode(Math.floor(Math.random()*26) + 65);}
var randomNumber = function() {return String.fromCharCode(Math.floor(Math.random()*10) + 48);};
var genDict = {
'l': randomLetter,
'n': randomNumber
};
// pass in a format string of the type: "4l 3n 2l", i.e. a space-delimited set of number/letter
// pairs, the first of which gives the number of characters of the given type and the second
// denotes the type: "n" for number, "l" for letter (always upper-case).