This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# The purpose of this script is to extract all constant references from a given | |
# source file. It reads ARGF, which means you can either pass the content in | |
# through stdin or you can pass the file name as an argument. So for example, | |
# you can either: | |
# | |
# echo 'Foo::Bar' | ./constants | |
# | |
# or you can pass a file name, as in: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] } | |
source = JSON.dump(struct) | |
tokens = [] | |
index = 0 | |
until source.empty? | |
tokens << |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This is the opcode of the instruction. | |
enum Op { | |
Add, | |
Sub, | |
Mov, | |
} | |
/// This is a reference to a register. It is passed around when generating the | |
/// IR through the Assembler struct. When it gets loaded into an Insn struct as | |
/// part of a generated instruction, it is wrapped into an Opnd::Reg. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module ActiveRecord | |
class Migration | |
class MigrationError < StandardError | |
end | |
RenameColumn = Struct.new(:table_name, :column_name, :new_column_name, keyword_init: true) | |
RemoveColumn = Struct.new(:table_name, :column_name, keyword_init: true) | |
AddColumn = Struct.new(:table_name, :column_name, :type, :options, keyword_init: true) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words = [] | |
letters = ("a".."z").to_a | |
File.foreach("/usr/share/dict/words", chomp: true) do |word| | |
words << word.downcase if word.match?(/\A[a-z]{5}\z/i) | |
end | |
while words.length > 1 | |
weights = letters.to_h { |letter| [letter, 0] } | |
words.each do |word| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_constant_refs(iseq) | |
cached = false | |
iseq.last.each_with_object([]) do |insn, counts| | |
case insn | |
in [:opt_getinlinecache, *] | |
cached = true | |
counts << 0 | |
in [:getconstant, *] | |
counts[counts.length - 1] += 1 if cached |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'ripper' | |
# A Ripper parser that will replace usage of Sorbet patterns with whitespace so | |
# that location information is maintained but Sorbet methods aren't called. | |
class Eraser < Ripper | |
# Represents a line in the source. If this class is being used, it means that | |
# every character in the string is 1 byte in length, so we can just return the | |
# start of the line + the index. |
Feedback loop speed in one of the biggest contributing factors to overall development time. The faster you get results, the faster you can move on to other things. A fast enough test suite is therefore critical to teams' success, and is worth investing some time at the beginning to save in the long run.
Below is a list of techniques for speeding up a Rails test suite. It is not comprehensive, but should definitely provide some quick wins. This list of techniques assumes you're using minitest
, but most everything should translate over to rspec
by simply replacing test/test_helper.rb
with spec/spec_helper.rb
.