Skip to content

Instantly share code, notes, and snippets.

View Thomascountz's full-sized avatar
💃
LGTM!

Thomas Countz Thomascountz

💃
LGTM!
View GitHub Profile
@Thomascountz
Thomascountz / ijq.sh
Last active January 31, 2025 23:53
(Yet another) interactive jq, but it's a bash script using fzf
#!/usr/bin/env bash
set -euo pipefail
if [ "${1:-}" = "--help" ]; then
cat << EOF
Usage: ijq [filename]
A wrapper around jq that uses fzf to interactively build jq filters.
@Thomascountz
Thomascountz / progress.rb
Created January 2, 2025 19:30
Progress bar in Ruby
def print_progress(title, total, current_progress, bar_width: 50)
progress_pct = (current_progress.to_f / total) * bar_width
printf("\r#{title}: [%-#{bar_width}s ] -- %s", "▤" * progress_pct.round, "#{current_progress}/#{total} ")
end
# Usage
1.upto(10) do |i|
print_progress("Here we go!", 10, i)
sleep 0.2
end;print("\n")
@Thomascountz
Thomascountz / models_to_erd.rb
Last active July 30, 2024 14:42
Turn your ApplicationRecord models into a Mermaid ERD
Rails.application.eager_load!
# Instead of all ApplicationRecord descendants, you can
# make an Array of only the models you care about
data = ApplicationRecord.descendants.each_with_object({}) do |model, data|
model_name = model.name.upcase
data[model_name] = {
columns: model.columns.map { |column| [column.name, column.sql_type] },
associations: model.reflect_on_all_associations.each_with_object({}) do |reflection, assoc_data|
assoc_data[reflection.name] = {
@Thomascountz
Thomascountz / laser_cut_test_card.svg
Created December 5, 2023 19:06
Laser Cut Test Card
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Thomascountz
Thomascountz / async_http_client.py
Last active October 25, 2023 13:43
AsyncHttpClient is an asyncio-based MicroPython library, designed for asynchronous, concurrent HTTP/HTTPS requests to avoid blocking the execution of other coroutines.
# v0.1
import usocket as socket
import ussl
import uasyncio as asyncio
import ujson as json
from utime import ticks_ms, ticks_diff
class AsyncHttpClient:
"""
@Thomascountz
Thomascountz / closures.md
Created August 7, 2023 01:23
Closures in Ruby

🚀 Let's explore Closures in #Ruby with a space-themed example! 🌌 #ThomasTip

Closures are functions/methods that can be invoked from other functions or methods, while retaining access to variables from their original scope.

def launch_sequence(seconds)
  start = Time.now
  -> do
    elapsed = Time.now - start
 remaining = seconds - elapsed.round
@Thomascountz
Thomascountz / hash_struct_data_class_benchmark.rb
Created August 4, 2023 18:45
Ruby Hash v. Struct v. Data v. Class
require 'benchmark/ips'
PointStruct = Struct.new(:x, :y, :grayscale)
PointData = Data.define(:x, :y, :grayscale)
class PointClass
attr_accessor :x, :y, :grayscale
def initialize(x, y, grayscale)
73d3a42b29e14f6ddeb56cee824957ee6cfaa5f95a3c3a205f102147288c3661a4ea95b6025dc788deb1f79b09552e75cab662ee432fcf0041a290f80a6f45cd0ad26fc0ab8fc49fa062e1ac81f4c5cfd99e4f695e7b349c008c2744e0637d79a1f25b1ef4b580655a7559617a4e1c104a98deefa265d5cee5471043bba9f57d8b46f3d166d98077b70bf729598b9d8fe063002befc47aa49cd14757ec80e4e93d3b934d2ad3ae80ea0ecd4d91e4f0d73374f6277f2776ca1e9560cc5111a6ef1dd363944c9430d2c894a6a4c09bedf4a59dcc91d00c9c96a122252bd127655e18e494d19b397b5030f9ca603788dbeb3cd1f1fefc5e4f7f1d178d7c714cd90623f0ac3eef0bf6a32dca69c20787e1576f1e7fa9bc7ae0249c4cc16624e594c5c05f1785ba3afe2fa9fee6f2b05b2300ceb59c35d91018bb924f0b430c3e843a0d9023503edc5adb335f71311841faa772c721dc4111ae045330ba53bdf4036a09c8273551b27ef7df82c29f899facbc7722d86c9479fa5e5b7dca0600512fc6f89b7885f2a63e0af36ccdc433576c868ff6792e6bbcfd2eb606c356c3be1e26876196f5b73349c5088686b4731f05fb1dd76069d04a92f1c5968614fafa71efa4bb6863db3e2bbd08945a776aa15f0861afacca64842077546c7c979d9e4620b34ea2fdbd20c2fec4c5658ba7663f1e5c673413e75c4f267f003c7f5261c04a
@Thomascountz
Thomascountz / rails_new_dev.sh
Last active April 21, 2023 11:53
Creating a new Rails app using locally checked-out code.
# Fork rails/rails on Github
> git clone gem https://github.com/thomascountz/rails.git
Cloning into 'rails'...
> cd rails
# Checkout SHA prior to the merge commit and create a new branch
> git checkout -b practice-pr-46683 59fe981^
Switched to a new branch 'practice-pr-46683'
@Thomascountz
Thomascountz / why_null_sql_text.md
Created September 14, 2022 12:50
Why is SQL_TEXT NULL?

This is an example of selecting * that will need to execute for more than the set timeout of 1ms.

mysql> select * /*+ MAX_EXECUTION_TIME(1) */ from test_table;
ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

mysql> select thread_id,event_name,sql_text,digest_text,current_schema,mysql_errno,returned_sqlstate,message_text,errors from performance_schema.events_statements_history where mysql_errno = 3024 limit 1\G
*************************** 1. row ***************************
        thread_id: 345
       event_name: statement/sql/select