Skip to content

Instantly share code, notes, and snippets.

@olvap
olvap / patrones.md
Last active August 29, 2015 14:04
Patrones de Diseño

Patrones de diseño

GoF

  • Erich Gamma
  • Richard Helm
  • Ralph Johnson
  • John Vlissides

Que es un patrón

Es una solución general a un tipo de problema.

@olvap
olvap / Juego.rb
Last active August 29, 2015 14:04 — forked from juancruzbupo/test juego ppt
#rspec , minitest cutest librerias
class Juego
GANA = { papel: :piedra, piedra: :tijera, tijera: :papel }
def initialize jugador1, jugador2
@jugador1 = jugador1
@jugador2 = jugador2
end
@olvap
olvap / morsca.rb
Created August 1, 2014 21:01
refactor mosca
require 'mqtt'
require 'json'
class Mosca
@@default_broker = "test.mosquitto.org"
@@default_timeout = 5
@@debug = false
attr_reader :options
def verify_phone_pin_and_delete_in_call_records(phone_verification_input)
verified = false
if self.phone_number.nil? && self.is_suspicious && verify_proposed_phone_pin(phone_verification_input)
verified = true
TwilioCall.find_by_user_id(self.id).try(:destroy)
elsif self.proposed_phone_number && verify_proposed_phone_pin(phone_verification_input)
verified = true
TwilioCall.find_by_user_id(self.id).try(:destroy)
elsif !self.proposed_phone_number && verify_phone_pin(phone_verification_input)
def validate_user_email_uniqueness
return true if self.skip_user_uniqueness
find = "where(:email => '#{self.email}')"
if self.user_id.present?
find += ".where('id != ?', #{self.user_id})"
end
user = User.class_eval(find)
@olvap
olvap / refactor_users_controller.rb
Last active August 29, 2015 14:04
Refactor example
def create_identity_for_existing_user
token = params[:token] # "token" is a better name for a token than "format"
user = User.find_by_email_verification_token(token)
# if you create an association between user and indentinty you dont need to set association
# manually(@identity.user_id = user.id).
@identity = user.identity.build(params[:identity])
# this part should be moved to a before_save method
# @identity.email = @identity.email_confirmation = user.email
# @identity.user_id = user.id
@olvap
olvap / Coffee.coffee
Last active August 29, 2015 14:03
A comparation between Coffee and JS
class PahoMessage
constructor: (@message) ->
value: ->
"value: #{ @message }"
topic: ->
"topic: #{ @message }"
paho_message = PahoMessage.new("un mensaje")
console.log paho_message.value
#= require paho
freezer =
randomToken: ->
Math.random().toString(36).substr(2)
id: ->
$('body').data('freezer-id').replace(/-/g,"")
domain: ->
@olvap
olvap / README.md
Last active August 29, 2015 14:03

Description

The application has 3 namespaces.

FieldOwer

This is the namespace for the people who own a field and want to rent it.

  • Log in, Log out and register FieldOwner users (with/without facebook)
  • FieldOwner has email, password, name, etc
  • FieldOwner has_many :fields
@olvap
olvap / archivo.md
Last active August 29, 2015 14:03
Instrucciones a ejecutar

Archivo

rails new archivo
cd archivo

Scaffold

La instrucción scaffold, ejecuta la instrucción model y controller para hacer un CRUD de un recurso dado. Es como hacer rails g model y rails g controller.

rails g scaffold file_record title