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 Array | |
# Returns the flatten version of the array | |
# example: [[1,2,[3]],4] -> [1, 2, 3, 4] | |
def flatten | |
out = [] | |
self.each do | e | | |
if e.is_a? Array | |
out += e.flatten | |
else | |
out.push(e) |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
#################### app/models/task.rb | |
class Task < ApplicationRecord | |
belongs_to :user | |
belongs_to :lead, required: false | |
belongs_to :creator, class_name: "User", foreign_key: "creator_id" | |
belongs_to :responsible, class_name: "User", foreign_key: "responsible_id" | |
update_index 'leads#lead', :lead |
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
import math | |
a = float(input("Ingrese el valor de a: ")) | |
b = float(input("Ingrese el valor de b: ")) | |
c = float(input("Ingrese el valor de c: ")) | |
print("Ecuación: " + str(a) + " * x * x + " + str(b) + " * x + " + str(c)) | |
print("a: " + str(a)) | |
print("b: " + str(b)) |
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
def index | |
items_with_images = news_items.each do |item| | |
item[:image] = UserScope::FetchNewsItem.call(id: params[:id]).news_item.image | |
end | |
respond_with items_with_images | |
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
resolve lambda { |_, args, _| | |
unless args[:name].present? | |
raise GraphQL::ExecutionError, 'You must provide a value for name' | |
end | |
unless args[:address].present? | |
raise GraphQL::ExecutionError, 'You must provide a value for address' | |
end | |
Model.find_by(address: args[:address], name: args[:name]) | |
} |
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
resolve lambda { |_, args, _| | |
Validators::Model.validate!(args) | |
Model.find_by(address: args[:address], name: args[:name]) | |
} |
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 Validators | |
class Model | |
def self.validate!(args) | |
unless args[:name].present? | |
raise GraphQL::ExecutionError, 'You must provide a value for name' | |
end | |
unless args[:address].present? | |
raise GraphQL::ExecutionError, 'You must provide a value for address' | |
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
module Validators | |
class GraphqlValidator | |
def self.validate_presence(attribute, value) | |
return if value.present? | |
raise GraphQL::ExecutionError, “You must provide a value for #{attribute}” | |
end | |
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
module Validators | |
class Model | |
def self.validate!(args) | |
validate_presence('name', args[:name]) | |
validate_presence('address', args[:address]) | |
end | |
end | |
end |
OlderNewer