Skip to content

Instantly share code, notes, and snippets.

@mverleg
mverleg / post-commit
Last active February 21, 2018 22:02
Git hook to automatically tag new versions
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
This git hooks makes sure a tag is created each time the version is increased.
This version only works with version from `setup.py` and `settings.gradle`, but can be adapted.
To enable it on git 2.9+, use::
chmod u+x dev/hooks/*
git config core.hooksPath dev/hooks
On older versions, copy or symlink the hooks to `.git/hooks`
@mverleg
mverleg / movie_rainbow.py
Last active October 3, 2017 17:54
Movie frame color rainbow (python 3)
"""
Loads a movie, analyzes the frames in a number of worker threads, and uses the average frame colors to create a rainbow image.
"""
import cv2
import threading
import queue
from os.path import basename
from multiprocessing import cpu_count
from PIL import Image
@mverleg
mverleg / struct_time.patch
Created September 18, 2017 19:29
Patch for pyjson_tricks struct_time (doesn't work because structs can have encoders)
Index: tests/test_tz.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- tests/test_tz.py (revision 55132d48ee28d59420d153088fad9a0db5648ae3)
+++ tests/test_tz.py (revision )
@@ -7,6 +7,7 @@
"""
@mverleg
mverleg / rust-mul-mix-generic.rs
Last active September 11, 2017 19:30
Rust Mul with mixed generics (doesn't work)
use std::fmt::{Display, Formatter, Result};
use std::ops::{Add, Sub, Mul, Div};
pub trait PNr : Copy + Clone + Sized + Mul + Add + Sub + Div + Display {}
impl PNr for f32 {}
impl PNr for f64 {}
impl PNr for i32 {}
impl PNr for i64 {}
from random import shuffle, seed
seed(12345)
x = list(range(10))
shuffle(x)
print(x)
def bubble_sort(z):
@mverleg
mverleg / quiz_04.java
Last active March 27, 2017 11:47
Generics and raw types in Java
// What is the output / error?
// From http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Main {
public static void main(String[] args) {
/*
For the question, see
https://gist.github.com/mverleg/1088fbb5f21590da6691a6e84547bada
OUTPUT:
super constructor
super b
x = 1, y = 3
sub b
x = null, y = 3
@mverleg
mverleg / quiz_03.java
Last active March 16, 2017 09:31
Java inheritane of attributes and methods
/*
The question is simply: what is the output?
Extra: what is `instance.z` after line 8?
*/
public class TestQuestion1 {
public static void main(String[] args) {
SuperCls instance = new SubCls();
}
}
@mverleg
mverleg / pycharm_jump_to_stracktrace_location.py
Created February 26, 2017 12:05
Copy a python stacktrace, then laucnh this script to open the appropriate file in PyCharm (v1)
"""
Get stacktrace from the clipboard, and open the relevant file/line in the
current PyCharm project (useful when using terminal instead of PyCharm run).
Arguments:
1. The path to the PyCharm launcher script (e.g. "~/pycharm/bin/pycharm.sh")
2. [Optional] A json dictionary of path substitutions (e.g '{"/remote/userA": "/home/userA"}')
https://www.jetbrains.com/help/pycharm/2016.3/opening-files-from-command-line.html
@mverleg
mverleg / extract-clementine-playlist-files.py
Last active April 23, 2017 18:16
Copy all the track files from a Clementine playlist to a separate directory.
"""
Reads a Clementine playlist, and copies all the song files to a directory.
arg 1: path to the playlist
arg 2: optionally, the output directory
You can ignore the BeautifulSoup parser warning (or fi you insist, follow it's directions)
"""
from bs4 import BeautifulSoup, Tag # pip install beautifulsoup4
from shutil import copy2