Skip to content

Instantly share code, notes, and snippets.

View apainintheneck's full-sized avatar

Kevin apainintheneck

View GitHub Profile
@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
@apainintheneck
apainintheneck / incorrect_caveats.txt
Created April 23, 2023 08:21
The caveats functions that don't currently work the Homebrew JSON API.
[./Formula/gawk.rb]
def caveats
on_macos do
<<~EOS
GNU "awk" has been installed as "gawk".
If you need to use it as "awk", you can add a "gnubin" directory
to your PATH from your ~/.bashrc and/or ~/.zshrc like:
PATH="#{opt_libexec}/gnubin:$PATH"
EOS