Skip to content

Instantly share code, notes, and snippets.

@Zulko
Zulko / python_mermaid_class_tree.py
Created April 18, 2017 18:04
Automatic Python module class tree generation, using Mermaid for rendering
import inspect
def class_name(cls):
"""Return a string representing the class"""
# NOTE: can be changed to str(class) for more complete class info
return cls.__name__
def classes_tree(module, base_module=None):
if base_module is None:
base_module == module.__name__
"""
An alternative text clip for Moviepy, relying on Gizeh instead of ImageMagick
Advantages:
- Super fast (20x faster)
- no need to install imagemagick
- full-vector graphic, no aliasing problems
- Easier font names
Disadvantages:
@Zulko
Zulko / nebscraper.py
Created November 21, 2016 14:54
Goes through the NEB website and compiles all enzymes prices into one spreadsheet
import urllib
import time
from Bio import Restriction
from bs4 import BeautifulSoup
from tqdm import tqdm
import pandas
def get_neb_soup(endpoint):
with urllib.request.urlopen("https://www.neb.com" + endpoint) as response:
from mpl_toolkits.axes_grid.inset_locator import inset_axes
def place_inset_ax_in_data_coordinates(ax, bbox):
"""Return an ax inset in the given ax at the given bbox in
data coordinates (bottom, left, width, height)"""
bottom, left, width, height = bbox
pixels_data_00 = ax.transData.transform([0,0])
pixels_data_11 = ax.transData.transform([1,1])
iwidth, iheight = (pixels_data_11 - pixels_data_00) / ax.figure.dpi
return inset_locator.inset_axes(
@Zulko
Zulko / static_to_django.py
Last active September 9, 2016 17:29
Transform the "static/some/file" of a HTML page into Django-compatible {% static "some/file" %}
"""
Transform the "static/some/file" of a HTML page
into Django-compatible {% static "some/file" %}
"""
import re
source = "some/template.html"
target = "new_template.html"
with open(source, "r") as f:
@Zulko
Zulko / erd.sublime-build
Created October 2, 2015 10:43
Sublime file to build erd diagrams (at least on Macs)
{
"cmd": ["erd", "-i", "$file", "-o", "__build__.png"],
"path": "/usr/bin:/usr/local/bin"
}
@Zulko
Zulko / param_curves.py
Last active December 15, 2020 17:33
Parametric curve animation with Python/Matplotlib/MoviePy
# IMPORTS: THIS SCRIPT REQUIRES THE PACKAGES PYLAB AND MOVIEPY
# It produces this gif: http://i.imgur.com/LbU55oK.gif
from pylab import *
import moviepy.editor as mp
from moviepy.video.io.bindings import mplfig_to_npimage
# PARAMETERS OF THE CURVE AND THE GIF
@Zulko
Zulko / makegifs.py
Last active December 27, 2022 18:16 — forked from luser/makegifs.py
Just indications on what you could do, @luser
#!/usr/bin/env python
# Taken from http://zulko.github.io/blog/2015/02/01/extracting-perfectly-looping-gifs-from-videos-with-python-and-moviepy/
import os
import sys
import moviepy.editor as mp
from moviepy.video.tools.cuts import FramesMatches
if len(sys.argv) != 2:
@Zulko
Zulko / Eugene_hey.py
Created February 9, 2015 20:23
Eugene saying hey!
# Result: http://i.imgur.com/thrh1TU.gif
from moviepy.editor import *
# We start with a looping gif, and we will add some text
clip = VideoFileClip("eugene.gif").speedx(0.7) # slow down a little
txt = (TextClip("Hey", fontsize=78, font='Impact-Normal',
color='yellow', stroke_color='black',
stroke_width=3, kerning=1.5)
@Zulko
Zulko / rapunzel_moviepy.py
Last active May 1, 2023 21:22
Tangled + MoviePy
"""
This creates the following GIF, where the text appears to be "embedded"
in the video and "disappears" behind rapunzel.
http://i.imgur.com/gxEHfLX.gif
"""
from moviepy.editor import *
import numpy as np
import skimage.morphology as skm