Skip to content

Instantly share code, notes, and snippets.

@cpbotha
cpbotha / init.el
Last active February 6, 2023 10:45
View init.el
;; minimal version of my Emacs setup which approximates the effective points per inch on your screen
;; and then selects your default font pts based on that
;; Also works on wayland / WSLg because it parses out physical dims from weston.log (necessary in 2023-01)
;; LIMITATION: Will probably not work on multi-monitor setups. Exercise for the reader!
;; BSD 3-clause copyright Charl P. Botha <info@charlbotha.com>
(defun get-mon-attr (which)
(cdr (assoc which (car (display-monitor-attributes-list)))))
(defun get-monitor-width-mm ()
View mastodon-init.el
(use-package mastodon
:ensure t
:config
;; I am @cpbotha@emacs.ch on Mastodon which translates to:
(setq mastodon-instance-url "https://emacs.ch")
(setq mastodon-active-user "cpbotha"))
@cpbotha
cpbotha / init.el
Last active January 28, 2022 13:56
View init.el
;; as of 2021-12-19 with latest master pgtk emacs on non-store WSL I can copy
;; text from other apps into Emacs, but I can't copy text from Emacs into other
;; apps, and so I use this work-around with wl-copy.
;; original value of interprogram-cut-function was gui-select-text.
;; you need to have the wl-clipboard package installed for the wl-copy tool.
;; update 2022-01-28: this work-around still required with WSL 0.51.2.0
(when (getenv "WAYLAND_DISPLAY")
(setq
interprogram-cut-function
(lambda (text)
View libgccjit.rb
# three changes by Charl Botha https://github.com/cpbotha to get this building
# on the M1
# 1. use the iains branch of gcc (see head spec)
# 2. change build config to "--build=aarch64-apple-darwin#{osmajor}"
# 3. remove --with-bugurl
# then build with:
# brew install --verbose --build-from-source -head --formula ./libgccjit.rb
# took about 18 minutes on my M1 MBA
View pyproject.toml
[tool.poetry]
name = "stream-manager"
version = "0.0.147"
description = ""
authors = ["David Weber <david.weber@stonethree.com>", "Janto Dreijer janto.dreijer@stonethree.com"]
license = "Proprietary"
packages = [
{ include = "server" }
]
@cpbotha
cpbotha / lapingvino_zig_example.nim
Created December 9, 2020 18:35
nim implementation of toy zig example
View lapingvino_zig_example.nim
# two nim-lang solutions based on this reddit thread:
# https://old.reddit.com/r/Zig/comments/k9q0vi/append_to_slice_in_zig/
# and this gist:
# https://gist.github.com/LaPingvino/57fb1c0afaacdb1185f247db2b365102
# -- Charl P. Botha <https://charlbotha.com/>
# on this Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz I get:
# with nim 1.4.2 and nim c --gc:orc -d:release:
# {500000002, 2}
@cpbotha
cpbotha / guessing_game.nim
Last active November 27, 2020 11:52
cpbotha's nim n00b version of togglebit's guessing game
View guessing_game.nim
# guess a number inspired by togglebit! https://www.twitch.tv/togglebit
# this nim version by nim n00b Charl P. Botha https://charlbotha.com/
# if I build this with nim 1.4 on ubuntu 20.04 with:
# nim c -d:release --opt:size guessing_game.nim
# the resultant binary is 62 kBytes
import random, strutils
# init random seed
randomize()
@cpbotha
cpbotha / figure.html
Last active January 19, 2023 06:31
Drop-in replacement for Hugo figure shortcode with img srcset support
View figure.html
{{/*
figure with auto-resizing and srcset v2020-05-10
Drop-in replacement for Hugo's figure shortcode as of 2020-05-02 that uses img srcset
to enable browsers to download only the resolution that they need.
The resizing and srcset magic only works for images that are part of the page
bundle. It will fall back to stock Hugo figure behaviour otherwise.
View archive-extract-to-file.el
;; https://emacs.stackexchange.com/a/3843/8743 original code
;; cpbotha.net made small improvements to ergonomics
;; cpbotha changes:
;; - by default extract files WITHOUT their relative directories into DIR,
;; because that's what I expect in OFMs.
(defun archive-extract-to-file (archive-name item-name command dir keep-relpath)
"Extract ITEM-NAME from ARCHIVE-NAME using COMMAND. Save to
DIR. If KEEP-RELPATH, extract with relative path otherwise don't."
(unwind-protect
View m0_itead_shield_xbee_test.ino
/**
* Running this sketch on the RobotDyn Arduino M0 (SAMD21) with the itead xbee shield 1.1 I see the following output:
*
* waiting for any serial data to become available from the xbee
* 2795 MODEM_STATUS_RESPONSE: 0
* waiting for any serial data to become available from the xbee
* No packet available.
* waiting for any serial data to become available from the xbee
* 7974 MODEM_STATUS_RESPONSE: 0
*