Skip to content

Instantly share code, notes, and snippets.

@jgreco
jgreco / mpv_thumbnail_script_client_osc.lua
Created November 8, 2018 23:18
mpv_thumbnailer_script WITH youtube-quality OSC icon
--[[
Copyright (C) 2017 AMM
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 3 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
@jgreco
jgreco / youtube-quality.lua
Last active August 30, 2021 04:54
demo mpv user builtin for youtube-dl
-- youtube-quality.lua
--
-- Change youtube video quality on the fly.
--
-- Diplays a menu that lets you switch to different ytdl-format settings while
-- you're in the middle of a video (just like you were using the web player).
--
-- Bound to ctrl-f by default.
local mp = require 'mp'
#lang racket
(require "murmur3.rkt")
(require data/bit-vector)
(require racket/serialize)
(provide make-bloom-filter make-recommended-bloom-filter bloom-filter-recommender bloom-filter-member? bloom-filter-batch-member? bloom-filter-add! false-positive-rate )
(define (murmur-int x seed) (murmur-hash (integer->integer-bytes x 8 false false) seed))
(define (h1 x) (murmur-int x 583))
(define (h2 x) (murmur-int x 2387))
@jgreco
jgreco / mpv.rkt
Last active September 22, 2019 08:53
quick hack mpv JSON IPC client
#lang racket
(require json
racket/port
racket/unix-socket
racket/async-channel)
(provide mpv/fire-and-forget)
(define (mpv/fire-and-forget files)
(match-let-values
([(_ _ to-mpv _) (subprocess (open-output-file "/dev/null" #:exists 'append)
(define (rmap proc target)
(cond
[(list? target) (map (curry rmap proc) target)]
[(vector? target) (vector-map (curry rmap proc) target)]
[else (proc target)]))
#lang racket/gui
(require framework)
(define swapping-tab-panel%
(class tab-panel%
(inherit get-selection set-selection set)
(super-new [callback
(lambda (b e)
(when (eq? 'tab-panel (send e get-event-type))
(send swapper-panel active-child
#lang racket
;; > (require "observer-app.rkt")
;; > (hash-set! (observers-namespace) '+ `(,(lambda (a . b) (printf "adding ~a to ~a~n" a b))))
;; > (+ 1 2 3)
;; adding 1 to (2 3)
;; 6
(provide (rename-out [observer-app #%app])
observers-namespace)
(define (sync/vector evts-v)
(let ([sync-vec (build-vector (vector-length evts-v)
(lambda (n)
(wrap-evt
(vector-ref evts-v n)
(lambda (r) (cons n r)))))])
(let loop ()
(let ([remaining-evts (filter evt? (vector->list sync-vec))])
(unless (empty? remaining-evts)
(let ([res (apply sync remaining-evts)])
#lang racket
(require db
memo
"util.rkt"
racket/serialize)
(provide #%app
#%datum
#%top
;; Remove a given tag from a set of file ids.
;; If any of the file ids is not tagged with the given tag, they are silently skipped
;; without hassling the user. If a tag is empty after this operation, it is deleted.
;;
;; TODO: This procedure performs up to three database writes. If those writes
;; happened to be interleaved with other writes which are associated with
;; the same tag, screwy things might happen. Therefore these two/three
;; writes should be performed in a single transaction.
(define (untag-files tag . file-ids)
(let* ([tag-id (get-tag-id tag)]