This file contains 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
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__ |
This file contains 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
""" | |
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: |
This file contains 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
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: |
This file contains 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 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( |
This file contains 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
""" | |
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: |
This file contains 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
Show hidden characters
{ | |
"cmd": ["erd", "-i", "$file", "-o", "__build__.png"], | |
"path": "/usr/bin:/usr/local/bin" | |
} |
This file contains 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
# 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 |
This file contains 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
#!/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: |
This file contains 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
# 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) |
This file contains 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
""" | |
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 |