Skip to content

Instantly share code, notes, and snippets.

@z0u
z0u / mp4-to-gif.sh
Created March 30, 2025 05:31
Converts a video to a gif for embedding in README files.
sudo apt update && sudo apt install ffmpeg gifsicle
# First pass: Generate a palette
ffmpeg -i input.mp4 -vf "fps=10,palettegen" palette.png
# Second pass: Create the GIF using the palette
ffmpeg -i input.mp4 -i palette.png -filter_complex "fps=10 [x]; [x][1:v] paletteuse" output.gif
# Third pass: Optimize the GIF
gifsicle -O3 --lossy=30 output.gif -o output-optimized.gif
@z0u
z0u / instance_cache.py
Created September 2, 2016 14:39
Just like functools.lru_cache, but creates a new cache for each instance - which is more useful for methods.
def instance_method_lru_cache(*cache_args, **cache_kwargs):
'''
Just like functools.lru_cache, but a new cache is created for each instance
of the class that owns the method this is applied to.
'''
def cache_decorator(func):
@wraps(func)
def cache_factory(self, *args, **kwargs):
# Wrap the function in a cache by calling the decorator
instance_cache = lru_cache(*cache_args, **cache_kwargs)(func)
@z0u
z0u / function_asfrom.py
Created December 1, 2015 23:10
SQLAlchemy workaround for PostgreSQL functions that produce columns
#
# Workaround for unusual PostgreSQL syntax, where functions act like columns.
# Recipe provided by zzzeek (Mike Bayer), author of SA.
# https://bitbucket.org/zzzeek/sqlalchemy/issues/3594/using-text-in-a-join
# https://bitbucket.org/zzzeek/sqlalchemy/issues/3566/figure-out-how-to-support-all-of-pgs#comment-23564706
#
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import functions
from sqlalchemy.sql.elements import ColumnClause
@z0u
z0u / package_bge_runtime.py
Last active November 24, 2022 21:50
Python script to create an executable game by combining a Blender file with the blenderplayer. Asset files can be included; these will not be combined with the executable, but included in the zip archive. The blenderplayer is sourced from a Blender release archive, so multiple platforms can be targeted. To get a release archive, go to: http://ww…
#!/usr/bin/env python3
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
<!doctype html>
<html>
<head>
<script src="lib/jquery/jquery.js"></script>
<script src="lib/jquery/jquery-ui.js"></script>
<script src="lib/jsplumb/jquery.jsPlumb.js"></script>
<script>
$(function() {
jsPlumb.importDefaults({
@z0u
z0u / git-svn-diff.sh
Created February 4, 2012 22:43 — forked from neowulf/git-svn-diff.sh
Creates a patch file between svn branch and git branch
#!/bin/bash
#
# git-svn-diff originally by (http://mojodna.net/2009/02/24/my-work-git-workflow.html)
# modified by [email protected]
# modified by aconway@[redacted] - handle diffs that introduce new files
# modified by [email protected] - fixes diffs that introduce new files
# modified by [email protected] - fix sed syntax issue in OS X
# modified by [email protected] - search for last SVN commit; allow diff
# against non-tracking branch; remove function names on @@ lines.
#