Skip to content

Instantly share code, notes, and snippets.

View thegedge's full-sized avatar

Jason Gedge thegedge

View GitHub Profile
@thegedge
thegedge / find_unused_functions.rb
Last active May 25, 2016 00:25
Find (maybe) unused functions in Ruby
#!/usr/bin/env ruby
require 'optparse'
module CLI
extend self
PATHS_TO_CHECK = %w(app bin config engines lib script)
EXTENSIONS_TO_CHECK_FOR_DEFINITIONS = %w(.rb .rake)
EXTENSIONS_TO_CHECK_FOR_USAGE = EXTENSIONS_TO_CHECK_FOR_DEFINITIONS + %w(.yml .yaml .erb)
@thegedge
thegedge / native_libs.rb
Last active June 16, 2016 19:17
Read -l flags from Makefiles for gems with native extensions
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|
@thegedge
thegedge / thunderstorm_timelapse.py
Created August 7, 2016 21:26
Produces a timelapse video of a thunderstorm with an emphasis on lightning
#!/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 / profile-curl.sh
Created November 23, 2016 23:01
Run a series of curl requests and profile the mean / std. dev. of those requests
#!/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 / graph_mutual_changes
Created January 9, 2020 15:21
Standalone script to read git history, and render a graph showing files that change together
#!/usr/bin/ruby --disable-gems
#
# # Prerequisites
#
# - ghostscript
# - graphviz
#
# # Example usage
#
# graph_mutual_changes --clustering=package --since="6 months ago" && open graph.pdf
@thegedge
thegedge / complexity_churn.rb
Created April 11, 2020 19:11
A Ruby script to compute complexity/churn stats on a codebase
#!/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
#!/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
#!/usr/bin/env ruby
# frozen_string_literal: true
require "csv"
require "set"
begin
require "erubi"
rescue LoadError
end
@thegedge
thegedge / locations.md
Last active July 25, 2020 15:43
nushell completion locations

Completion locations

Command head

Completion types:

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

Location(s):

@thegedge
thegedge / group_methods.rb
Created September 4, 2020 20:37
Group methods together that are called together
#!/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.