Skip to content

Instantly share code, notes, and snippets.

@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
@garlic0x1
garlic0x1 / defmemo.lisp
Created November 22, 2023 05:08
defmemo/int->int
; depends on alexandria
; memoizes int->int functions in a mutable vec
(defmacro defmemo/int->int (size name (in) &body body)
(let ((memo-name (read-from-string (format nil "~a-memo" name))))
`(progn (defvar ,memo-name (make-array (+ 1 ,size) :initial-element nil))
(defun ,name (,in)
(if-let ((memo (aref ,memo-name ,in)))
memo
(setf (aref ,memo-name ,in) (progn ,@body)))))))
@garlic0x1
garlic0x1 / workers.lisp
Last active September 5, 2023 11:36
CL concurrent worker functions
(defpackage workers
(:use :cl)
(:export #:list->simple-cqueue
#:simple-cqueue->list
#:join-workers
#:join-consumers
#:wmap
#:wfilter
#:wforeach))
@garlic0x1
garlic0x1 / glob.scm
Last active August 28, 2023 08:52
scheme glob->regex
(module (web globby) (globby->regexpstr globby->regexp globby-match)
(import (garlic base) regex)
;; made this since the one in `regex` egg doesnt support globstar
(define (globby->regexpstr glob)
"Only supports | ? * **"
;; mutable variable to dedupe globstars, sorry
(define ignoring-stars #f)