Skip to content

Instantly share code, notes, and snippets.

View skull-squadron's full-sized avatar
💭
*aaS unreleased project in Elixir, Rust, Typescript, Kafka, and k8s

🏴‍☠️ skull-squadron

💭
*aaS unreleased project in Elixir, Rust, Typescript, Kafka, and k8s
  • (stealth)
  • ATX
  • 13:14 (UTC -06:00)
View GitHub Profile
@skull-squadron
skull-squadron / type_name.rs
Created May 19, 2025 20:31
Rust anything (as opposed to just `Any`) type's to string
pub trait TypeName {
fn type_name(&self) -> &str {
std::any::type_name::<Self>().trim_start_matches("dyn::")
}
}
impl<T> TypeName for T {}
#[cfg(test)]
mod tests {
@skull-squadron
skull-squadron / replace_str.rs
Last active May 20, 2025 04:30
Rust replace beginning of string generically
use std::borrow::Cow;
pub trait ReplaceBeginning<'a>: Into<Cow<'a, str>> {
fn replace_beginning(
self,
prefix: impl AsRef<str>,
replacement: impl AsRef<str>,
) -> Cow<'a, str> {
let new_self = self.into();
let prefix = prefix.as_ref();
@skull-squadron
skull-squadron / make_loop.rs
Created May 16, 2025 09:57
make_loop! Ruby while and until, and C for loop syntactic sugar
#[macro_export]
macro_rules! make_loop {
// do { ... } while cond
(
do $body:block while $cond:expr
) => {
loop {
$body
if !$cond { break; }
}
@skull-squadron
skull-squadron / fix.rb
Created May 16, 2025 04:52
Homebrew fix for macOS 15.4+ / clang 17+ zlib _stdio.h:314:7: error: expected identifier or '('
class NodeAT18 < Formula
# ...
def install
# Workaround clang 17+ breaking bug
if OS.mac? && DevelopmentTools.clang_build_version >= 1700
ENV.append_to_cflags "-fno-define-target-os-macros"
end
@skull-squadron
skull-squadron / install-sorbet-and-tapioca-on-macos.bash
Created May 16, 2025 00:51
Install sorbet and tapioca on macOS without failing
#!/usr/bin/env bash
# Because Shopify sucks at release engineering consistency and insists on imposing overly-complicated, nonstandard build systems
# Whoever did this, this is for you: ✨ 🖕 🖕 ✨
set -Eeuo pipefail
ver=$(curl -fsSL https://rubygems.org/gems/sorbet-static/versions | sed -E '/darwin/!d;s!</a>!!;s/.*>//' | sort -V | tail -1)
gem install sorbet-static-and-runtime -v "$ver"
gem install tapioca
# Gemfile
#
@skull-squadron
skull-squadron / sketch.ino
Created March 16, 2025 09:54
[Arduino] Properly debounced button class
// Arduino proper switch debouncing
// Based on https://docs.arduino.cc/built-in-examples/digital/Debounce
//
// Button libraries that do not work properly:
// - Button - doesn't debounce
// - EZButton - doesn't debounce
// - ezButton - laggy
// Arduino Nano 5V
// 5V pin -> Vcc
@skull-squadron
skull-squadron / sketch.ino
Created February 28, 2025 08:57
Keyestudio 4wd BT Car Lesson 17 Bluetooth Multifunctional Car KS0559
// *******************************************************************************
// Adapted from https://docs.keyestudio.com/projects/KS0559/en/latest/Arduino/arduino.html
/*
Keyestudio 4wd BT Car
Lesson 17
Bluetooth Multifunctional Car
http://www.keyestudio.com
*/
#define HAS_LED // Comment out if the LED module is not attached to D9
@skull-squadron
skull-squadron / ddg_bangs.rb
Last active February 7, 2025 13:17 — forked from nogweii/ddg_bangs.rb
get a list of all of duckduckgo's bangs in a programmatic manner, useful for scripting
# frozen_string_literal: true
require 'cgi'
require 'json'
require 'open-uri'
require 'yaml'
UA = 'Ruby script to read the full list of bangs/2.0 ; https://gist.github.com/skull-squadron/f53c38c678045660a36a5fcd1f50196a'
module Flow
@skull-squadron
skull-squadron / fix-aafire-aalib-gentoo.patch
Created October 29, 2024 02:36
Patch to make aafire from aalib to stablize frame rate
--- a/src/aafire.c
+++ b/src/aafire.c
@@ -2,4 +2,5 @@
#include <stdlib.h> /* exit() */
+#include <time.h>
#include "aalib.h"
#define XSIZ aa_imgwidth(context)
@@ -135,14 +136,29 @@ drawfire (void)
aa_scrheight (context));
@skull-squadron
skull-squadron / silence-ruby-3.3.5-rdoc-psych-warning.bash
Last active October 28, 2024 10:58
HACK Fix ruby 3.3.5 annoyance
#!/usr/bin/env bash
set -eEuo pipefail
# https://stackoverflow.com/questions/79015158/why-is-gem-clean-reporting-multiple-ambiguous-references-to-the-default-psych
# https://stackoverflow.com/q/79015158
targets() {
find "$(gem env home)"/specifications/default -name 'rdoc-*.gemspec'
}