Skip to content

Instantly share code, notes, and snippets.

@erw7
erw7 / fib.el
Last active July 16, 2024 11:03
Some Fibonacci sequence functions with Emacs lisp
(defun fib-tail-recursion (n &optional n-1 n-2)
(let ((n-1 (or n-1 1))
(n-2 (or n-2 0)))
(cond ((zerop n) n-2)
(t
(fib-tail-recursion (- n 1) (+ n-1 n-2) n-1)))))
(defun fib-tail-recursion-cl-lables (n)
(cl-labels ((fib-in (n n-1 n-2)
(cond ((zerop n) n-2)
@erw7
erw7 / func.el
Created July 17, 2024 09:51
Some function of Emacs Lisp
(defun walk-leaf-cl-labels (lst fn)
(cl-labels ((walk-leaf-in
(lst fn &optional acc)
(setq acc (funcall fn lst acc))
(cond
((or
(null lst)
(not (listp lst)))
acc)
(t (walk-leaf-in
(let ((electric-input-enable-dmeassage nil))
(defun set-electric-input-dprint (flag)
(setq electric-input-enable-dmeassage flag))
(defun get-electric-input-dprint ()
electric-input-enable-dmeassage)
(defun electric-input-dmessage (&rest args)
(when electric-input-enable-dmeassage
(let ((inhibit-message t))
;;; Emacs Lisp version of On Lisp with-gensyms
(defmacro with-make-symbol (vars &rest body)
`(let ,@(mapcar (lambda (v)
`((,v (make-symbol ,(symbol-name v)))))
vars)
,@body))
(defmacro inc (var)
`(setq ,var (1+ ,var)))
@erw7
erw7 / wslbridge2.diff
Last active October 7, 2024 09:54
Fix issue where wslbridge2 fails to get vmid
diff --git a/src/GetVmId.cpp b/src/GetVmId.cpp
index ba5a612..dd7bcee 100644
--- a/src/GetVmId.cpp
+++ b/src/GetVmId.cpp
@@ -8,9 +8,12 @@
* GetVmId.cpp: Get GUID of WSL2 Utility VM with LxssUserSession COM interface.
*/
+#include <Wbemidl.h>
#include <winsock.h>