Skip to content

Instantly share code, notes, and snippets.

View duhaime's full-sized avatar

Douglas Duhaime duhaime

View GitHub Profile
@duhaime
duhaime / image-to-points.ipynb
Created July 30, 2019 13:34
Image to Points: Convert an input image to a series of discrete, uniform-sized points using simple statistical sampling
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@duhaime
duhaime / B612.ttf
Last active July 16, 2019 19:27
Load Many Fonts
@duhaime
duhaime / download.py
Last active July 12, 2019 18:54
Download Yale Digital Collection Images
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time, os, json, glob
if not os.path.exists('records'):
os.makedirs('records')
max_page_fetched = 0
for i in glob.glob('records/*.json'):
page = int(os.path.basename(i).split('-')[0])
@duhaime
duhaime / dat.gui.min.js
Last active July 10, 2019 19:58
Wordmap
/**
* dat-gui JavaScript Controller Library
* http://code.google.com/p/dat-gui
*
* Copyright 2011 Data Arts Team, Google Creative Lab
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@duhaime
duhaime / randomDarkColor.js
Created July 10, 2019 18:44
random dark color - javascript
function randomDarkColor() {
var lum = -0.35;
var hex = String('#' + Math.random().toString(16).slice(2, 8).toUpperCase()).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
var c, i, rgb = '#';
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i * 2, 2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ('00' + c).substr(c.length);
}
@duhaime
duhaime / scroll-into-view.js
Last active July 2, 2019 23:22
Scroll Into View (via SO 17722497)
(function() {
function currentYPosition() {
// Firefox, Chrome, Opera, Safari
if (self.pageYOffset) return self.pageYOffset;
// Internet Explorer 6 - standards mode
if (document.documentElement && document.documentElement.scrollTop)
return document.documentElement.scrollTop;
// Internet Explorer 6, 7 and 8
if (document.body.scrollTop) return document.body.scrollTop;
return 0;
@duhaime
duhaime / mongodb.conf
Created June 24, 2019 15:14
mongodb.conf default mongo mongodb config file
# mongodb.conf
# Where to store the data.
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb
#where to log
@duhaime
duhaime / .block
Last active September 10, 2019 20:01
Visualizing Vicon Streams
height: 450
@duhaime
duhaime / socket_stream.py
Last active June 20, 2019 14:20
stdin stream
import sys, socket, redis, json
# config
stream = {'host': '127.0.0.1', 'port': 6000} # streaming data host / port
r = redis.Redis(host='127.0.0.1', port=6379) # redis instance host / port
# consume data from stdin and publish to redis on localhost
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((socket.gethostbyname(stream['host']), stream['port'])) # host, port
@duhaime
duhaime / signal.py
Created June 20, 2019 11:54
Signal Listener
# class to gracefully handle sigint / sigterm (SO 18499497)
class SignalListener:
kill_now = False
def __init__(self):
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
def exit_gracefully(self,signum, frame):
self.kill_now = True