Skip to content

Instantly share code, notes, and snippets.

View duhaime's full-sized avatar

Douglas Duhaime duhaime

View GitHub Profile
@duhaime
duhaime / body2mesh.js
Last active February 17, 2024 22:44
Convert a Cannon.js body to a THREE.js mesh
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 / index.html
Last active November 8, 2023 21:22
GPU Picking (Three.js)
<html>
<head>
<style>
html, body { width: 100%; height: 100%; background: #000; }
body { margin: 0; overflow: hidden; }
canvas { width: 100vw; height: 100vh; }
#selected { position: absolute; top: 10; left: 10; font-size: 40; color: black; background: #fff; width: 100%;}
</style>
</head>
<body>
@duhaime
duhaime / .gitignore
Last active July 21, 2023 05:39
Minimal Multiple File Uploads with Vue + Node or Flask Server
*.pem
*.swp
*.DS_Store
__pycache__/
node_modules/
uploaded_files/
@duhaime
duhaime / app.py
Last active June 27, 2023 16:16
smtp python
from flask import Flask, render_template
from smtp_client import send_email
from smtp_server import SMTPServer
app = Flask(__name__)
@app.route('/send_email')
def email():
server = SMTPServer()
server.start()
@duhaime
duhaime / index.html
Last active May 27, 2023 17:19
Three.js points mesh + ShaderMaterial
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>title</title>
<style>
body, html {
margin: 0;
padding: 0;
background: #000;
@duhaime
duhaime / index.html
Last active April 20, 2023 10:00
Three.js: Indexed Buffer Geometry with Texture and Custom Shader Attributes
<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 / measure_img_similarity.py
Last active March 1, 2023 08:41
Compare image similarity in Python using Structural Similarity, Pixel Comparisons, Wasserstein Distance (Earth Mover's Distance), and SIFT
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 / headless.py
Last active February 16, 2023 23:19
Python Selenium Headless Chrome OSX
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', chrome_options=chrome_options)
driver.get("http://www.duo.com")
@duhaime
duhaime / doors-ice.jpg
Last active January 28, 2023 21:33
Three.js Image Overlay
doors-ice.jpg
@duhaime
duhaime / TrackballControls.js
Created May 12, 2019 15:29
Image Pixels (Three.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;