Skip to content

Instantly share code, notes, and snippets.

> .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),
;; 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)]
#lang racket
(require db
memo
"util.rkt"
racket/serialize)
(provide #%app
#%datum
#%top
(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 "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)
#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
(define (rmap proc target)
(cond
[(list? target) (map (curry rmap proc) target)]
[(vector? target) (vector-map (curry rmap proc) target)]
[else (proc target)]))
@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)