Skip to content

Instantly share code, notes, and snippets.

View rlabbe's full-sized avatar

Roger Labbe rlabbe

  • SF Bay Area, California
View GitHub Profile
void foo1(HANDLE start, HANDLE end, vector<Data>* data_queue, int index)
{
int id = index;
vector<Data>* data = data_queue;
while (true) {
WaitForSingleObject(start, INFINITE);
ResetEvent(start);
Data& d = (*data)[index++];
if (index >= data->size())
@rlabbe
rlabbe / R-to-Python
Last active February 24, 2016 01:13
dbeta (.7, 1, 2)
from scipy.stats import beta
beta(1, 2).pdf(.7) # frozen form, very slow if only calling once!!!!!!
beta.pdf(.7, 1, 2)
@rlabbe
rlabbe / style_notebook.py
Created August 29, 2015 16:17
Style Jupyter Notebook using CSS
# style the notebook
from IPython.core.display import HTML
import urllib.request
# this link is to my Kalman filter book CSS file.
response = urllib.request.urlopen('http://bit.ly/1LC7EI7')
HTML(response.read().decode("utf-8"))
@rlabbe
rlabbe / equal aspect ratio
Created July 13, 2015 04:48
Matplotlib equal aspect ratio
import matplotlib.pyplot as plt
ax = plt.gca()
ax.set_aspect('equal')
plt.xlim(-4, 4)
plt.ylim(0, 8)
@rlabbe
rlabbe / real_time_plotting.py
Last active March 14, 2023 13:09
Plot with matplotlib with real time updates without plt.pause
# draw the figure so the animations will work
import matplotlib.pyplot as plt
fig = plt.gcf()
fig.show()
fig.canvas.draw()
while True:
# compute something
plt.plot([1, 2, 3, 4, 5], [2, 1, 2, 1, 2]) # plot something
@rlabbe
rlabbe / gist:8870c25915085194cd8d
Last active August 29, 2015 14:18
Plot linear equations with sympy
from sympy.abc import x, y, z
from sympy.plotting import plot, plot3d
import sympy as sp
fron sympy import solve, Eq
def plot_line(e):
e = solve(e, y)
plot(e[0])
def triangle_angles(p0, p1, p2):
A = p1 - p0
B = p2 - p1
C = p0 - p2
angles = []
for e1, e2 in ((A,-B), (B,-C), (C,-A)):
num = np.dot(e1, e2)
denom = np.linalg.norm(e1) * np.linalg.norm(e2)
angles.append(np.arccos(num/denom))
return angles
@rlabbe
rlabbe / chrono_timing.cpp
Last active June 16, 2017 19:05
timing in c++
#include <chrono>
using namespace std;
auto start = chrono::high_resolution_clock::now ();
double x = 3; // bet this doesn't take long
auto now = chrono::high_resolution_clock::now ();
chrono::duration<double> time_span = now - start;
auto seconds = time_span.count();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.