Skip to content

Instantly share code, notes, and snippets.

View gmaclennan's full-sized avatar

Gregor MacLennan gmaclennan

View GitHub Profile
@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 / map-tiles.md
Last active October 6, 2021 06:00
Ideas for an alternative to mbtiles for map tile storage

MBTiles (MapBox Tiles)

https://github.com/mapbox/mbtiles-spec

MBTiles is a specification for storing tiled map data in SQLite databases for immediate usage and for transfer.

MBTiles is a useful format for storing image and vector tilesets (used in "slippy-maps") on disk, and for transferring between devices for offline use.

MBTiles advantages

@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 / machine.js
Last active February 21, 2020 12:09
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@gmaclennan
gmaclennan / README.md
Last active June 21, 2019 14:57
Marker Dispersion

Uses d3-force to disperse overlapping markers on a mapbox-gl map.

Markers are tethered to their actual location, but have a collision force based on the radius of the icon. An additional force pulls icons towards their previous location (locations are calculated each time you move the map) to avoid markers jumping around excessively as they settle into different local minima on each re-draw.

@gmaclennan
gmaclennan / DISCUSSION.md
Created August 7, 2018 23:16
Ideas for a file format for mapeo sync

Problem

We want to be able to synchronize the data in mapeo-core to disk so that it can be transported via "sneakernet" to another device. This would most likely be on a USB flash drive, but could also be sent over email or a local bluetooth connection.

Currently safe-fs-blob-store - an implementation of abstract-blob-store - is used for storing media (attachments) in the mapeo-core database. On disk the blobs as stored as files and folders. This is potentially a problem for moving the archive around on disk because a user could easily, accidentally or intentionally, move files and folders and result in data loss and a corrupt database.

Requirements

Ideally we would have a single file containing all attachments and all database data that can be used to sync between machines.

@gmaclennan
gmaclennan / guyana-volunteer-wifi.md
Last active July 4, 2018 18:43
Long-distance solar-powered wifi in the forests and savannahs of Guyana

Overview

Digital Democracy is looking for a volunteer to help pilot long-distance solar-powered wifi antennaes in indigenous communities in Guyana.

Background

Digital Democracy is working with the Wapichan people in the South Rupununi in Guyana to support them in efforts to secure their ancestral territory and increase their autonomy and self-determination. The Wapichan live in 17 villages and 7 smaller "satellites" in a large semi-natural savannah ecosystem surrounded by tropical forest. Communication between villages and with the outside world is difficult due to limited or no cellphone or internet access. We want to help the Wapichan improve their means of communicating with the rest of the world and communicating and coordinating between villages.

Location

@gmaclennan
gmaclennan / example.js
Last active April 26, 2018 17:06
Adding layers to react-mapfilter
var LayerControl = require('@digidem/mapbox-layer-control')
var layerControl
var myControl = {
onAdd: function (map) {
var style = map.getStyle()
var layers = getLayersFromStyle(style)
layerControl = new LayerControl(layers)
return layerControl.onAdd(map)
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@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
}