Skip to content

Instantly share code, notes, and snippets.

View adregan's full-sized avatar
🛶
My other car is a canoe

Duncan Regan adregan

🛶
My other car is a canoe
View GitHub Profile
const range = (start = 0, end = undefined, skip = 1) => {
if (!end) [end, start] = [start, 0];
if (start >= end) return [];
return {
[Symbol.iterator]: function* () {
yield start;
while (start < end - skip) yield start += skip;
},
toArray () {

Doin' things with service workers

  • Service workers are about giving web sites more abilities in order to operate like apps
  • Big features of service workers: proxying requests / caching, receiving push notifications
  • wrt. caching, most online tutorials focus solely on this feature. We won't spend time on it beyond a high level overview of how it works and why it's different from browser caching (diagram of how sw can intercept fetch requests. Could even demo)
  • The more interesting feature is the ability to register for and receive push notifications, even when the page is closed
  • Push notifictions can allow the app to update behind the scenes
  • Do you stash the new data in IndexedDB and on initialization of the page send a message? Or can we do something different?
  • Can we put the application store in the service worker?
  • Intro to sw-redux https://github.com/adregan/sw-redux
/*
* I add this to html files generated with pandoc.
*/
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
@adregan
adregan / range.js
Last active November 28, 2016 23:13
/**
* The range utility works like the range included in Python 3. It either takes:
* - a single number representing the stop value (implicitly starting at 0)
* - 2 numbers representing the start and stop values
* - 3 numbers representing the start, stop, and step values
*
* @see https://docs.python.org/3/library/stdtypes.html#range
*
* @param {number} [start=0] - Starting number of the sequence (0 by default)
* @param {number} stop - Generate up to but not including this number
export type Dict<K, V> = {
[key: K]: V
};
export type Field = {|
type: 'field',
iterable: boolean,
name: string,
nested: boolean,
path: string | void,
validate = (value) => _validate(transform(value))
^^^^^^^^^^^^^^^^ function call. Function cannot be called on possibly undefined value
validate = (value) => _validate(transform(value))
^^^^^^^^^ undefined
import React from 'react';
import styled from 'styled-components';
const createGetPosition = end => index => {
if (index === 0) {
return 'flex-start'
} else if (index === end) {
return 'flex-end'
} else {
return 'center'
@adregan
adregan / README.md
Created January 26, 2019 17:30
SCRIPT-8
function nand
set -lx nand_path "/Users/duncan/projects/nand2tetris/tools"
set -lx programs (ls $nand_path | rg "sh")
printf "Nand2Tetris: Which Program would you like to run? \n\n"
set -lx len (count $programs)
for i in (seq (count $programs))
printf "$i) $programs[$i]\n"
end
function fixup
set -lx current_branch (git rev-parse --abbrev-ref HEAD)
set -lx commits (git log --oneline $current_branch...origin/master)[-1..1]
set -lx len (count $commits)
printf "Fixup: Which commit would you like to fixup? \n\n"
for i in (seq $len)
printf "$i) $commits[$i]\n"
end