Skip to content

Instantly share code, notes, and snippets.

View wboykinm's full-sized avatar

Bill Morris wboykinm

View GitHub Profile
@wolever
wolever / histogram.sql
Last active April 19, 2023 20:28
Functions to create and draw histograms with PostgreSQL.
-- Functions to create and draw histograms with PostgreSQL.
--
-- psql# WITH email_lengths AS (
-- -# SELECT length(email) AS length
-- -# FROM auth_user
-- -# LIMIT 100
-- -# )
-- -# SELECT * FROM show_histogram((SELECT histogram(length, 0, 32, 6) FROM email_lengths))
-- bucket | range | count | bar | cumbar | cumsum | cumpct
-- --------+-------------------------------------+-------+--------------------------------+--------------------------------+--------+------------------------
@darribas
darribas / contextily_labels.ipynb
Created February 4, 2021 12:21
Contextily labels examples
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bmcbride
bmcbride / LeafletToWKT.js
Last active June 7, 2022 02:17
Leaflet layer to WKT
function toWKT(layer) {
var lng, lat, coords = [];
if (layer instanceof L.Polygon || layer instanceof L.Polyline) {
var latlngs = layer.getLatLngs();
for (var i = 0; i < latlngs.length; i++) {
latlngs[i]
coords.push(latlngs[i].lng + " " + latlngs[i].lat);
if (i === 0) {
lng = latlngs[i].lng;
lat = latlngs[i].lat;
@mourner
mourner / tiles.js
Created February 5, 2014 15:21
Leaflet — get all tile URLs given geographic bounds, tile layer and zoom
function getTileUrls(bounds, tileLayer, zoom) {
var min = map.project(bounds.getNorthWest(), zoom).divideBy(256).floor(),
max = map.project(bounds.getSouthEast(), zoom).divideBy(256).floor(),
urls = [];
for (var i = min.x; i <= max.x; i++) {
for (var j = min.y; j <= max.y; j++) {
var coords = new L.Point(i, j);
coords.z = zoom;
@tmcw
tmcw / ajax_for_cats.md
Last active April 19, 2021 21:08
AJAX for Cats

AJAX For Cats

I will assume that you are familiar with Javascript and HTML - read up on jsforcats.com if you need Javascript chops, and Learn HTML for HTML.

AJAX is a feature of Javascript and your browser that downloads new data after you initially request a page: so you live-update content and pull in new bits of content a user requests. AJAX is how the Pinterest home page keeps loading content when you scroll, and it's how Gmail can ring in new emails without requiring you to click 'refresh' all the time.

Let's clear things up. Like Javascript for Cats, it's best to use Google Chrome for this, and to use your web developer extensions.

Requests

<html>
<head>
<title>Deckgl RGB PointCloud + Mapbox</title>
<script src="https://unpkg.com/deck.gl@^7.0.0/dist.min.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.54.0/mapbox-gl.js"></script>
<link rel="stylesheet" type="text/css" href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.54.0/mapbox-gl.css">
<style>
body {
background-color: #000000;
margin: 0;
@robertsdionne
robertsdionne / deepdream-install.md
Last active February 15, 2021 16:07
Deepdream installation
#!/usr/bin/env bash

# Assuming OS X Yosemite 10.10.4

# Install XCode and command line tools
# See https://itunes.apple.com/us/app/xcode/id497799835?mt=12#
# See https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html
xcode-select --install
#! /bin/bash -ex
# Convert Landsat 8 GeoTIFF images into RGB pan-sharpened JPEGs.
#
# Requirements:
# * gdal http://www.mapbox.com/tilemill/docs/guides/gdal/
# * Dan Stahlke's https://github.com/gina-alaska/dans-gdal-scripts
# * convert (image-magick)
#
# Reference info:
@jacobandresen
jacobandresen / gist:836127
Created February 20, 2011 17:28
nonimatim openlayers jquery example
$(function() {
var geoCodeURL = "http://nominatim.openstreetmap.org/search";
var map = new OpenLayers.Map({ div: "map" });
var osm = new OpenLayers.Layer.OSM();
map.addLayers([osm]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(
new OpenLayers.LonLat( 9.2134, 55.3028).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
@wboykinm
wboykinm / hexgrid.sql
Created February 12, 2014 17:12
Hexgrid code
WITH hgrid AS
(SELECT CDB_HexagonGrid(ST_Expand(CDB_XYZ_Extent(/* INSERT TILE XYZ SOMEHOW */), CDB_XYZ_Resolution(/* CURRENT ZOOM */) * 15), CDB_XYZ_Resolution(/* CURRENT ZOOM */) * 15) AS cell)
SELECT hgrid.cell AS the_geom_webmercator,
count(i.cartodb_id) AS points_count,
count(i.cartodb_id)/power(15 * CDB_XYZ_Resolution(/* CURRENT ZOOM */), 2) AS points_density,
1 AS cartodb_id
FROM hgrid,
(SELECT *
FROM /* TABLE NAME HERE */) i
WHERE ST_Intersects(i.the_geom_webmercator, hgrid.cell)