Code Snippets Crystal

Short texts Crystal 🧑‍💻 Code snippets Crystal ✍️ Reading lists Crystal 👀

Simple OpenGL test in Crystal

require “lib_gl” require “crystglfw” include CrystGLFW vertex_shader = “#version 330 core\n layout (location = 0) in vec3 aPos;\n void main()\n {\n gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n }\n” vertex_shader_ptr = vertex_shader.to_unsafe vertexShader = LibGL.create_shader(LibGL::VERTEX_SHADER) LibGL.shader_source(vertexShader, 1, pointerof(vertex_shader_ptr), nil) LibGL.compile_shader(vertexShader) fragment_shader = “#version 330 core\n out vec4 FragColor;\n void main()\n {\n FragColor = vec4(1.0f, 0.5f, 0.2f, […]

cve_repl.cr

require “json” # https://csrc.nist.gov/schema/nvd/feed/1.1/nvd_cve_feed_json_1.1.schema record CVE_Response, resultsPerPage : Int32, startIndex : Int32, totalResults : Int32, result : CVE_Result do include JSON::Serializable end record CVE_Result, cve_data_type : String, cve_data_format : String, cve_data_version : String, cve_data_numberOfCVEs : String?, cve_data_timestamp : String, cve_Items : Array(CVE_Item) do include JSON::Serializable @[JSON::Field(key: “CVE_data_type”)] property cve_data_type : String @[JSON::Field(key: “CVE_data_format”)] property cve_data_format […]

cve_records.cr

require “json” # https://csrc.nist.gov/schema/nvd/feed/1.1/nvd_cve_feed_json_1.1.schema record CVE_Response, resultsPerPage : Int32, startIndex : Int32, totalResults : Int32, result : CVE_Result do include JSON::Serializable end record CVE_Result, cve_data_type : String, cve_data_format : String, cve_data_version : String, cve_data_numberOfCVEs : String?, cve_data_timestamp : String, cve_Items : Array(CVE_Item) do include JSON::Serializable @[JSON::Field(key: “CVE_data_type”)] property cve_data_type : String @[JSON::Field(key: “CVE_data_format”)] property cve_data_format […]

mulitple dispatch to an option class in crystal

abstract class Option alias DefaultType = Int32 | Bool | Nil @default : DefaultType getter :default def self.create(cls : Class? = nil, default : DefaultType = nil) if cls # we have class, so use that cls.new(default) else # no class, so attempt to get class from default case default in Int32 IntOption.new(default) in Bool […]

Visualizing the unofficial autobahn API into the Elastic Stack

# autobahn-api-to-es # # Indexes autobahn API metadata into Elasticsearch to use it with Kibana Maps # # Original API description https://gist.github.com/LilithWittmann/06bd153317b635e7b622651f5cfd95ea # # # MIT License # # Copyright (c) [2021] # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files […]