Skip to content

Instantly share code, notes, and snippets.

@garlic0x1
garlic0x1 / hooks.lisp
Created February 25, 2024 05:17
Lisp hook API
(defpackage :hooks
(:use :cl)
(:import-from :alexandria :if-let)
(:export :register-hook :run-hook))
(in-package :hooks)
(defvar *hooks* (make-hash-table)
"Global hook table.
Use `register-hook` and `clear-hook` to modify this.")
@garlic0x1
garlic0x1 / readtable-case.lisp
Created February 18, 2024 19:53
Common Lisp case-sensitive keywords
(set-macro-character
#\$
(lambda (stream char)
(declare (ignore char))
(let ((*readtable* (copy-readtable nil)))
(setf (readtable-case *readtable*) :preserve)
(read stream))))
$:CaseSensitiveKeyword
;; => :|CaseSensitiveKeyword|
@garlic0x1
garlic0x1 / setup.sh
Last active February 7, 2024 08:01
Setup Lisp Machine (Fedora)
#!/bin/bash
set -x
### Packages
dnf update -y
dnf install -y sbcl git make gcc ncurses-devel redhat-rpm-config curl rlwrap
### Config
curl https://raw.githubusercontent.com/garlic0x1/dotfiles/master/.bashrc > ~/.bashrc
@garlic0x1
garlic0x1 / glob.lisp
Created January 29, 2024 07:45
Glob match with CFFI
(cffi:defcfun ("fnmatch" fnmatch) :int
(pattern :string)
(string :string)
(flags :int))
(defun glob-match (pattern string &optional (flags 4))
(= 0 (fnmatch pattern string flags)))
@garlic0x1
garlic0x1 / tilde-list.lisp
Created January 29, 2024 06:12
CL shorthand list
(set-macro-character
#\~
(lambda (stream char)
(declare (ignore char))
`(list ,@(read stream t))))
;; USAGE:
(macroexpand (quote ~(1 2 3)))
;; => (LIST 1 2 3)
@garlic0x1
garlic0x1 / glib_example.c
Created January 15, 2024 08:09
GLib collections examples
#include <stdio.h>
#include <glib.h>
int main(int argc, char *argv[])
{
/* Linked List demo */
GList *list = NULL;
list = g_list_append(list, "Hello world!");
list = g_list_append(list, "Bye world!");
@garlic0x1
garlic0x1 / ollama.el
Last active December 13, 2023 11:58
Async Ollama client for Emacs
;;; gpt.el -*- lexical-binding: t; -*-
(defgroup ollama nil
"Ollama client for Emacs."
:group 'ollama)
(defcustom ollama:endpoint "http://192.168.68.108:11434/api/generate"
"Ollama http service endpoint."
:group 'ollama
:type 'string)
@garlic0x1
garlic0x1 / hello-rpm.org
Created December 12, 2023 09:44
Hello RPM

Hello Rpm

hello.spec:

Name:     hello
Version:  2.10
Release:  %autorelease
Summary:  Produces a familiar, friendly greeting
License:  GPL-3.0-or-later
URL:      https://www.gnu.org/software/hello/
@garlic0x1
garlic0x1 / c.el
Last active December 7, 2023 07:57
Auto format C in Emacs
;; help load config files (convenience function for my Doom setup, change for other distros)
(defun config-path (path)
(concat doom-user-dir path))
;; runs clang-format with a specified config file
(defun clang-format-with-spec (spec)
(shell-command
(concat "clang-format"
" --style=file:" spec
" -i " buffer-file-name)))
@garlic0x1
garlic0x1 / Makefile
Last active December 3, 2023 06:17
C Makefile
##
# Project Title
#
# @file
# @version 0.1
CC=gcc
CFLAGS=-g -Wall
PROGNAME=CHANGEME