This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (rmap proc target) | |
(cond | |
[(list? target) (map (curry rmap proc) target)] | |
[(vector? target) (vector-map (curry rmap proc) target)] | |
[else (proc target)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require db | |
memo | |
"util.rkt" | |
racket/serialize) | |
(provide #%app | |
#%datum | |
#%top |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> .schema | |
CREATE TABLE Files( file_id INTEGER PRIMARY KEY, filename VARCHAR(4096) NOT NULL UNIQUE, last_modified INTEGER, size INTEGER, num_tags INTEGER DEFAULT 0); | |
CREATE TABLE sqlite_stat1(tbl,idx,stat); | |
CREATE TABLE FileTags( file_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, probability DOUBLE NOT NULL, PRIMARY KEY (file_id, tag_id), FOREIGN KEY(file_id) REFERENCES Files(file_id), FOREIGN KEY(tag_id) REFERENCES Tags(tag_id)); | |
CREATE TABLE Tags(tag_id INTEGER PRIMARY KEY, tag_name VARCHAR[50] NOT NULL UNIQUE, num_files INTEGER DEFAULT 0); | |
CREATE TABLE TagCardinalities( | |
a INTEGER NOT NULL, | |
b INTEGER NOT NULL, | |
cardinality INTEGER, | |
PRIMARY KEY (a,b), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(query-exec (sqldb-param) | |
(prepared (string* "INSERT OR REPLACE INTO TagCardinalities (a,b,cardinality)" | |
" SELECT min($1,t.tag_id),max($1,t.tag_id),ifnull(sub.cnt,0) " | |
" FROM Tags t LEFT JOIN" | |
"(SELECT tag_id, COUNT(*) as cnt FROM FileTags WHERE file_id IN " | |
"(SELECT file_id FROM FileTags WHERE tag_id=$1)" | |
"GROUP BY tag_id) AS sub" | |
"ON t.tag_id = sub.tag_id")) | |
a-id))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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' |
NewerOlder