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
const sublistsOf = (list, number) => { | |
const result = []; | |
let aux = []; | |
list.forEach(el => { | |
if (aux.length >= number) { | |
result.push(aux); | |
aux = []; | |
} | |
aux.push(el); |
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 Result | |
def initialize(options = {}) | |
@success = options[:success] || false | |
@error = options[:error] | |
@result = options[:result] | |
end | |
def success? | |
@success | |
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
# Helper classes | |
class String | |
def colorize(color_code) | |
"\e[#{color_code}m#{self}\e[0m" | |
end | |
def red | |
colorize(31) | |
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 BaseCommand | |
def initialize(params: {}, context: {}) | |
@params = params | |
@context = context | |
end | |
def call; end | |
def undo; 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_relative 'pascal_triangle' | |
class PascalMath | |
def initialize | |
@triangle = PascalTriangle.new | |
end | |
def binomial_power(a, b, n) | |
coefficients = @triangle.get_file(n) |
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 ChangeVersionType < ActiveRecord::Migration[5.2] | |
def up | |
add_column :schema_migrations, :version2, :string | |
versions = ActiveRecord::Base.connection.execute('SELECT * FROM schema_migrations').to_a | |
versions.each do |version| | |
ActiveRecord::Base.connection.execute("UPDATE schema_migrations SET version2 = '#{version['version']}' WHERE version = '#{version['version']}'") | |
end | |
remove_column :schema_migrations, :version, :string |
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
#!/bin/sh | |
mkdir .githooks | |
curl https://gist.githubusercontent.com/alebian/d7b3e18549599cacec3f16621c67e6f5/raw/pre-push.sh > .githooks/pre-push | |
chmod u+x .githooks/pre-push | |
git config core.hooksPath ./.githooks |
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 ruby | |
def checkout_to_master_and_delete_current_branch | |
current_branch = `git rev-parse --abbrev-ref HEAD`.strip | |
`git checkout master` | |
puts "Deleting branch #{current_branch}" | |
`git branch -D #{current_branch}` | |
puts "Fetching master" | |
`git fetch -p` | |
puts "Pulling master" |
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 DatabaseRowStream | |
include Enumerable | |
BATCH_SIZE = 20_000 | |
def initialize(sql, options = {}) | |
@sql = sql | |
if options[:pluck] | |
@pluck = options[:pluck].respond_to?(:join) ? options[:pluck].join(', ') : options[:pluck] | |
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 Retryer | |
def initialize | |
@retry_times = 3 | |
@block = Proc.new {} | |
@args = nil | |
@backoff = false | |
end | |
def block(&block) | |
@block = block |
NewerOlder