Skip to content

Instantly share code, notes, and snippets.

@LeMinaw
LeMinaw / emby-vlc.js
Created October 14, 2022 17:31
Add a "Copy VLC command" link to Emby media server pages.
// ==UserScript==
// @name VLC playback link for Emby web client
// @namespace LeMinaw/EmbyVLCPlayback
// @version 1.0.0
// @description Add a "Copy VLC command" link to Emby media pages.
// @author LeMinaw
// @grant none
// @match *://emby.*.synology.me/*
// ==/UserScript==
@LeMinaw
LeMinaw / managers.py
Created August 22, 2022 12:40
Custom manager for ordering Django QuerySets with modeltranslation
from django.db.models import F, QuerySet
from django.db.models.functions import Coalesce
from modeltranslation.settings import AVAILABLE_LANGUAGES
from modeltranslation.utils import (
build_localized_fieldname, get_language, resolution_order)
class MultilingualOrderQuerySet(QuerySet):
def coalesce_translations(self, field):
"""Coalesce all translations of a given field according to the
@LeMinaw
LeMinaw / only-red.html
Created November 27, 2021 04:38
SVG filter to turn an image into grayscale, except for a specific color channel (namely, red)
<svg>
<filter id="only-red">
<!-- Build an alpha mask to match pixels where R>G and R>B -->
<!-- That "192" value can be adjusted to change the selectivity of the selection -->
<feColorMatrix result="mask" values="
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
192 -255 -255 0 1
"/>
@LeMinaw
LeMinaw / select_search.js
Last active July 20, 2023 13:00
Text filtering widget in MaterializeCSS multiple select
/*
MaterializeCSS tweak to allow text filtering in multiple selects.
It should be fairly easy to adapt it for use in single selects. :-)
*/
document.addEventListener('DOMContentLoaded', event => {
document.querySelectorAll('select[searchable]').forEach(elem => {
const select = elem.M_FormSelect;
const options = select.dropdownOptions.querySelectorAll('li:not(.optgroup)');
import numpy as np
vdot = lambda x, y: np.float64(x.T * y)
norm2 = lambda x: vdot(x, x)
norm = lambda x: np.sqrt(norm2(x))