Skip to content

Instantly share code, notes, and snippets.

View joeldrapper's full-sized avatar
🇺🇦
Slava Ukraini

Joel Drapper joeldrapper

🇺🇦
Slava Ukraini
View GitHub Profile
@joeldrapper
joeldrapper / squircle.css
Created May 21, 2025 12:38
Tailwind squircle mask
@utility mask-squircle-1 {
mask: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'%3e%3cpath d='M 0,0.5 C 0,0 0,0 0.5,0 1,0 1,0 1,0.5 1,1 1,1 0.5,1 0,1 0,1 0,0.5'/%3e%3c/svg%3e");
}
@utility mask-squircle-2 {
mask: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'%3e%3cpath d='M 0,0.5 C 0,0.0575 0.0575,0 0.5,0 0.9425,0 1,0.0575 1,0.5 1,0.9425 0.9425,1 0.5,1 0.0575,1 0,0.9425 0,0.5'/%3e%3c/svg%3e");
}
@utility mask-squircle-3 {
mask: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'%3e%3cpath d='M 0,0.5 C 0,0.115 0.115,0 0.5,0 0.885,0 1,0.115 1,0.5 1,0.885 0.885,1 0.5,1 0.115,1 0,0.885 0,0.5'/%3e%3c/svg%3e");
@joeldrapper
joeldrapper / fuzzy_index.rb
Created March 27, 2025 11:20
Simple fuzzy index with left weight
class FuzzyIndex
def initialize
@index = Hash.new { |h, k| h[k] = Set.new }
end
def []=(key, value)
trigrams(key).each { @index[it] << [key, value] }
end
def [](query)
@joeldrapper
joeldrapper / gravatar.rb
Created October 3, 2024 23:30
Private server-side fetched async gravatar component in Phlex
# frozen_string_literal: true
class Components::Gravatar < Ode::Base
include Flecks
prop :size, Integer, default: 80
prop :alt, String
prop :email, String do |value|
value.to_s.strip.downcase
end
@joeldrapper
joeldrapper / keymap.json
Last active March 27, 2025 23:43
My Zed Config
[
{
"context": "Editor",
"bindings": {
"alt-up": "editor::SelectLargerSyntaxNode",
"alt-down": "editor::SelectSmallerSyntaxNode",
"ctrl-cmd-up": "editor::MoveLineUp",
"ctrl-cmd-down": "editor::MoveLineDown"
}
}
@joeldrapper
joeldrapper / murmur.rb
Created May 13, 2024 12:09
Murmur hash in pure Ruby
module Murmur
MASK32 = 0xffffffff
def self.hash(str, seed = 0)
# Initialize variables
# h1: The main hash value that will be iteratively updated
# k1: A temporary value used to process chunks of 4 bytes
# i: Counter to keep track of the number of bytes processed
h1 = seed
k1 = 0
@joeldrapper
joeldrapper / example.rb
Last active January 25, 2024 06:57
Table component
render TableComponent.new(@posts) do |t|
t.column("Title", &:title)
t.column("Author") { |post| post.author.name }
end
@joeldrapper
joeldrapper / fingerprinting.rb
Created January 10, 2024 14:30
Rails request fingerprinting concern
# frozen_string_literal: true
module Fingerprinting
def full_fingerprint
generate_fingerprint(
ip_fingerprint,
browser_fingerprint
)
end
@joeldrapper
joeldrapper / accordion_of_types.rb
Created November 29, 2023 14:44
Accordion of Literal types
# Okay
class Foo < Literal::Data
attribute :sizes, Array
end
# Better
class Foo < Literal::Data
attribute :sizes, Array(Symbol)
end
@joeldrapper
joeldrapper / packer.rb
Last active July 12, 2023 12:58
Paquito Job Packer
# frozen_string_literal: true
module Packer
# A special packer class for globally identifiable objects. It takes a global ID and packs it as a String, then rehydrates it as a GlobalID lookup.
class GloballyIdentifiable
def self.from_pack(uri)
GlobalID::Locator.locate(uri)
end
def initialize(identifiable)
@joeldrapper
joeldrapper / freeze.rb
Created April 17, 2023 14:49
Enforce frozen string literals when possible and output a list of problematic files
#!/usr/bin/env ruby
class Run
def initialize(files)
@files = files
end
def call
@files.each(&:process)