Skip to content

Instantly share code, notes, and snippets.

@jnpn
jnpn / django-extensions.el
Created July 15, 2024 07:45
Hackish code to run a test class or the test at point using transient (magit)
;;; django-extensions.el
;;;
;;; various helpers
;;; VARIABLES
;;; TOFIX change <project>
(defvar *project-dir* "/home/jnpn/Code/<project>")
;;; TOFIX: change <app>
(defvar *terminal-template* "xfce4-terminal --working-directory='%s' -H -T '[django.test %s]' -e 'docker compose -f docker-compose.test.yml exec -it <app> python manage.py test %s %s'")
@jnpn
jnpn / peigne.py
Created June 21, 2024 22:34
Classe des elements dans des intervalles. (binning)
class IPeigne:
"""
IPeigne(dents).
Classe des elements dans des intervalles. (binning)
"""
def count(self, elems):
"""Bin elems into buckets."""
@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 = [];
}