Skip to content

Instantly share code, notes, and snippets.

View victor-shepardson's full-sized avatar

Victor Shepardson victor-shepardson

View GitHub Profile
@victor-shepardson
victor-shepardson / gist:6127aeb8de4e4b7b023c
Created May 4, 2015 21:24
simple texture feedback example (untested)
//in your .h file if using one
ofShader shader;
ofFbo fbo;
int w, h;
//in .cpp file
void ofApp::setup(){
w = 640; h=480;
ofEnableDataPath();
ofSetWindowShape(w,h);
Wolfram Alpha input to get polynomial approximation to function on an interval
for example to approximate exp(x) with ax^2 + bx + 1 on [0,1]:
solve (partial derivatives wrt a,b of (integral of (exp(x)-(ax^2 +bx+1))^2 from 0 to 1)) for a,b
or properly:
Solve[ D[ Integrate[ (exp(x)-(ax^2 +bx+1))^2, {x,0,1} ], {{a,b}} ] = 0, {a,b}]
running test
running egg_info
writing dependency_links to protobuf.egg-info/dependency_links.txt
writing protobuf.egg-info/PKG-INFO
writing namespace_packages to protobuf.egg-info/namespace_packages.txt
writing requirements to protobuf.egg-info/requires.txt
writing top-level names to protobuf.egg-info/top_level.txt
reading manifest file 'protobuf.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files found matching 'google/protobuf/internal/*.proto'
@victor-shepardson
victor-shepardson / gibbs.py
Created March 13, 2017 18:55
estimate a univariate Gaussian with Gibbs sampling
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm, invgamma
# estimate a univariate gaussian by Gibbs sampling
true_mu = 10
true_sigma = 2
true_v = true_sigma**0.5
N = 50
R = 5000
@victor-shepardson
victor-shepardson / pytorch-glumpy.py
Last active March 25, 2024 19:47
using pycuda and glumpy to draw pytorch GPU tensors to the screen without copying to host memory
from contextlib import contextmanager
import numpy as np
import torch
from torch import Tensor, ByteTensor
import torch.nn.functional as F
from torch.autograd import Variable
import pycuda.driver
from pycuda.gl import graphics_map_flags
from glumpy import app, gloo, gl
@victor-shepardson
victor-shepardson / pytorch-glumpy.md
Last active September 10, 2022 16:09
using pycuda and glumpy to draw pytorch GPU tensors to the screen without copying to host memory
@victor-shepardson
victor-shepardson / bokeh_notebook_image_figure.py
Created September 25, 2017 17:52
dynamic RGB image figure in bokeh+jupyter for monitoring GAN training, etc. import or paste into cell.
try:
from bokeh.io import push_notebook, output_notebook, show
from bokeh.plotting import figure
output_notebook()
def dynamic_image_figure(w,h):
"""create an RGB image figure in current cell and return an update function for it"""
def im2bokeh(img):
img = (img*255).astype(np.uint8)
img = np.dstack([img, np.ones(img.shape[:2], np.uint8) * 255])
img = np.squeeze(img.view(np.uint32))
@victor-shepardson
victor-shepardson / es6-promise-catch-behavior.js
Created March 13, 2018 16:25
demonstrate that `.catch(err => Promise.reject(err))` is redundant
'use strict';
(new Promise((resolve, reject) => {
resolve('success');
})).then(x => {throw 'thrown error in then, no catch'});
(new Promise((resolve, reject) => {
resolve('success');
})).then(x => {throw 'thrown error in then, with catch'})
.catch(err => Promise.reject(err));
@victor-shepardson
victor-shepardson / handy_coroutine_decorator.py
Last active January 20, 2020 05:01
write a function once as a coroutine and easily get blocking version or kick off a Future
import asyncio
def wrap_coroutine(coroutine):
def future(*a, **kw):
return asyncio.ensure_future(coroutine(*a, **kw))
def sync(*a, **kw):
return asyncio.get_event_loop().run_until_complete(coroutine(*a, **kw))
coroutine.sync = sync
coroutine.future = future
return coroutine
@victor-shepardson
victor-shepardson / pqd.py
Last active January 20, 2020 05:01
Python 3 combined priority queue + dict. pop the smallest (key, value) pair by value comparison order or access any value by key. assigning to a key which is still in the queue will mark the old value dead and push the new one.
import heapq
class PQDItem:
def __init__(self, k, v):
self.v = v
self.k = k
self.dead = False
def __lt__(self, other):
return self.v < other.v