Skip to content

Instantly share code, notes, and snippets.

@danodic
danodic / hello-sdl.janet
Created July 7, 2024 05:57
Janet SDL Example
# This is an example of how to use SDL in Janet using the FFI module.
# This is based on Lazy Foo's tutorial that can be found at:
# https://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php
#
# In order to run this, you need:
# - To have libSDL2.so at the same folder where the source code is.
# - Create three separate files, as descibed by the comments below.
# - Read the FFI docs here:
# https://janet-lang.org/1.25.1/docs/ffi.html
#
@danodic
danodic / heading-tree.cljc
Created June 1, 2024 03:39
Transform a list of html headings and return a TOC tree
;; I had to create a Table of Contents component for my personal site, and in
;; order to do that I had to scan all headings in the document (using .querySelectorAll)
;; and transform them into a list of maps that I could use to nest them properly.
;; The idea is to get a plain vector of nodes created using `make-node` and return
;; a tree in which nodes are nested according to their level.
(defn make-node
"Creates the representation of an HTML heading. You can search for all headings
in your document and convert them to this structure."
[tag-name tag-level value]
@danodic
danodic / collisions.py
Created November 22, 2023 03:50
Vector Collisions using PyGame
# This code is ugly and slow, just a reference.
# But is works (mostly)
from __future__ import annotations
from dataclasses import dataclass
from typing import Tuple
import pygame.draw
from pygame import Surface
{
"transfer": "AAAAA",
"transaction_feed": "BBBBB",
"change_name": "CCCCC"
}
@danodic
danodic / log.clj
Last active June 22, 2020 01:27
A simple log lib using mutable data in clojure
(ns dev.danodic.log
"A simple module with mutable data structures. Used to create logs grouped
by discrete elements, like files. It was meant to be used as the logging
lib for rushbeat, but at this point I'm not sure if this is being used or
not. As it relies on refs, it is probably thread safe as well (did not
test this and at this point I'm a beginner at Clojure."
(:require [clj-time.local :as time])
(:gen-class))
; Stores the log entries