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 'bundler' | |
lockfile = Bundler::LockfileParser.new(Bundler.read_file('Gemfile.lock')) | |
specs = lockfile.specs | |
gems_hash = Hash.new.tap do |h| | |
specs.each do |s| | |
h[s.name] = { | |
spec: s, | |
dependencies: s.dependencies.map(&:name) |
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/perl | |
use strict; | |
use warnings; | |
use 5.014; | |
=head1 NAME | |
Rails Assets Coverage |
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
# https://en.wikipedia.org/wiki/Riemann_sum | |
class RiemannSum | |
def initialize(f, v_start, v_end, n_step) | |
@f = f | |
@v_start = v_start | |
@v_end = v_end | |
@n_step = n_step | |
@step_size = (v_end - v_start) / (n_step * 1.0) | |
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 NewtonsMethod | |
def initialize(f_proc, f_prime_proc) | |
@fp = f_proc | |
@fpp = f_prime_proc | |
end | |
def apply(x) | |
x - (@fp.call(x) / (@fpp.call(x) * 1.0)) | |
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
# https://it.wikipedia.org/wiki/Partita_IVA#Struttura_della_partita_IVA | |
module ChecksumCalculation | |
def calculate(ary) | |
(10 - t(ary)) % 10 | |
end | |
private | |
def t(ary) | |
odd, even = separate_odd_even(ary) |
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
# source: https://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Ruby | |
class Array | |
def quick_sort | |
h, *t = self | |
h ? t.partition { |e| e < h }.inject { |l, r| l.quick_sort + [h] + r.quick_sort } : [] | |
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
require 'rails_helper' | |
require 'representable/json' | |
require 'representable/json/collection' | |
class Song < OpenStruct | |
end | |
# Ex. 1 using standalone collections | |
class SongRepresenter < Representable::Decorator | |
include Representable::JSON |
NewerOlder