Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Gedge thegedge

View GitHub Profile
@thegedge
thegedge / group_methods.rb
Created Sep 4, 2020
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 Jul 25, 2020
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 Sep 7, 2020
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 Apr 11, 2020
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
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
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 Jan 9, 2020
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 Nov 23, 2016
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
@thegedge
thegedge / thunderstorm_timelapse.py
Created Aug 7, 2016
Produces a timelapse video of a thunderstorm with an emphasis on lightning
View thunderstorm_timelapse.py
#!/usr/bin/env python
import cv2
import os.path
import sys
import tqdm
def frames(reader, indices=None, desc=None):
frame_count = int(reader.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
if indices is None:
indices = xrange(0, frame_count)
@thegedge
thegedge / native_libs.rb
Last active Jun 16, 2016
Read -l flags from Makefiles for gems with native extensions
View native_libs.rb
require 'set'
libs = Set.new
Gem::Specification.reject { |spec| spec.extensions.empty? }.each do |spec|
spec.extensions.each do |ext_path|
extconf_rb_path = Pathname.new(spec.gem_dir).join(ext_path)
makefile_path = extconf_rb_path.dirname.join('Makefile')
if makefile_path.readable?
last_was_lib_flag = false
makefile_path.readlines.map(&:strip).each do |line|
You can’t perform that action at this time.