Skip to content

Instantly share code, notes, and snippets.

Artur arturictus

Block or report user

Report or block arturictus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View if.js
if("hello") "hello";
"hello"
if(0) "hello";
undefined
if('') "hello";
undefined
if(1) "hello";
"hello"
View sam_message.md

Example with translations:

{
  "response": [
    {
      "type":"text",
      "message":{
        "translation": {
          "en":"do you need and hotel?",
View hash.rb
class Hash
# merge_present
# examples:
# {hello: ''}.merge_present(hello: 'sd') #=> {hello: 'sd'}
#
# {hello: nil}.merge_present(hello: '') #=> {}
#
def merge_present(other_hash)
mapped = self.map do |k, v|
if v.blank?
View unless.rb
# &&
'hello' unless true && false
#=> "hello"
'hello' unless false && true
#=> "hello"
'hello' unless false && false
#=> "hello"
'hello' unless true && true
#=> nil
View array.rb
class Array
# find_map
# example:
# [nil, 'hello '].find_map |n|
# n.try(:strip)
# end => 'hello'
def find_map(&block)
result = nil
self.each do |q|
result = yield(q)
View add_child_validations.rb
# In not working!!
# Validations are added, but errors are not in the errors list after valid
module AddChildValidations
extend ActiveSupport::Concern
class_methods do
# Example:
# class User < ActiveRecord::Base
# has_one :address
# add_child_validations_for :address do
@arturictus
arturictus / rspec_helper.rb
Created Oct 8, 2015
Translating AtiveJob::TestHelper to Rspec
View rspec_helper.rb
def specific_enqueued_jobs(job)
enqueued_jobs.select{ |j| j if j[:job] == job }
end
require 'active_support/core_ext/class/subclasses'
require 'active_support/core_ext/hash/keys'
module ActiveJob
# Provides helper methods for testing Active Job
module RSpecHelper
extend ActiveSupport::Concern
View Operaciones-Git
#############################################
# Push de la rama actual
git push origin $rama_actual
#############################################
# Volver a un commit anterior, descartando los cambios
git reset --HARD $SHA1
#############################################
# Ver y descargar Ramas remotas
View skippable_callbacks.rb
module SkippableCallbacks
extend ActiveSupport::Concern
module ClassMethods
def _skippable_callbacks
[
:after_initialize,
:after_build,
:before_validation,
:after_validation,
:before_create,
@arturictus
arturictus / rails_helper.rb
Created Mar 19, 2015
Rspec-capybara login with warden
View rails_helper.rb
# spec/rails_helper.rb
# add to your rails_helper inside the
RSpec.configure do |config|
config.around(:each, type: :request) do |example|
Warden.test_mode!
example.run
Warden.test_reset!
end
end
You can’t perform that action at this time.