Skip to content

Instantly share code, notes, and snippets.

View phensalves's full-sized avatar
👾
MCMXC

No More Cookies phensalves

👾
MCMXC
  • London, UK
View GitHub Profile
class User < ActiveRecord::Base
scope :email_exist, -> { where.not(email: nil) }
attr_accessor :password
validates :nome, presence: true, length: { maximum: 50 }
before_save { self.email = email.downcase }
validates :email, presence: true, format: {with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, on: :create}, uniqueness: {case_sensitive: false}
class Produto < ActiveRecord::Base
# id, nome, quantidade_em_estoque
validates :id, :nome, :quantidade_em_estoque
end
#####
class EstoqueController < ApplicationController
current_user
class Produto < ActiveRecord::Base
# id, nome, quantidade_em_estoque
validates :id, :nome, :quantidade_em_estoque
end
#####
class EstoqueController < ApplicationController
# current_user_id
class Product < ActiveRecord::Base
validates :name, :estoque_id
has_many :log
end
class User < ActiveRecord::Base
validates :name
has_many :log
end
%table
%thead
%tr
%th Number
%th Created At
%th Text
%th
%th
%th
{
"excludeFiles": ["node_modules/**", "bower_components/**"],
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
{
"bitwise": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"es3": false,
"forin": true,
"freeze": true,
"immed": true,
"indent": 4,
@phensalves
phensalves / delete_local_branches.txt
Last active November 9, 2016 13:39
Snippet to delete all local branches and keep master
git branch | grep -v "master" | xargs git branch -D
@phensalves
phensalves / character_manager.rb
Last active December 2, 2016 15:57
Consuming api using NET from ruby
module Api
class CharacterManager
API_CONFIG = YAML.load_file("#{Rails.root.to_s}/config/marvel_configs.yml")["marvel_api"]
def initialize options={}
@ts = "#{API_CONFIG['ts']}"
@api_key = "#{API_CONFIG['api_key']}"
@hash = "#{API_CONFIG['secret_hash']}"
@limit = "#{API_CONFIG['limit']}"
class Marvel::CharactersController < ApplicationController
before_action :authenticate_user!
def index
@characters = Character.paginate(page: params[:page], per_page: 10)
get_all_characters unless @characters.present?
end
def show
@character = get_character