Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Rich-Harris / gh-pages.md
Created August 11, 2013 23:02
Automating gh-pages branch updating with changes to the master branch
steps from huge shape file to topo json:
topojson -q 1e3 --id-property ELECT_DIV national-esri-16122011/COM20111216_ELB_region.shp -o aussieMapTopoFromShp.json
/* -q 1e3 */ //This is the quality/simplification property, the lower the number the lower the quality
/* --id-property ELECT_DIV */ //This copies over the ELECT_DIV property from the shape file to the topoJSON file
//national-esri-16122011/COM20111216_ELB_region.shp //This is the input shape file
@Rich-Harris
Rich-Harris / throttle.js
Last active December 22, 2015 05:48
A throttling function
(function ( global ) {
'use strict';
var throttle;
if ( typeof Date.now !== 'function' ) {
Date.now = function () {
return new Date().getTime();
};
@Rich-Harris
Rich-Harris / svg.js
Created October 6, 2013 16:05
SVG utility
/*global define, document */
/*jslint white: true */
(function ( global ) {
'use strict';
var svg, trimWhitespace;
trimWhitespace = /\s+/g;
@Rich-Harris
Rich-Harris / makeObservable.js
Last active December 26, 2015 18:28
Utility for making observable objects
// Usage
// =====
//
// Create an observable object:
//
// obj = makeObservable();
// obj.set( 'foo', 'bar' );
//
// observer = obj.observe( 'foo', function ( newFoo, oldFoo ) {
// alert( 'foo changed from ' + oldFoo + ' to ' + newFoo ); // alerts 'foo changed from undefined to bar'
@Rich-Harris
Rich-Harris / numberRegex.js
Last active December 28, 2015 18:39
A regular expression that matches any legal JavaScript number, including weird edge cases. If you have a failing test case, let me know!
var pattern = /(?:[+-]?)0*(?:(?:(?:[1-9]\d*)?\.\d+)|(?:(?:0|[1-9]\d*)\.)|(?:0|[1-9]\d*))(?:[eE][+-]?\d+)?/;
var shouldPass = [
'0',
'00',
'000123',
'0.01',
'1',
'-0',
'+1',
@Rich-Harris
Rich-Harris / get.js
Created December 11, 2013 01:17
quick and dirty XHR helper
(function ( global ) {
'use strict';
var get;
get = function ( url, callback ) {
var xhr = new XMLHttpRequest();
xhr.open( 'GET', url );
@Rich-Harris
Rich-Harris / wrappedvalues.md
Last active January 1, 2016 08:29
An explanation of `wrapped.value` in Ractive adaptors

What is wrapper.value?

When using Ractive.js with adaptors, each 'wrappable' object (i.e. each object that passes the adaptor's filter() method) has a wrapper created:

ractive = new Ractive({
  el: 'body',
  template: '{{myModel.foo}}',
  data: {
    myModel: new Backbone.Model({ foo: 'bar' })
@Rich-Harris
Rich-Harris / computedValues.md
Created January 21, 2014 13:20
Computed values in Ractive

In response to this tweet:

There are a couple of ways to get computed values into a template. The first is to write the expression straight into a mustache tag - Ractive will pick out the references and recompute the value when necessary:

<p>Full name: {{ person.first + ' ' + person.last }}</p>

If you're doing more complex computation, you could also do it like this:

@Rich-Harris
Rich-Harris / gtfo.py
Last active August 29, 2015 13:56 — forked from wuub/gtfo.py
import sublime, sublime_plugin
BUILD_COLOR_SCHEME = "Packages/Color Scheme - Default/Dawn.tmTheme"
def in_build_dir(view):
if not view or not view.file_name():
return False
return "/build/" in view.file_name()