Skip to content

Instantly share code, notes, and snippets.

Avatar
🐞

Ben Lopatin bennylope

🐞
View GitHub Profile
@bennylope
bennylope / brew-cleanup.sh
Created Nov 22, 2017
A short script for performing brew cleanup for all but specified packages. The 'cleanup' command can either be used for specific packages or for all - there is no exclusion option - and this means cleanup on older packages that I want.
View brew-cleanup.sh
#!/usr/bin/env bash
# Clean all but specified packages of old homebrewed installed packages
declare -a exclude=(python python3 python34 python35 python36 python27 pypy ruby node)
for PACKAGE in $(brew ls)
do
SENTINEL=false
for EXCLUDE in "${exclude[@]}"
@bennylope
bennylope / conftest.py
Created Mar 4, 2017 — forked from asfaltboy/conftest.py
A pytest fixture to test Django data migrations
View conftest.py
# based on https://gist.github.com/blueyed/4fb0a807104551f103e6
from django.db import connection
from django.db.migrations.executor import MigrationExecutor
import pytest
@pytest.fixture()
def migration(transactional_db):
@bennylope
bennylope / productivity.sh
Last active Sep 30, 2019
Block (from Samuel Mullen on Legacy Rocks slack)
View productivity.sh
# List the domains you want to block, one per line, in your ~/.blocked_sites file,
# then ensure this script is included or sourced in your terminal configuration.
function worktime {
while read -r line; do
echo "127.0.0.1 ${line} # WORKTIME"
echo "fe80::1%lo0 ${line} # WORKTIME"
echo "127.0.0.1 www.${line} # WORKTIME"
echo "fe80::1%lo0 www.${line} # WORKTIME"
done < $HOME/.blocked_sites | sudo tee -a /etc/hosts > /dev/null
@bennylope
bennylope / assert_close_enough.py
Created Aug 26, 2016
Assertion for ensuring that two values are close enough within a certain threshold, comparing on the percentage difference
View assert_close_enough.py
class SomeTestMixin:
def assertCloseEnough(self, first, second, diff=0.0001):
"""
Asserts that the percentage difference between the two values
is smaller than given diff value.
Results may depend on the order of the values. A more robust
version might test the difference against both values.
@bennylope
bennylope / flake8parser.py
Last active Jul 20, 2016
A helper script to create summarize flake8 output.
View flake8parser.py
#!/usr/bin/env python
"""
A script for parsing a flake8 error log and generating useful stats about the
errors in the code.
Author: Ben Lopatin (I think I wrote it, at least, no guarantee)
License: BSD
"""
@bennylope
bennylope / trim-movie.sh
Created May 24, 2016
A short helper script to decode QuickTime .mov files to mp4 files using default settings. Good for creating short screencasts.
View trim-movie.sh
#!/bin/bash
#
# A short helper script to decode QuickTime .mov files to mp4 files using default settings.
#
# Usage:
# ./trim-movie.sh path/to/source.mov path/to/destination.mp4
# ./trim-movie.sh path/to/source.mov path/to/destination.mp4 1080
#
# The optional third paramater is width. You may need to respecify this if you encounter
# divisibility by 2 errors. Not sufficiently motivated to bother checking the size and
@bennylope
bennylope / Vagrantfile
Created May 1, 2016 — forked from pansen/Vagrantfile
Jupyter (aka IPython Notebook) Vagrantfile
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
@bennylope
bennylope / ffmpeg-watermark.md
Created Apr 22, 2016 — forked from webkader/ffmpeg-watermark.md
FFmpeg add a watermark to video
View ffmpeg-watermark.md

How to Add a Watermark to Video

FFMPEG filters provide a powerful way to programmatically enhance or alter videos, and it’s fairly simple to add a watermark to a video using the overlay filter. The easiest way to install ffmpeg is to download a pre-built binary for your specific platform. Then you don’t have to worry about including and installing all the right dependencies and codecs you will be using.

Once you have ffmpeg installed, adding a watermark is as easy as passing your existing source through an overlay filter like so:

ffmpeg -i test.mp4 -i watermark.png -filter_complex "overlay=10:10" test1.mp4

Basically, we’re passing in the original video, and an overlay image as inputs, then passing it through the filter, and saving the output as test1.mp4.

@bennylope
bennylope / export_issues.py
Created Mar 22, 2016
Export GitHub issues to a Pivotal Tracker-ready CSV format
View export_issues.py
#!/usr/bin/env python3
"""
Script for exporting GitHub Issues to an import ready CSV format.
Outputs to stdout for redirection.
It is hard coded (sorry) to include up to 2 comments from an issue.
Usage:
@bennylope
bennylope / leanpub.sh
Last active Jan 3, 2016
A Leanpub API client script
View leanpub.sh
#!/usr/bin/env bash
# Copyright 2016, Ben Lopatin
# Licensed freely to use, modify, and redistribute under GNUGPLv3
APIKEY=$LEANPUB_API_KEY
SLUG=$LEANPUB_SLUG
case "$1" in
preview)