Skip to content

Instantly share code, notes, and snippets.

@alanthird
alanthird / wombat-theme.el
Last active September 18, 2023 18:06
Playing with Emacs's built-in wombat theme
;;; wombat-theme.el --- Custom face theme for Emacs -*- lexical-binding:t -*-
;; Copyright (C) 2011-2023 Free Software Foundation, Inc.
;; Author: Kristoffer Grönlund <krig@koru.se>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
(require 'svg)
(defun replace-text (start end)
(interactive "r")
(let* ((str (buffer-substring start end))
(scale (cadr (assoc :height (assoc 'default face-remapping-alist))))
(width (float (car (window-text-pixel-size nil start end))))
(height (float (cdr (window-text-pixel-size nil start end))))
(family (face-attribute 'default :family))
(ascent (* (aref (font-info family) 8) (if scale scale 1)))
(img (format "<?xml version='1.0' encoding='UTF-8'?>
@alanthird
alanthird / svg-text.el
Last active April 10, 2021 09:16
Use SVGs to replace text in Emacs
;; Score out this text
(require 'svg)
(defun replace-text (start end)
(let* ((str (buffer-substring start end))
(scale (cadr (assoc :height (assoc 'default face-remapping-alist))))
(family (face-attribute 'default :family))
(height (* (aref (font-info family) 2) (if scale scale 1)))
(ascent (* (aref (font-info family) 8) (if scale scale 1)))
(img (svg-create (car (window-text-pixel-size nil start end))
@alanthird
alanthird / noto-fonts.el
Last active November 2, 2023 14:22
Set up Noto fonts in Emacs
;; Provided by Sebastian Urban
;; More information at https://idiocy.org/emacs-fonts-and-fontsets.html
(set-fontset-font "fontset-default" 'adlam "Noto Sans Adlam")
(set-fontset-font "fontset-default" 'anatolian "Noto Sans Anatolian Hieroglyphs")
(set-fontset-font "fontset-default" 'arabic "Noto Sans Arabic")
(set-fontset-font "fontset-default" 'aramaic "Noto Sans Imperial Aramaic Regular")
(set-fontset-font "fontset-default" 'armenian "Noto Sans Armenian")
(set-fontset-font "fontset-default" 'avestan "Noto Sans Avestan")
(set-fontset-font "fontset-default" 'balinese "Noto Sans Balinese")
@alanthird
alanthird / create-restore-script.sql
Created June 28, 2018 12:36
Generate restore commands for all SQL Server backups taken in the last day, while changing datafile locations.
DECLARE @source nvarchar(256),
@destination nvarchar(256)
SET @source = 'X:\Websense SQL\MSSQL10_50.WEBSENSEWSG\MSSQL\DATA\'
SET @destination = 'C:\ClusterStorage\DBstore1\MSSQL12.WEBSENSEWSG\MSSQL\DATA\'
SELECT DISTINCT 'RESTORE DATABASE ' + database_name +
' FROM DISK = ''' + physical_device_name + ''''+
' WITH RECOVERY,' +
' MOVE ''' + datafile.logical_name + '''' +
@alanthird
alanthird / lisp.js
Created September 4, 2016 11:22
Lisp-like meta-circular evaluator written in JavaScript
"use strict";
function lexer(input) {
let pos = 0
/* A couple of functions to help us grab the characters. */
function next() {
if (pos < input.length) {
return input.charAt(pos++)
}
@alanthird
alanthird / unichar-mode.el
Last active November 23, 2015 15:14
An Emacs minor mode for inserting unicode quotes and dashes.
;;; unichar-mode --- Insert correct unicode characters
;;; Copyright (C) Alan Third 2015
;; Author: Alan Third <alan@idiocy.org>
;; Created: 21 Nov 2015
;; Homepage: https://gist.github.com/alanthird/b758d3fb45b0e863f8a4
;; Version: 1.0
@alanthird
alanthird / greek-letters.el
Last active August 29, 2015 14:23
Add bindings for all the Greek letters to emacs.
;; Bind all the greek letters with the prefix C-c g. So, for example
;; C-c ga inserts α and C-c gOME inserts Ω
(defun at/global-bind-alist (prefix alist)
(mapc
(lambda (p)
(global-set-key (kbd (concat prefix (car p))) (cdr p)))
alist))
(at/global-bind-alist "C-c g"
@alanthird
alanthird / prime.js
Last active August 29, 2015 14:17
Javascript stream-based prime number checking
function millerRabin(n) {
function isOdd(n) {
return n%2===1;
}
function rnd(floor, ceil) {
return floor+Math.floor(Math.random()*(ceil-floor));
}
function expmod(base, exponent, mod) {