Skip to content

Instantly share code, notes, and snippets.

View apainintheneck's full-sized avatar

Kevin apainintheneck

View GitHub Profile
@apainintheneck
apainintheneck / docs.yml
Created January 16, 2024 04:30
Generate a documentation website on Github Pages for a Crystal project.
# This action does the following on a push to the `main` branch:
# 1. It generates the docs website with `crystal docs`.
# 2. It bundles that docs folder and pushes it to the `gh-pages` branch.
# 3. It deploys that branch to Github pages.
#
# First time setup:
# - Go into the Github settings and specify that the `gh-pages` branch
# should be deployed on Github pages.
name: Github Pages for Crystal Project
@apainintheneck
apainintheneck / generate-slim-json-sample.rb
Created January 7, 2024 17:57
Testing a slimmer JSON representation for Homebrew Formula.
#!/usr/bin/env brew ruby
# Related to: https://github.com/Homebrew/brew/pull/16433
sample = Homebrew::API::Formula.all_formulae.keys.sample(25)
formulae = sample.map { Formulary.factory(_1) }
json = formulae.map(&:to_hash_with_variations)
json = json.map { Homebrew::API::Formula.slim_hash(_1) }
json_string = JSON.pretty_generate(json)
outfile_path = File.expand_path("~/Desktop/slim-formula-sample.json")
File.write(outfile_path, json_string)
# Benchmarking things to explore `brew desc` without a cache.
# See: https://github.com/Homebrew/brew/issues/16237
Benchmark.bm do |x|
x.report("JSON") do
Homebrew::API::Formula.all_formulae
end
x.report("Ruby") do
CoreTap.instance.formula_files.map do |file|
@apainintheneck
apainintheneck / tyranny
Last active December 25, 2023 00:40
A blatant clone of the `choose` command written in awk.
#!/usr/bin/env sh
awk '
BEGIN {
TRUE = 1
FALSE = 0
arg_parse()
if(HELP) {
@apainintheneck
apainintheneck / brew_pkg_parser_profile.txt
Created December 16, 2023 21:03
Running a profile on the `parser` gem using the Homebrew package files as examples.
This file has been truncated, but you can view the full file.
*****************
* Homebrew/Core *
*****************
>>> Flat Profile
Measure Mode: wall_time
Thread ID: 80
Fiber ID: 60
Total: 736.246833
Sort by: self_time
@apainintheneck
apainintheneck / gitsh.awk
Created October 16, 2023 03:49
An experimental wrapper for Git that acts like a shell.
#!/usr/bin/env gawk -f
# Inspired by zbg
# We use gawk to allow next inside a function.
BEGIN {
if(!is_git_installed()) {
die("Git is not installed!")
}
if(!is_git_repo()) {
@apainintheneck
apainintheneck / ksink
Created September 4, 2023 17:19
A command line test runner to test everything but the kitchen sink.
#!/usr/bin/env awk -f
# Run `ksink` to see usage.
################################
# Main
################################
BEGIN {
parse_args()
@apainintheneck
apainintheneck / rsample
Last active September 4, 2023 17:19
rsample - reservoir sampling script in awk
#!/usr/bin/env awk -f
# Slight variation of this script: https://stackoverflow.com/a/48869665
BEGIN {
if (k !~ /^[1-9][0-9]*$/) {
help()
exit(0)
}
srand();
}
@apainintheneck
apainintheneck / benchmark-custom-homebrew-cops.rb
Created August 14, 2023 02:46
Benchmark custom cops used for linting in Homebrew.
# Script to manually run each custom cop individually to see if
# there are any very slow cops that can be improved on average.
#
# Note: This is very slow since each cop takes 20-50 seconds to run.
require "pathname"
require "benchmark"
unless system("brew --prefix > /dev/null")
raise "Missing: Brew is NOT installed locally since `brew --prefix` doesn't work."
@apainintheneck
apainintheneck / README.md
Created May 12, 2023 06:38
Testing the new service name DSL.

Overview

The idea here is to test the new service name DSL on the two formulae in homebrew/core that will need it right away. The xinit and dbus packages previously redefined the Formula#plist_name method which worked previously but now doesn't work at all with the API. To improve the situation and make it easier to serialize we're in the process of adding a new DSL.

service do
  plist_name "name"
  service_name "name"
end