Skip to content

Instantly share code, notes, and snippets.

View carlossanchezp's full-sized avatar

Carlos Sánchez Pérez carlossanchezp

View GitHub Profile
# Algorithm maxmimal Bron Kerbosch
class Algorithm
def initialize(graph)
@graph = graph
end
def bron_kerbosch(noder, nodep, nodex)
return if nodep.nil? || nodex.nil?
puts ' ' + noder.sort.join(' ') if maximal_clique?(nodep, nodex)
module Scripts::MigrateBigData
def self.bulk_big_data_to(table_origin,table_destination, date)
start_proc = Time.now
con_sql = ActiveRecord::Base.connection()
if !con_sql.table_exists?(table_destination.to_sym)
con_sql.execute("CREATE TABLE #{table_destination} like #{table_origin}")
con_sql.execute("alter table #{table_destination} change order_id order_id integer(15)")
puts "First step remove all index for speed..."
con_sql.execute("alter table #{table_destination} drop index index_spree_order_events_on_order_number")
@carlossanchezp
carlossanchezp / example_message.rb
Created March 20, 2020 12:42
Example messages reading
class Api::V1::Chapters::MessagesController < Api::V1::ApiController
before_action :set_chapter, only: :index
before_action :set_current_user_from_token, only: :index
before_action :set_or_create_guest_from_identifier, only: :index
before_action :check_if_max_messages_exceeded, only: :index
before_action :increment_messages_count, only: :index
api :GET, '/v1/chapters/:chapter_id/messages', "Messages from chapter (with pages)"
param_group :app_headers, Api::V1::ApiController
param :story_id, Integer, required: true
Redis only stores strings as values. If you want to store an object, you can use a serialization mechanism such as JSON:
require "json"
redis.set "foo", [1, 2, 3].to_json
# => OK
JSON.parse(redis.get("foo"))
# => [1, 2, 3]
Rails.redis.get(key)
Rails.redis.set(key, value)
Rails.redis.expire(key, 1.hour)
Rails.redis.del(key)
Rails.redis.sadd(set_name, value)
Rails.redis.srem(set_name, key)
Rails.redis.sismember(set_name, value) # boolean test to see if val exists
module RowUtils
extend ActiveSupport::Concern
FILE_HEADERS = %W(ID_PAIS ID_PROVINCIA ID_POBLACION ID_PROVEEDOR ID_ESPECIALIDAD ID_GRUPO ID_INFRAESTRUCTURA ID_TIPO_PROVEEDOR ID_COD_POSTAL ID_CENTRO_HIS ID_SERVICIO_HIS ID_SEXO ID_PROFESIONAL ID_SEXO_PROF ID_IDIOMA ID_EXCEPCION ID_AMBITO ID_TIPO_EXCEPCION ID_CAMPO ID_EQUIPO SW_JEFE_EQUIPO NUM_TELEFONO OBS_TELEFONO DESC_PROVINCIA DESC_POBLACION ID_TRATAMIENTO DESC_TRATAMIENTO DESC_PROVEEDOR DESC_ESPECIALIDAD DESC_GRUPO DESC_TIPO_PROVEEDOR RAZON_SOCIAL DESC_DOMICILIO DESC_HORARIO DESC_PROFESIONAL ID_TRATAMIENTO_PROF DESC_TRATAMIENTO_PROF DESC_IDIOMA EXCEPCION F_ALTA ID_CITACION CX CY ORDEN ID_TIPO_PERSONA)
included do
FILE_HEADERS.each do |header|
define_method header.underscore do
value = self[header]
value =~ /^\d+$/ ? value.to_i : value
@carlossanchezp
carlossanchezp / readgemfilelock
Created June 1, 2014 20:47
Read Gemfile.lock
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler'
require 'fileutils'
require 'net/http'
require 'net/https'
require 'uri'
TMP_DIR = "/tmp/gems"
@carlossanchezp
carlossanchezp / withorwithoutIF
Created April 2, 2014 21:16
The best way to do with or without IF:
This way with if
S.find(:all).each do |each|
if each.expired?
each.renew!
else
each.update!
end
end
@carlossanchezp
carlossanchezp / gist:9475926
Created March 10, 2014 22:35
Métodos de clase y métodos de instancia
1) Sin herencia métodos de clase y de instancia
===============================================
class Foo
def self.some_class_method
puts self
end
def some_instance_method
puts self.class
@carlossanchezp
carlossanchezp / numeric_method_missing
Last active August 29, 2015 13:57
Solución con Method Missing
1) Solución con método de clase
class Numeric
CURRENCIES = {dollar: 1, yen: 0.013, euro: 1.292, rupee: 0.019} "Para versiones superiores a la 1.9 de Ruby"
CURRENCIES = {:dollar => 1, :yen => 0.013, :euro => 1.292, :rupee => 0.019}
def euros
self * CURRENCIES[:euro]
end