Skip to content

Instantly share code, notes, and snippets.

View vaclavcadek's full-sized avatar

Václav Čadek vaclavcadek

  • Stealth
  • Prague, Czech Republic
View GitHub Profile
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()))
@vaclavcadek
vaclavcadek / consumer.py
Last active December 6, 2017 12:06
Simple Kafka communication.
from kafka import KafkaConsumer
consumer = KafkaConsumer('fast-messages', bootstrap_servers='localhost:9092')
for message in consumer:
print(message)
@vaclavcadek
vaclavcadek / Dockerfile
Created December 19, 2017 12:26
Jupyter notebook minimal configuration.
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
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.
'''
@vaclavcadek
vaclavcadek / ortools_cp.py
Created July 30, 2018 16:05
Simple Ortools solver for CP
from ortools.sat.python import cp_model
class SolutionPrinter(cp_model.CpSolverSolutionCallback):
def __init__(self, variables):
super().__init__()
self.variables = variables
self.solutions = []
@vaclavcadek
vaclavcadek / rgb2hex.py
Created August 8, 2018 13:58
Transform RGB color to hex.
def rgb2hex(rgb):
return ''.join([format(val, '02X') for val in rgb])
@vaclavcadek
vaclavcadek / 51_1.tsp
Created September 13, 2018 15:46
Simple implementation (I don't remember where I found it, but it was in C/C++) of Lin-Kernighan heuristic for TSP.
51
27 68
30 48
43 67
58 48
58 27
37 69
38 46
46 10
61 33
@vaclavcadek
vaclavcadek / fourier_transform.py
Created March 4, 2021 16:24
Code for amazing 3B1B lecture (https://youtu.be/spUNpyF58BY) about Fourier Transform intuition.
from scipy.integrate import simpson
import matplotlib.pyplot as plt
import numpy as np
def almost_fourier_transform(g: np.ndarray, t: np.ndarray, f: float):
# approximate center of mass as a mean
t1 = np.min(t)
t2 = np.max(t)
scaling_factor = (1 / (t2 - t1))
@vaclavcadek
vaclavcadek / Dockerfile
Last active April 2, 2024 17:37
Simple example of AWS Lambda + custom image, usage: 1) docker build . -t test/hello-world 2) docker run --rm -p 9000:8080 test/hello-world:latest 3) curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"foo": "test"}'
FROM python:3.8-alpine
# Define global args
ARG FUNCTION_DIR="/home/app/"
RUN apk add --no-cache \
libstdc++
# Install aws-lambda-cpp build dependencies
RUN apk add --no-cache \
@vaclavcadek
vaclavcadek / backward_compatibility.py
Created March 25, 2021 13:00
Forward and backward compatibility illustration.
import json
import pickle
class Foo:
""" An old Foo."""
def __init__(self, a, b):
self.a = a
self.b = b