This file contains 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 bash | |
# Based on https://github.com/spinningarrow/git-coauthors/ | |
# Runs "git commit" and initializes the commit editor with a co-authorship trailer | |
# matching the argument you provided. Will only search past commiters to the current | |
# repo and branch. | |
# | |
# $ pair-commit melba | |
# -> Opens up commit editor populated with the following trailer: |
This file contains 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
class Trie < Hash | |
def initialize | |
# Ensure that this is not a special Hash by disallowing | |
# initialization options. | |
super | |
end | |
def add(string) | |
string.chars.inject(self) do |trie, char| | |
trie[char] ||= Trie.new |
This file contains 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
include Quicksort | |
RSpec.describe 'Quicksort' do | |
describe '#partition!' do | |
it 'partitions the p..r subarray around a pivot' do | |
array = [9, 7, 5, 11, 12, 2, 14, 3, 10, 4, 6] | |
pivot = partition!(array, 0, array.length - 1) | |
expect(pivot).to eq(4) | |
expect(array).to eq([5, 2, 3, 4, 6, 7, 14, 9, 10, 11, 12]) |
This file contains 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
module Quicksort | |
module_function | |
# Sorts in place the subarray of `array` from index `first` | |
# to index `last`, inclusive. | |
# | |
# @param array [Array] the array to be (partially) sorted | |
# @param first [Integer] the left index of the subarray to be sorted | |
# @param last [Integer] the right index of the subarray to be sorted | |
# @return [Array] the sorted array |
This file contains 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
# ### | |
# # OVERVIEW | |
# ### | |
# | |
# Monkey patch of Grape DSL to augment behavior in cases where | |
# we are presenting lists of objects of different types. The | |
# primary use case for this is the presentation of lists of | |
# records that inherit from an abstract parent, i.e. single- | |
# table inheritance. | |
# |
This file contains 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
class MyClass | |
def foo_via_method | |
p "Superclass Chain: #{self.class.ancestors}" | |
p "Lexical Scope Chain: #{Module.nesting}" | |
foo_method | |
end | |
def foo_via_constant | |
p "Superclass Chain: #{self.class.ancestors}" | |
p "Lexical Scope Chain: #{Module.nesting}" |
This file contains 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 WORKS | |
SubClass.new.foo_via_method | |
# => "foo" | |
# THIS DOESN'T | |
SubClass.new.foo_via_constant | |
# NameError: uninitialized constant MyClass::FOO_CONSTANT |
This file contains 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
class StarsController < StoryBooleansController | |
STORY_BOOLEAN = :starred | |
end |
This file contains 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
class StarsController < StoryBooleansController | |
private | |
def story_boolean | |
:starred | |
end | |
end |
This file contains 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
class StoryBooleansController < BaseController | |
def create | |
update_story(story_boolean => true) | |
end | |
def destroy | |
update_story(story_boolean => false) | |
end | |
private |
NewerOlder