Skip to content

Instantly share code, notes, and snippets.

View duhaime's full-sized avatar

Douglas Duhaime duhaime

View GitHub Profile
@duhaime
duhaime / cheatsheet.rb
Created May 3, 2024 22:40 — forked from mabenson00/cheatsheet.rb
Rails ActiveRecord JSON cheatsheet
# Basic key operators to query the JSON objects :
# #> : Get the JSON object at that path (if you need to do something fancy)
# -> : Get the JSON object at that path (if you don't)
# ->> : Get the JSON object at that path as text
# {obj, n} : Get the nth item in that object
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE
# Date
# date before today
@duhaime
duhaime / imagenet1000_clsidx_to_labels.txt
Created April 7, 2021 19:55 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class idx to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
@duhaime
duhaime / separate_points.py
Created January 2, 2020 17:37 — forked from naught101/separate_points.py
Separating points on a map
def lat_lon_hex_mesh(bounds, d=3):
"""Creates a hexagonal lat/lon mesh within bounds that has a radial separation of d"""
lone, lonw, lats, latn = bounds
# heigt of equilatral triangle from radial distance sqrt(r^2 - (r/2)^2)
h = np.sqrt(0.75) * d
w = d / 2
lat_vals = np.arange(lats, latn, h)
@duhaime
duhaime / bezier_curves.py
Created April 30, 2019 09:58 — forked from astrojuanlu/bezier_curves.py
Interactive Bézier curves with Python using just matplotlib.
import matplotlib
matplotlib.use('webagg')
import numpy as np
from scipy.special import binom
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
@duhaime
duhaime / .block
Created April 3, 2019 00:15 — forked from Fil/.block
Circular Vortex Emergence
license: gpl-3.0
border: no
scrolling: no
height: 500
@duhaime
duhaime / index.html
Last active October 26, 2018 14:05 — forked from omimo/index.html
Dancing Lines
<html>
<head>
<title>
[Visualizing Movement Data with D3.js]
</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://omid.al/Mova-Viz/MovaViz-v0.1.2.js"></script>
<style>
* {
box-sizing: border-box
@duhaime
duhaime / README.md
Created October 1, 2018 01:12 — forked from armollica/README.md
K-Nearest Neighbors

K-nearest neighbors search of a 2D set of points. Move the slider or scroll to change k.

The algorithm was adapted from this block

@duhaime
duhaime / README.md
Created October 1, 2018 01:09 — forked from armollica/README.md
K-D Tree Nearest Neighbors (k-NN)

k-d tree nearest neighbors search (k-NN). The red dots are the 10 nearest neighbors. Orange dots are scanned and not selected.

Compare with this block that implements a k nearest neighbor search using a quadtree instead of a k-d tree.

The algorithm for this search came from this course handout. Note that the "k" in k-d tree need not be the same number as the "k" in

@duhaime
duhaime / .block
Created September 11, 2018 10:40 — forked from mbostock/.block
Milky Way
license: gpl-3.0
@duhaime
duhaime / .block
Created September 11, 2018 10:37 — forked from Fil/.block
visualizing map distortion d3v4
license: mit