Skip to content

Instantly share code, notes, and snippets.

View thegedge's full-sized avatar

Jason Gedge thegedge

View GitHub Profile
@thegedge
thegedge / bench-mobx.ts
Last active September 26, 2023 17:22
MobX benchmark
View bench-mobx.ts
import { makeAutoObservable, makeObservable, observable } from "mobx";
import { DataModel, Model, model, prop } from "mobx-keystone";
import { types } from "mobx-state-tree";
function bench(f: () => { value: number }) {
// Warmup
let sum = 0;
for (let index = 0; index < 100_000; ++index) {
sum += f().value;
}
@thegedge
thegedge / bench_template_engines.ts
Created September 27, 2021 19:19
Benchmarking pure JS + top three templating engines on NPM
View bench_template_engines.ts
import { Event, Suite } from "benchmark";
import * as ejs from "ejs";
import * as handlebars from "handlebars";
import * as nunjucks from "nunjucks";
const DATA = {
greeting: "Hello",
things: [
{ name: "Test", color: "red" },
{ name: "Boat", color: "blue" },
@thegedge
thegedge / group_methods.rb
Created September 4, 2020 20:37
Group methods together that are called together
View group_methods.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# Output a grouping of methods (within a file) such that for each group G, and any method m ∈ G:
# - ∃ x ∈ G such that x calls m, or
# - no other method in all groups calls m
#
# The output is a kind of "function cohesion", where you can find groups of methods that are related.
# This is useful when trying to find what you need to extract from a file.
@thegedge
thegedge / locations.md
Last active July 25, 2020 15:43
nushell completion locations
View locations.md

Completion locations

Command head

Completion types:

  • Internal commands and subcommands
  • External commands
  • Files (executable)

Location(s):

@thegedge
thegedge / git-tophat
Last active April 8, 2021 07:54
A git subcommand to "tophat" (build/run/test) a PR from a fork
View git-tophat
#!/bin/zsh
function main {
if [[ ! "$1" =~ ".*:.*" ]]; then
echo "Empty username or branch name: \`$1\` should be of the form \`user:branch\`"
exit 1
fi
local username="${1%:*}"
local branch="${1#*:}"
@thegedge
thegedge / complexity_churn.rb
Created April 11, 2020 19:11
A Ruby script to compute complexity/churn stats on a codebase
View complexity_churn.rb
#!/usr/bin/env ruby
require "flog"
require "open3"
def capture_output(cmd, *args)
stdout, stderr, status = Open3.capture3(cmd, *args)
return stdout if status.success?
STDERR.puts("Failed to run git #{args.join(" ")}")
@thegedge
thegedge / find_cohesive_changes.rb
Last active May 14, 2020 13:42
Attempt to find cohesive sets of methods in a Ruby file, based on how it's changed with other files in a repo
View find_cohesive_changes.rb
#!/usr/bin/ruby --disable-gems
#
# # Prerequisites
#
# # Example usage
#
# find_cohesive_changes <file>
#
require "open3"
@thegedge
thegedge / find_unused_methods.rb
Last active May 19, 2020 08:17
Find unused Ruby methods (expect false positives) via static analysis
View find_unused_methods.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require "csv"
require "set"
begin
require "erubi"
rescue LoadError
end
@thegedge
thegedge / graph_mutual_changes
Created January 9, 2020 15:21
Standalone script to read git history, and render a graph showing files that change together
View graph_mutual_changes
#!/usr/bin/ruby --disable-gems
#
# # Prerequisites
#
# - ghostscript
# - graphviz
#
# # Example usage
#
# graph_mutual_changes --clustering=package --since="6 months ago" && open graph.pdf
@thegedge
thegedge / profile-curl.sh
Created November 23, 2016 23:01
Run a series of curl requests and profile the mean / std. dev. of those requests
View profile-curl.sh
#!/bin/bash
profile-curl() {
local num_iters=500
local num_warmups=10
local -a times
for x in $(seq 1 "${num_warmups}"); do
curl -s -o /dev/null "$@" 2>&1
done