Skip to content

Instantly share code, notes, and snippets.

@jacoduplessis
jacoduplessis / admin.py
Created April 12, 2020 06:04
MPTT admin to move multiple nodes at once
class PlaceAdmin(MPTTModelAdmin):
def get_model_info(self):
app_label = self.model._meta.app_label
return app_label, self.model._meta.model_name
def get_move_form_class(self):
class MoveSelectTargetForm(forms.Form):
target = forms.ModelChoiceField(self.model.objects.all())
position = TreeNodePositionField()
@jacoduplessis
jacoduplessis / data.csv
Created April 10, 2019 08:17
D3 v5 Waterfall
period start of period new returned went inactive
Four Weeks Ago 100 20 30 40
Three Weeks Ago 110 30 20 30
Two Weeks Ago 130 40 25 40
One Week Ago 155 30 55 50
Current Week 190 0 0 0
@jacoduplessis
jacoduplessis / utils.py
Last active March 28, 2019 05:45
Stream SQLAlchemy result as CSV response in Django
import csv
from sqlalchemy.engine.result import ResultProxy
class _Echo:
def write(self, value):
return value
def stream_csv(res: ResultProxy):
w = _Echo()
@jacoduplessis
jacoduplessis / colors.js
Created February 6, 2019 15:43
List of 20 simple distinct colours
// from https://sashat.me/2017/01/11/list-of-20-simple-distinct-colors/
var categoricalColors = [
'#e6194B',
'#3cb44b',
'#ffe119',
'#4363d8',
'#f58231',
'#911eb4',
'#42d4f4',
var GeoJSONFilterControl = L.Control.extend({
initialize: function (geoJsonLayer, data, fields, options = {}) {
this.layer = geoJsonLayer;
this.data = data;
this.fields = fields;
this.filteredOut = {};
L.Util.setOptions(this, options);
},
options: {
position: 'bottomright'
@jacoduplessis
jacoduplessis / firefox_geckodriver_standalone.go
Created November 14, 2018 05:53
Running headless firefox without selenium in golang.
package main
import (
"fmt"
"github.com/tebeka/selenium"
"github.com/tebeka/selenium/firefox"
"log"
"os"
)
@jacoduplessis
jacoduplessis / extract_keyframes.sh
Created July 9, 2018 21:17
Extract keyframes from video
ffmpeg -skip_frame nokey -i video.mp4 -vsync 0 -r 30 -f image2 thumbnails-%03d.jpg
@jacoduplessis
jacoduplessis / dev.sh
Created June 10, 2018 20:28
Run a build script when source files change
while inotifywait -e close_write src ; do NODE_ENV=development node build.js; done
@jacoduplessis
jacoduplessis / remove-mac.sh
Last active June 9, 2018 18:23
Remove mac files
find . -name "*.DS_Store" -delete
find . -name "*._*" -delete
@jacoduplessis
jacoduplessis / build.sh
Created June 8, 2018 18:42
Compile libvips for use with h2non/bimg
#!/bin/bash
apt-get install automake build-essential gobject-introspection gtk-doc-tools libglib2.0-dev libjpeg-dev libpng12-dev libwebp-dev libtiff5-dev libexif-dev libgsf-1-dev liblcms2-dev libxml2-dev swig libmagickcore-dev curl
LIBVIPS_VERSION=8.6.3
cd /tmp
curl -OL https://github.com/jcupitt/libvips/releases/download/v${LIBVIPS_VERSION}/vips-${LIBVIPS_VERSION}.tar.gz
tar zvxf vips-${LIBVIPS_VERSION}.tar.gz
cd /tmp/vips-${LIBVIPS_VERSION}