Skip to content

Instantly share code, notes, and snippets.

View joseluistorres's full-sized avatar
🤠
Como te ves me vi, como me veo te verás...

JoséLuis Torres joseluistorres

🤠
Como te ves me vi, como me veo te verás...
View GitHub Profile
class Node
attr_accessor :children, :size
def initialize
@children = {}
@size = 0
end
def find_count(word, index)
return @size if index == word.length
@joseluistorres
joseluistorres / cheat_sheet_docker_go.txt
Created March 6, 2017 22:23
Docker for Go and RethinkDB
# Running rethinkdb from docker
docker run --name whatever-chido-name -v "$PWD:/data" -d rethinkdb
# Build the docker image with the go app
docker build -t compa .
# This will start the previous container and will link
# the two containers to communicate from each other
docker run --name mi-compa-running -p 8000:8000 --link elated_bassi -d compa
@joseluistorres
joseluistorres / cheat_sheet_ruby.md
Created February 27, 2017 16:25
Cheat Sheet Ruby operations

Slice an array

arr_new = arr_new.slice(0, len - 1)

Insert a new item at the begginning of the array

arr_new.unshift(last_item)

Find number of occurrences of a substring in a string

require 'mail'
require 'thread'
require 'parallel'
require 'benchmark'
Mail.defaults do
delivery_method :smtp, options
end
class FailingWorker < Processable::Base
include Processable::HandlerRetries
sidekiq_retries_exhausted do |msg|
handle_retries_exhausted(msg)
end
def self.handle_retries_exhausted(msg)
p "===========================Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}************************"
@joseluistorres
joseluistorres / run_rake_rails_consoler.rb
Created May 25, 2016 19:48
run a rake from rails console
require 'rake'
MyRailsApp::Application.load_tasks # <-- MISSING LINE
Rake::Task['my_task'].invoke
@joseluistorres
joseluistorres / establish_connection.rb
Created May 24, 2016 19:53
Run a custom query function from rails console to another DB
# whenever you need to do a custom query/function/sproc into another DB that is not development
app = ActiveRecord::Base.establish_connection(
adapter: "mysql",
host: "localhost",
username: "myuser",
password: "mypass",
database: "somedatabase"
)
# if you have already defined an entry in database.yml
# -------------- READ THIS TOO ---------------------------------
@joseluistorres
joseluistorres / ultimo-taco.rb
Created January 24, 2014 15:24
Herencia - Parte 6
class Tripita < Taco
attr_reader :tripita_dorada, :frijolitos
def inicializa_despues(args)
@tripita_dorada = args[:tripita_dorada]
@frijolitos = args[:frijolitos]
end
def otras_verduras
{ frijolitos: frijolitos}
@joseluistorres
joseluistorres / Taco-re.rb
Created January 24, 2014 15:23
Herencia - Parte 5
class Taco
attr_reader :maiz_o_harina, :cebolla, :cilantro
def initialize(args)
@maiz_o_harina = args[:maiz_o_harina]
@cebolla = args[:cebolla] || con_cebolla
@cilantro = args[:cilantro] || con_cilantro
inicializa_despues(args)
end
@joseluistorres
joseluistorres / mas-tacos.rb
Created January 24, 2014 15:22
Herencia - Parte 4
class Pastor < Taco
attr_reader :salsa
def initialize(args)
@salsa = args[:salsa]
super(args)
end
end
class Pescado < Taco