Skip to content

Instantly share code, notes, and snippets.

(defun etc-maybe-recenter ()
(unless (or
;; don't interfere with erc scroll-to-bottom
(derived-mode-p 'erc-mode 'term-mode 'shell-mode 'eshell-mode)
(not (eq (get-buffer-window (current-buffer) t) (selected-window)))
(equal (window-point) (point-max))
(region-active-p)
)
(recenter)))
#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
typedef void (*test_function_t)();
// Why is `__attribute__((aligned(16)))` necessary? With the default
// alignment of 8, we print a large negative value for limit and then
// don't print any `a` fields.
struct __attribute__((aligned(16))) foo
@jgarvin
jgarvin / random_event_loop.py
Last active December 15, 2023 01:20
Randomize asyncio awaits
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import random
import logging as log # noqa
from typing import TypeVar, Generator
import pytest
_T = TypeVar("_T")
@jgarvin
jgarvin / gist:5a0ae2d5ac8a97fb3170cab3d88144a5
Created December 3, 2023 16:46
asyncio won't automatically shutdown all tasks huh...
import asyncio
import signal
import logging as log
def cancel_all_tasks(loop: asyncio.AbstractEventLoop) -> None:
log.info("SIGINT received, cancelling tasks...")
tasks = asyncio.all_tasks(loop)
for task in asyncio.all_tasks(loop):
task.cancel()
@jgarvin
jgarvin / gist:42539190ea136d92db0ee898daf8ac8b
Created December 3, 2023 16:23
So python asyncio only has weak refs to tasks in the event loop...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
from asyncio import Task
import contextvars
from typing import Any, Coroutine, TypeVar
T = TypeVar("T")
@jgarvin
jgarvin / gist:0ee73b1d4b9dc306c63b68e6e7d0fbca
Created September 7, 2023 23:17
bazel system calls on incremental build
$ cut -d'(' -f 1 /tmp/log | grep -av attached | grep -aoE '\] [a-zA-Z0-9]+' | sort | uniq -c
4 ] accept4
18 ] chmod
194 ] clone
427 ] close
50 ] epoll
192 ] exit
12 ] fcntl
413 ] fstat
35636 ] futex
#![allow(dead_code)]
struct A {
data: i32,
}
struct B {
data: i32,
}
(defun mouse-button-pressed-p ()
"Return non-nil if last event is a mouse-button down event."
(run-hooks 'mouse-leave-buffer-hook)
(and (consp last-input-event)
(string-match-p "down-mouse-" (format "%s" (car last-input-event)))))
(defun etc-maybe-recenter ()
(unless (or
;; don't interfere with erc scroll-to-bottom
(wrong-type-argument char-or-string-p [nil 22077 4073 787364 1 etc-clear-truncate-timer (#<buffer $shell<5>>) nil 553000])
helm-mm-exact-match([nil 22077 4073 787364 1 etc-clear-truncate-timer (#<buffer $shell<5>>) nil 553000])
#[0 "\300\211\205\215\211@\307\"\204\206\310!\305\301\203\301!\202!\203\205\307\"\204\205\311\303\236\2047\312\313#\210\314\315\303\"\211\203k\211<\203f\316!\204f\211\317:\203a@\262\211!\262A\262\202L\266\202k\211!\262\210\306\306\242B\240\210\304\211\242T\240\210\304\242\302U\203\205\320\321\317\"\210\210A\266\202\202\207" [([nil 22077 4073 787364 1 etc-clear-truncate-timer (#<buffer $shell<5>>) nil 553000] [nil 22077 4074 0 1 buffer-tail ("*mandimus-server*") nil 0] [nil 22077 4087 730233 60 etc-set-repeat-rate nil nil 16000] [nil 22077 4102 266712 30 erc-server-send-ping (#<buffer irc.freenode.net:6667>) nil 804000] [nil 22077 4206 596849 300 savehist-autosave nil nil 963000] [nil 22077 53928 0 86400 run-hooks (midnight-hook) nil 0]) nil 10
@jgarvin
jgarvin / eshell-hist-dirs.el
Created November 4, 2015 18:49
eshell f/b
(defvar-local eshell-hist-dirs nil)
(defvar-local eshell-hist-index 0)
(defun etc-eshell-update-hist-dir ()
;; prevent "cd /tmp" over and over from making new entries
(when (not (equal (car (last eshell-hist-dirs)) (eshell/pwd)))
(push (eshell/pwd) eshell-hist-dirs)))
(add-hook 'eshell-directory-change-hook #'etc-eshell-update-hist-dir)