Skip to content

Instantly share code, notes, and snippets.

View gmaclennan's full-sized avatar

Gregor MacLennan gmaclennan

View GitHub Profile
@gmaclennan
gmaclennan / gist:8610640
Last active January 4, 2016 10:39
Google Sheets update cell value from cell colour (hex code)
// Will update the value of the cell to the hex value of the color of the cell
// It is triggered by typing a "#" into the cell
// Unfortunately changing the color of a cell does not trigger an edit event in sheets
// Will not work in the new version of Google Sheets
function onEdit(e) {
var cell, value;
var values = e.range.getValues();
for (var i=0; i < values.length; i++) {
@gmaclennan
gmaclennan / README.md
Last active February 27, 2023 01:03
Fast long scrolling image grid

This is an implementation of a long-scrolling image grid. You should be able to smoothly scroll through 500,000 images from Flickr (you will see repeats because flickr only returns 4,000 images from a search). The images will delay when first loading, but once your browser has cached the images scrolling should be pretty smooth.

The trick to keeping it smooth is by only modifying CSS properties that are cheap to animate and by minimizing modifications to the DOM by reusing our exit nodes as enter nodes.

A full page of images (the same height as window height) is rendered above and below the viewable area. In addition, empty rows with a placeholder background are padded around for an additional 2 x window height. This is useful for mobile, which will not fire a scroll event until you stop scrolling.

@gmaclennan
gmaclennan / README.md
Last active May 4, 2020 21:55 — forked from gmaclennan/README.md
Long-scrolling image grid

This is an implementation of a long-scrolling image grid. You should be able to smoothly scroll through 500,000 images from Flickr (you will see repeats because flickr only returns 4,000 images from a search). The images will delay when first loading, but once your browser has cached the images scrolling should be pretty smooth.

The trick to keeping it smooth is by only modifying CSS properties that are cheap to animate and by minimizing modifications to the DOM by reusing our exit nodes as enter nodes.

A full page of images (the same height as window height) is rendered above and below the viewable area. In addition, empty rows with a placeholder background are padded around for an additional 2 x window height. This is useful for mobile, which will not fire a scroll event until you stop scrolling.

@gmaclennan
gmaclennan / variance.js
Last active March 2, 2018 13:17
Running variance Welford method
// See http://www.johndcook.com/blog/standard_deviation/
function varianceReduce (p, x, i) {
p.mean = isNaN(p.mean) ? 0 : p.mean
var mean = p.mean + (x - p.mean) / (i + 1)
var vari = i < 1 ? 0 : (p.vari * i + (x - p.mean) * (x - mean)) / (i + 1)
return {
mean: mean,
vari: vari
}
@gmaclennan
gmaclennan / open-file.js
Created December 3, 2016 21:37
React Drag and Drop example
const React = require('react')
const dragDrop = require('drag-drop')
const RaisedButton = require('material-ui/RaisedButton').default
const fileExtension = require('file-extension')
const blobToBuffer = require('blob-to-buffer')
const { connect } = require('react-redux')
const {replaceFeatures} = require('../action_creators')
const styles = {
@gmaclennan
gmaclennan / babel-plugin-insert-css.js
Created December 12, 2016 03:58
Insert css with a babel plugin
var resolve = require('resolve').sync
var nodePath = require('path')
var fs = require('fs')
var rework = require('rework')
var reworkImport = require('rework-import')
module.exports = function ({types: t}) {
return {
visitor: {
CallExpression: function (path, state) {
@gmaclennan
gmaclennan / multipolygon.geojson
Created January 13, 2017 13:18
OSM XML Polygon from relation example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gmaclennan
gmaclennan / connected-line-fixture.geojson
Last active January 21, 2017 20:50
Dissolve connected GeoJSON LineStrings
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am gmaclennan on github.
  • I am gmaclennan (https://keybase.io/gmaclennan) on keybase.
  • I have a public key ASBkNcWJZSORRsuupjzXIeg2sMS2fE_Kou6h5fEc5_UAGwo

To claim this, I am signing this object: