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
multiline { | |
tags => ["rails"] | |
pattern => "^Started" | |
negate => true | |
what => "previous" | |
} |
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
RubyVM::InstructionSequence.compile_option = { | |
:tailcall_optimization => true, | |
:trace_instruction => false | |
} | |
RubyVM::InstructionSequence.new(<<-RUBY).eval | |
def acc(start_date, end_date, accu) | |
if start_date >= end_date | |
accu + [end_date] | |
else |
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
result = IO.popen(command, 'r+') do |io| | |
io.write(input) | |
io.close_write | |
io.read | |
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
require 'fibonacci_heap' | |
# Assuming `graph` is an object with the following interface that stores vertices as `FibonacciHeap::Node` | |
# instances and `source` is a `FibonacciHeap::Node`: | |
# | |
# * `graph.vertices`: return an Enumerable of all vertices in the graph | |
# * `graph.neighbours(u)`: return an Enumerable of all vertices that neighbour a given vertex `u` | |
# * `graph.length(u, v)`: return the numeric weight of the edge between two given vertices `u` and `v` | |
def dijkstra(graph, source) | |
dist = Hash.new(Float::INFINITY) |
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 CircularDoublyLinkedList | |
include Enumerable | |
class Node | |
include Comparable | |
attr_accessor :key, :next, :prev | |
alias right next | |
alias left prev |
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
# A pure Ruby implementation of https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm | |
# | |
# Takes a graph in hash form, e.g. { 'A' => ['B', 'C'], 'B' => ['D'], 'C' => ['D'] }, | |
# and a source node, e.g. 'A', and returns the distances to every reachable node and a hash of "next hops" for each node. | |
def dijkstra(graph, source) | |
q = graph.keys | |
prev = {} | |
dist = Hash.new(Float::INFINITY) | |
dist[source] = 0 |
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
# snitch = Snitch.new('A string') | |
#=> #<Snitch:0x00007fe53a1964b0 @obj="A string"> | |
# snitch.empty? | |
# Calling empty? on A string with [] | |
#=> false | |
class Snitch | |
attr_reader :obj | |
def initialize(obj) |
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
# Validate a UK postcode using a modified version of the official | |
# regular expression provided by | |
# http://www.govtalk.gov.uk/gdsc/schemaHtml/bs7666-v2-0-xsd-PostCodeType.htm | |
# | |
# @param [String] postcode the postcode to validate | |
# @return [Boolean] true if the postcode is valid, false if not | |
def is_valid_postcode?(postcode) | |
!!(postcode =~ /^\s*((GIR\s*0AA)|((([A-PR-UWYZ][0-9]{1,2})|(([A-PR-UWYZ][A-HK-Y][0-9]{1,2})|(([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))))\s*[0-9][ABD-HJLNP-UW-Z]{2}))\s*$/i) | |
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
require "pathname" | |
namespace :deploy do | |
task :create_symlink, :except => { :no_release => true } do | |
deploy_to_pathname = Pathname.new(deploy_to) | |
on_rollback do | |
if previous_release | |
previous_release_pathname = Pathname.new(previous_release) | |
relative_previous_release = previous_release_pathname.relative_path_from(deploy_to_pathname) |