This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rgb2hex(rgb): | |
return ''.join([format(val, '02X') for val in rgb]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ortools.sat.python import cp_model | |
class SolutionPrinter(cp_model.CpSolverSolutionCallback): | |
def __init__(self, variables): | |
super().__init__() | |
self.variables = variables | |
self.solutions = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import stats | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def PoissonPP( rt, Dx, Dy=None ): | |
''' | |
Determines the number of events `N` for a rectangular region, | |
given the rate `rt` and the dimensions, `Dx`, `Dy`. | |
Returns a <2xN> NumPy array. | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:latest | |
MAINTAINER Vaclav Cadek | |
RUN apt-get update | |
RUN apt-get install python-virtualenv -y | |
RUN virtualenv -p /usr/bin/python3 ~/venv | |
RUN . ~/venv/bin/activate | |
RUN ~/venv/bin/pip install numpy pandas matplotlib jupyter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kafka import KafkaConsumer | |
consumer = KafkaConsumer('fast-messages', bootstrap_servers='localhost:9092') | |
for message in consumer: | |
print(message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def animate(i): | |
return plt.plot(x[:i], y[:i], c='r') | |
x = np.linspace(0, 2*np.pi, 100) | |
y = np.sin(x) | |
fig = plt.figure(figsize=(12, 8)) | |
plt.xlim(0, 2 * np.pi) | |
plt.ylim(-1, 1) | |
anim = animation.FuncAnimation(fig, animate, frames=100) | |
display(HTML(anim.to_html5_video())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
permutation = list(np.random.permutation(m)) | |
shuffled_X = X[:, permutation] | |
shuffled_Y = Y[:, permutation].reshape((1,m)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def logger(func): | |
def wrapped(*args, **kwargs): | |
print('Calling {} with args = {} and kwargs = {}'.format(func, args, kwargs)) | |
return func(*args, **kwargs) | |
return wrapped | |
@logger | |
def factorial(n): | |
if n == 1: | |
return 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib.animation import FuncAnimation | |
import matplotlib.pyplot as plt | |
import numpy as np | |
fig, ax = plt.subplots(figsize=(5, 8)) | |
def update(i): | |
im_normed = np.random.random((64, 64)) | |
ax.imshow(im_normed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent import futures | |
import time | |
def long_running_task(result): | |
print('Task is running!') | |
time.sleep(1) | |
return result | |
start = time.perf_counter() |