Skip to content

Instantly share code, notes, and snippets.

@Blacksmoke16
Blacksmoke16 / .env
Last active February 23, 2024 04:08
Crystal Client code for publishing to a Mercure Hub
MERCURE_URL=http://localhost:8000/.well-known/mercure
MERCURE_JWT_SECRET=eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdLCJzdWJzY3JpYmUiOlsiaHR0cHM6Ly9leGFtcGxlLmNvbS9teS1wcml2YXRlLXRvcGljIiwie3NjaGVtZX06Ly97K2hvc3R9L2RlbW8vYm9va3Mve2lkfS5qc29ubGQiLCIvLndlbGwta25vd24vbWVyY3VyZS9zdWJzY3JpcHRpb25zey90b3BpY317L3N1YnNjcmliZXJ9Il0sInBheWxvYWQiOnsidXNlciI6Imh0dHBzOi8vZXhhbXBsZS5jb20vdXNlcnMvZHVuZ2xhcyIsInJlbW90ZUFkZHIiOiIxMjcuMC4wLjEifX19.KKPIikwUzRuB3DTpVw6ajzwSChwFw5omBMmMcWKiDcM
@Blacksmoke16
Blacksmoke16 / lib_c.cr
Last active March 26, 2024 17:42
OS Agnostic way to determine terminal height/width
{% if flag?(:win32) %}
lib LibC
STDOUT_HANDLE = 0xFFFFFFF5
struct Point
x : UInt16
y : UInt16
end
struct SmallRect
@Blacksmoke16
Blacksmoke16 / code.cr
Created June 16, 2022 01:29
XML2 XSD Schema validation
require "xml"
lib LibXML
type XMLSchemaParserCtxtPtr = Void*
type XMLSchemaValidCtxtPtr = Void*
struct XMLError
domain : Int
code : Int
message : UInt8*
@Blacksmoke16
Blacksmoke16 / entity_manager.cr
Last active December 15, 2021 17:58
Simple DB Abstractions
@[ADI::Register]
# Central access point to DB related actions
class Blog::Services::EntityManager
@@connection : DB::Database = DB.open ENV["DATABASE_URL"]
# Each entity has a Repository to store query methods
# Longer term ofc this could be made a bit better but manual overload for each works just fine.
#
# Could prob use a macro loop over entity and add overload if the repo type exists
def repository(entity_class : Blog::Entities::User.class) : Blog::Entities::User::Repository
@Blacksmoke16
Blacksmoke16 / test.cr
Last active January 4, 2024 01:09
Test Crinja + Athena integration
require "crinja"
ACF.configuration_annotation Template, name : String
@[ADI::Register]
class HTMLFormatHandler
include Athena::Framework::View::FormatHandlerInterface
private CRINJA = Crinja.new loader: Crinja::Loader::FileSystemLoader.new "#{__DIR__}/../views"