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
# 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) |
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
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") |
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 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 |
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
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] |
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
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 |
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
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 |
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 | |
require 'rubygems' | |
require 'bundler' | |
require 'fileutils' | |
require 'net/http' | |
require 'net/https' | |
require 'uri' | |
TMP_DIR = "/tmp/gems" |
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
This way with if | |
S.find(:all).each do |each| | |
if each.expired? | |
each.renew! | |
else | |
each.update! | |
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
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 |
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
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 |
NewerOlder