Skip to content

Instantly share code, notes, and snippets.

Avatar

Douglas Duhaime duhaime

View GitHub Profile
@duhaime
duhaime / doors-ice.jpg
Last active January 28, 2023 21:33
Three.js Image Overlay
@duhaime
duhaime / TrackballControls.js
Created May 12, 2019 15:29
Image Pixels (Three.js)
View TrackballControls.js
/**
* @author Eberhard Graether / http://egraether.com/
* @author Mark Lundin / http://mark-lundin.com
* @author Simone Manini / http://daron1337.github.io
* @author Luca Antiga / http://lantiga.github.io
*/
THREE.TrackballControls = function ( object, domElement ) {
var _this = this;
@duhaime
duhaime / measure_img_similarity.py
Last active January 19, 2023 22:11
Compare image similarity in Python using Structural Similarity, Pixel Comparisons, Wasserstein Distance (Earth Mover's Distance), and SIFT
View measure_img_similarity.py
import warnings
from skimage.measure import compare_ssim
from skimage.transform import resize
from scipy.stats import wasserstein_distance
from scipy.misc import imsave
from scipy.ndimage import imread
import numpy as np
import cv2
##
@duhaime
duhaime / arrowhead.js
Created September 17, 2017 13:28
Directed Graph Arrowhead
View arrowhead.js
// Add svg marker for arrowheads
svg.append('svg:defs').append('svg:marker')
.attr('id', 'arrowhead')
.attr('viewBox', '0 0 10 10')
.attr('refX', 22)
.attr('refY', 5)
.attr('markerWidth', 9)
.attr('markerHeight', 9)
.attr('orient', 'auto')
.append('svg:path')
@duhaime
duhaime / index.html
Last active August 8, 2022 20:40
Three.js: Indexed Buffer Geometry with Texture and Custom Shader Attributes
View index.html
<html>
<head>
<style>
html, body { width: 100%; height: 100%; background: #000; }
body { margin: 0; overflow: hidden; }
canvas { width: 100%; height: 100%; }
</style>
</head>
<body>
<script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/92/three.min.js'></script>
@duhaime
duhaime / body2mesh.js
Last active August 8, 2022 08:54
Convert a Cannon.js body to a THREE.js mesh
View body2mesh.js
function body2mesh(body, wireframe) {
var wireframe = wireframe || true;
var obj = new THREE.Object3D();
for (var l = 0; l < body.shapes.length; l++) {
var shape = body.shapes[l];
var mesh;
switch(shape.type){
@duhaime
duhaime / .gitignore
Last active July 12, 2022 16:22
Minimal Multiple File Uploads with Vue + Node or Flask Server
View .gitignore
*.pem
*.swp
*.DS_Store
__pycache__/
node_modules/
uploaded_files/
@duhaime
duhaime / .gitignore
Last active July 6, 2022 15:23
Minimal Heroku / Flask App
View .gitignore
*.pyc
__pycache__
@duhaime
duhaime / convert.py
Created February 23, 2019 15:33
Particle Dance
View convert.py
import json
l = {}
j = json.load(open('dance.json'))
for body_part in j:
l[body_part] = []
sub = []
for idx in j[body_part]:
val = j[body_part][idx]
View british-cities-to-counties.json
{"Aberdare": "Mid Glamorgan", "Aberdeen": "Aberdeenshire", "Aberdovey": "Gwynedd", "Abergavenny": "Gwent", "Abergele": "Clwyd", "Abertillery": "Gwent", "Aberystwyth": "Dyfed", "Abingdon": "Oxfordshire", "Accrington": "Lancashire", "Airdrie": "Lanarkshire", "Alcester": "Warwickshire", "Aldeburgh": "Suffolk", "Alderley Edge": "Cheshire", "Aldershot": "Hampshire", "Alfreton": "Derbyshire", "Alness": "Ross-shire", "Alnwick": "Northumberland", "Alresford": "Hampshire", "Alston": "Cumbria", "Alton": "Hampshire", "Altrincham": "Cheshire", "Ambleside": "Cumbria", "Amersham": "Buckinghamshire", "Amesbury": "Wiltshire", "Ammanford": "Carmarthenshire", "Andover": "Hampshire", "Anstruther": "Fife", "Antrim": "Co Antrim", "Appleby-in-Westmorland": "Cumbria", "Arbroath": "Angus", "Ardrossan": "Ayrshire", "Armagh": "Co Armagh", "Arthog": "Gwynedd", "Arundel": "West Sussex", "Ascot": "Berkshire", "Ashbourne": "Derbyshire", "Ashburton": "Devon", "Ashford": "Middlesex", "Ashington": "Northumberland", "Ashtead": "Surrey", "Asht