Skip to content

Instantly share code, notes, and snippets.

View aleonjob's full-sized avatar
🤓
happy coding

Andres Leon aleonjob

🤓
happy coding
View GitHub Profile
module ValidateSpanishVat
module ClassMethods
# Implements model level validator for Spanish's VAT number.
# Usage:
#
# Inside a model with a vat field, simply put
#
# validates_spanish_vat field_name
#
def validates_spanish_vat(*attr_names)
@aleonjob
aleonjob / spanish_vat_validator.rb
Last active March 3, 2017 11:33
Spanish VAT Validator for Rails
# Add this file to the config/initializers folder
#
# Use:
# class Entity < ActiveRecord::Base
# validates :vat_number, spanish_vat: true
# end
class SpanishVatValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless validate_vat(value)
@aleonjob
aleonjob / hash.rb
Last active March 12, 2017 12:52
Override the Hash class to add a method to perform a deep strip for all levels of a hash object. This is useful when parsing json/xml responses.
class Hash
class << self
def strip_hash_values(hash)
hash.each { |_key, value| deep_strip!(value) }
end
def strip_array_values(array)
array.each { |value| deep_strip!(value) }
end
@aleonjob
aleonjob / rubymine_on_iterm.txt
Created October 11, 2017 10:57
Open files with RubyMine from iterm2
1. Open iTerm2
2. Go to: Preferences -> Profile -> Profiles -> Advanced (tab)
3. In "Semantic History" select "Run command" and fill out with:
/Applications/RubyMine.app/Contents/MacOS/rubymine \5 --line 0\2 \1
# This file is the correlative of Gemfile and it's aim is to include gems that are note meant to be part of the project
# but only for development purposes and you don't want to include them in the project as dependencies.
# That's why Gemfile_dev and Gemfile_dev.lock must be git-ignored or git-excluded
# To use the gems specified in this file:
# 1. Create a "Gemfile_dev" file (at same level of "Gemfile")
# 2. Prepend "BUNDLE_GEMFILE=Gemfile_dev" before "bundle install" or "bundle exec rails c" and so forth.
#
@aleonjob
aleonjob / pry_alias.rb
Last active November 6, 2019 10:33
Use bp instead of binding.pry for debugging with pry
# For Rails, include this file within the initializers folder and ignore it or exclude it from Git
require 'binding_of_caller'
module Kernel
# 'bp' stands for binding.pry or break point
pry_alias = ENV['PRY_ALIAS'] || 'bp'
caller_level = 1
@aleonjob
aleonjob / my-script-sample.js
Last active February 18, 2021 17:28
Script sample
"got yaaa!!!"
@aleonjob
aleonjob / ParamStoreUtil.scala
Created January 30, 2024 14:43 — forked from sasaken555/ParamStoreUtil.scala
Find value from AWS SSM ParameterStore with Scala
package net.ponzmild.aws
import com.amazonaws.services.simplesystemsmanagement.model.{GetParameterRequest}
import com.amazonaws.services.simplesystemsmanagement.{AWSSimpleSystemsManagement, AWSSimpleSystemsManagementClientBuilder}
import scala.util.{Failure, Success, Try}
/**
* Find value from AWS SSM ParameterStore
*/