Skip to content

Instantly share code, notes, and snippets.

View tmcw's full-sized avatar
💭
merging your prs

Tom MacWright tmcw

💭
merging your prs
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel='stylesheet' type='text/css' href='' />
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
</head>
<body>
<button id='foo'>foo!</button>
<script>
@tmcw
tmcw / index.html
Created January 3, 2013 17:05
d3.keybinding
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font:12px/20px 'Helvetica';
}
textarea, input {
width:100%;
height:20px;
margin:0;

Bonus geometry types in GeoJSON

Basically two types:

  1. Rectangles
  2. Circles

Let's say you have a drawing tool that permits both. Both geometry types benefit from some non-standard drawing abilities: it would be nice to resize circles, and it would be nice to resize rectangles in a way that keeps them rectangular. However, GeoJSON does not have circle or rectangle types. Both are represented as polygons. This gives us two options:

  1. "Detect" these shapes with a heuristic. This is doable for a rectangle by checking the corners, but much, much less doable for circles. Also, circles have an additional property that I will mention in the next bit.
{
"@type": "html",
"value": "<p>Example</p>"
}
#!/usr/bin/env python
from multiprocessing import Pool
import os
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.

My least favorite part of the web platform

Behold, the worst part of the web platform: user gestures.

In short, let's say you've built a web application that edits maps, or… does something else, hypothetically. You implement file saving in that application using the fancy new native browser APIs. Then you have to do some stuff to process or load the file when you click Save - like if you're converting the file and you want to do it in a WebWorker for optimum smoothness. Soon, you will meet this error message:

SecurityError Failed to execute 'showSaveFilePicker' on 'Window': Must be handling a user gesture to show a file picker.

This is just one example of "user gesture" restrictions: you can also find them when you request permissions or attempt to open windows. Basically, to crack down on bad actors or misuse, the browser restricts certain functions to only being called in connection with a click handler.

@tmcw
tmcw / index.html
Created November 2, 2012 00:34
MapBox.js With SVG Markers
<!DOCTYPE html>
<html>
<head>
<script src='http://api.tiles.mapbox.com/mapbox.js/v0.6.6/mapbox.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v0.6.6/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
#marker {
position:absolute;
@tmcw
tmcw / README.md
Last active January 5, 2022 17:37
MapBox OpenLayers Example
@tmcw
tmcw / stripe.md
Created December 21, 2021 14:03
Stripe webhooks in development

Micro-devlog for something tiny.

Placemark uses Stripe, and uses their webhooks. You can use Stripe without webhooks, but it's better to build with the webhooks.

I'm developing the account system actively, so I want the webhooks to work in local development. Thankfully, the stripe cli supports proxying webhooks from your development Stripe environment to your local setup. You run

$ stripe listen --forward-to localhost:5000/stripe_webhooks
@tmcw
tmcw / distance.csv
Last active November 29, 2021 23:51
totalseconds totalmeters starttime sport
2678 6164.9 2009-08-30T13:41:31.000Z Running
10656 5781.8 2009-09-01T23:30:02.000Z Running
1191 2601.8 2009-09-03T23:07:43.000Z Running
1949 6424.6 2009-09-05T16:05:28.000Z Running
1136 3526.4 2009-09-08T23:49:29.000Z Running
2011 5447.2 2009-09-12T20:44:12.000Z Running
1408 4445.9 2009-09-16T23:14:56.000Z Running
1051 2530.5 2009-09-19T20:17:36.000Z Running
1583 3666.2 2009-09-19T20:37:32.000Z Running