Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / cffi.md
Last active May 23, 2024 19:28
CFFI passing structs by value

I am trying to return a struct by value from a C function, and then pass it by value to another C function using cffi-libffi.

Here are the relevant functions and structure with links to the definitions in the header file:

(use-foreign-library "libtree-sitter.so")

;; https://github.com/tree-sitter/tree-sitter/blob/master/lib/include/tree_sitter/api.h#L99
(defcstruct ts-node
  (context :uint32 :count 4)
  (id :pointer)
@garlic0x1
garlic0x1 / ts_query.c
Created May 28, 2024 20:24
Performing a query in tree-sitter
#include <stdint.h>
#include <stdio.h>
#include <tree_sitter/api.h>
#include <tree_sitter/tree-sitter-c.h>
int main() {
// Create a Tree-sitter parser
const TSLanguage *language = tree_sitter_c();
TSParser *parser = ts_parser_new();
ts_parser_set_language(parser, language);