Skip to content

Instantly share code, notes, and snippets.

@jnpn
jnpn / gengen.js
Created May 3, 2024 10:11
Dirty generator yielding more generators
function* range(a=0, b=100) {
while (a <= b) {
yield a;
a = a+1;
}
yield range(a=b, b=b+b);
}
var i = range();
@jnpn
jnpn / new-with-mode.el
Created April 8, 2024 09:37
create a new buffer with predefined name and asks which major-mode you want to apply
(defun new-with-mode ()
"Open a new buffer with a selected major-mode MODE."
(interactive "")
(let* ((modes (mapcar #'cdr (cl-remove-if-not (lambda (l) (length= l 1)) auto-mode-alist)))
;; (modes (list #'python-mode #'js-mode #'org-mode))
(rev (mapcar (lambda (m) (cons (symbol-name m) m)) modes))
(mode-pair (assoc (ido-completing-read
"mode> "
(mapcar #'symbol-name modes))
rev))
@jnpn
jnpn / l.el
Created March 1, 2024 00:35
line templating utils
;;; quick naive contextual template WIP
(defun replace-by-transient-overlay ()
"copy word at point as w
kill-word
create overlay with text `w'
overlay map -> any char -> delete overlay"
:todo)
(defun l/line-template-at-point ()
@jnpn
jnpn / y.el
Created February 25, 2024 01:14
failed yeetube.el clone
;;; y.el
;;; url -> yt-dlp -> mpv
;;;
"
url
-> title and formats[id, url]
-> completing-read
"
@jnpn
jnpn / org-capture-template.el
Created February 21, 2024 01:36
simple append-only auto-datetimed blog entry template for emacs org-mode
'(("b" "blog" entry
(file+function "~/org/blog.org" end-of-buffer)
"* %T %^{TITLE} %^g
> %^{MOOD}p
> %c
> %x
> %i
> %F
%?"))
@jnpn
jnpn / blind.sh
Created February 15, 2024 00:21
blind typing exercises
# you can type stuff blind, listen to it to check, and do it again
which espeak || echo "you need to install espeak"
while true; do read word; echo $word | espeak ; sleep 1; echo "next" | espeak ; sleep 1 ; done
@jnpn
jnpn / tre.py
Created January 11, 2024 03:05
a tree eDSL to describe filesystems or similar
"""
a tree eDSL to describe filesystems or similar
- can stack children
- can indicate a point up in the tree (//, mark ?)..
- can shift back up (-, up ?)
- can stack non atomic values, list ? generators ? sub Tre ?
- can have domain specific children (inject(filename))
to describe the content of the tree later on
@jnpn
jnpn / repeated.js
Created December 26, 2023 01:32
js class to wrap setinterval and make a start/stopable thunk with ~private state
class Repeated {
constructor(delay, cond, fn, state) {
this.delay = delay;
this.cond = cond;
this.fn = fn;
this.state = state;
this.timer = null;
this.timers = [];
}
@jnpn
jnpn / pgsql_table_size.sql
Created November 12, 2023 20:20
top 10 largest table by size (postgresql)
select schemaname as table_schema,
relname as table_name,
pg_size_pretty(pg_total_relation_size(relid)) as total_size,
pg_size_pretty(pg_relation_size(relid)) as data_size,
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid))
as external_size
from pg_catalog.pg_statio_user_tables
order by pg_total_relation_size(relid) desc,
pg_relation_size(relid) desc
limit 10;
@jnpn
jnpn / flan.py
Created June 27, 2023 13:17
FLuent ANnotations
class Flan:
def __init__(self, *a, **k):
self.a = a
self.k = k
self.chain = []
def __floordiv__(self, other):
self.chain.append(other)
return self