Skip to content

Instantly share code, notes, and snippets.

View duhaime's full-sized avatar

Douglas Duhaime duhaime

View GitHub Profile
@duhaime
duhaime / server.py
Created June 20, 2019 10:53
Flask + Redis + background process in while loop
from flask import Flask, jsonify, request, send_from_directory
import redis, celery, sys, socket, os, json
# config
port = 6000 # port on which data streams
# app
app = Flask(__name__, static_url_path='')
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
@duhaime
duhaime / .gitignore
Last active June 18, 2020 12:06
Simple Flask Server
*.json
@duhaime
duhaime / knn.py
Created June 17, 2019 15:52
Find KNN for Gensim Model
from annoy import AnnoyIndex
import json
import os
def build_ann_index(model):
'''Build an ANN model and persist to disk for faster vector similarity queries'''
words = list(model.wv.vocab.keys()) # list of strings, one per word
idx_to_word = {str(idx): i for idx, i in enumerate(words)} # d[word] = word_idx in words
dims = model.wv[words[0]].shape[0] # number of dimensions in each input vector
@duhaime
duhaime / unproject.js
Created June 2, 2019 15:47
three.js unproject unprojection event to world coords
function getWorldCoords(e) {
// identify the x,y coords in canavs that got event
var rect = canvas.getBoundingClientRect(),
x = e.clientX - rect.left,
y = e.clientY - rect.top;
// convert x,y to clip space in canvas:
// canvas coords from top left in clockwise order
// (-1,1), (1,1), (-1,-1), (1, -1)
var mouse = new THREE.Vector3();
mouse.x = ( (x / canvas.clientWidth ) * 2) - 1;
@duhaime
duhaime / DH-Ideation.pdf
Last active February 13, 2020 18:10
Rapid Prototyping Grants and Project Management in Yale's DHLab
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@duhaime
duhaime / atlas-0.jpg
Last active June 2, 2019 13:22
MNIST 3D (Three.js)
atlas-0.jpg
@duhaime
duhaime / index.html
Last active May 27, 2019 15:22
Draw a Neural Network
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Drawing a Neural Network</title>
<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/5.9.2/d3.min.js'></script>
</head>
<body>
<script>
@duhaime
duhaime / 1812_Page_03.jpg
Last active May 24, 2019 15:20
Extracting illustrations with picsnip
1812_Page_03.jpg
@duhaime
duhaime / index.html
Last active July 29, 2024 01:23
Minimal Frame Buffer Object (Three.js)
<html>
<head>
<style>
html, body { width: 100%; height: 100%; background: #000; }
body { margin: 0; overflow: hidden; }
canvas { width: 100%; height: 100%; }
</style>
<meta charset='UTF-8'>
</head>
<body>
@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;