Skip to content

Instantly share code, notes, and snippets.

// ==UserScript==
// @name Floating Panel Class
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Reusable floating panel with indicators and burger menu
// @author You
// @grant none
// ==/UserScript==
(function() {
@vidarh
vidarh / claude-er.html
Created August 19, 2024 12:31
Simple example of an ER diagram with some embellishments (gradients, fixes to connector routing) using JointJS written entirely by Claude
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ER Diagram with JointJS, Metallic Entities, and Drop Shadows (Fixed)</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.4.0/backbone-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.5.5/joint.min.js"></script>
@vidarh
vidarh / terrain.rb
Created February 25, 2024 18:27
Stupidly basic and ugly terrain generation for DragonRuby
def tick args
args.outputs.background_color = [0,0,0]
args.outputs.labels << {x: 20, y: 700, text: "Landscape Test", r: 255, g: 255, b: 255 }
args.pixel_array(:col).width = 1
args.pixel_array(:col).height = 200
px = args.pixel_array(:col).pixels
200.times do |y|
y = y.abs.floor & 0xff
col = y << 8
@vidarh
vidarh / stateexample.rb
Created January 22, 2024 05:29
Trivial state machine example
module StateMachine
def self.included(base) = base.extend(ClassMethods)
def transition_to(to)
before = self.class.do_before_transition(state)
send(before) if before
return @state = to
end
@vidarh
vidarh / a-hairy-exploration-of-k.md
Last active January 5, 2024 11:39
A hairy exploration of k
@vidarh
vidarh / SIEVE.rb
Last active January 5, 2024 12:09
Ruby port of the SIEVE caching algorithm using a ring instead of a linked list
# See https://cachemon.github.io/SIEVE-website/blog/2023/12/17/sieve-is-simpler-than-lru/
# for a description and the Python version
# *LARGELY UNTESTED*
Node = Struct.new(:value, :visited, :prev, :next)
class SieveCache
def initialize(capacity)
@capacity = capacity
@cache = {}
@vidarh
vidarh / rubywm.rb
Created November 21, 2023 20:16
rubywm.rb - a minimalist WM using pure-x11 and based on TinyWM
# Based on TinyWM by Nick Welch
require 'X11'
dpy = X11::Display.new
root = dpy.screens.first.root
# OK, so pure-x11 *really* badly needs built in keysym lookup,
# but I don't want to add that without doing it properly, so this
@vidarh
vidarh / README.md
Created September 28, 2023 18:37
Identify relevant commands for this directory, and optionally bring up rofi|dmenu to select, and optionally run them

dir-commands

Pick and optionally run relevant commands for a directory

Vidar Hokstad [email protected], 2023. Licensed under the MIT license.

With no options dir-commands looks for Makefile, Rakefile, Gemfile, package.json, .git etc. in

@vidarh
vidarh / sexp.rb
Created June 8, 2023 15:17
Minimal Ruby S-expression parser w/test case showing using %(string syntax) to naturally embed s-expressions in Ruby code.
require 'strscan'
class Sexp
def initialize(str); @s = StringScanner.new(str); end
def s(e); @s.scan(e); end
def r(e); s(e) or raise "Expected #{x}"; end
def list; s("(")&&b=body and r(")") and b; end
def exp; s(/[a-zA-Z][\w_-]*/)&.to_sym||s(/[0-9]+/)&.to_i||s(/"[^"]*"/)&.[](1..-2)||list||r("exp"); end
def body; r=[]; while s(/\s*/) and [email protected]? and [email protected](")") and e=exp; r<<e; end; r; end
end
def sexp str; Sexp.new(str).body; end
@vidarh
vidarh / loader.rb
Created November 10, 2021 15:05
Prototype loader for GtkSourceView themes into Rouge
#
# # Theme loader
#
# Tries to load different types of themes
#
require 'nokogiri'
module ThemeLoader
include Rouge::Token::Tokens