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 ---------------------------------
defmodule Ph_14Version.Field do
use Ph_14Version.Web, :model
use Ecto.Model.Callbacks
before_insert :set_map_coords
schema "fields" do
field :name, :string
field :map_coords, Geo.MultiPolygon
@joseluistorres
joseluistorres / tests_controller.rb
Created September 15, 2014 20:55
then I want a method that is executed for create / edit actions, that use @my_var1, and can set variables available in the view.
class TestsController < ApplicationController
before_filter :execute_me, :only => :index
def index
@my_var2 = translate_me('ES', @my_var)
end
private
def execute_me
@joseluistorres
joseluistorres / geometry_error.sql
Last active August 29, 2015 14:01
public.geometry(MultiLineString,3857) does not exist
-- If you have an error running a query with geometry in Postgresql
CREATE TABLE "some_random_table" (
"id" int4 NOT NULL,
"map_coords" "public"."geometry(MultiLineString,3857)",
"col3" int4 NOT NULL,