Skip to content

Instantly share code, notes, and snippets.

View equivalent's full-sized avatar
:octocat:
I'm IDDQD + IDKFA for Ruby on Rails

Tomas Valent equivalent

:octocat:
I'm IDDQD + IDKFA for Ruby on Rails
View GitHub Profile
@equivalent
equivalent / try-out-htmlcsstoimage.com.rb
Last active July 6, 2020 12:28
trying out htmlcsstoimage.com
def x
user_id = Rails.application.credentials.dig(:htmlcsstoimage, :user_id) #this will return my Htmlcsstoimage user_id
key = Rails.application.credentials.dig(:htmlcsstoimage, :key) #this will return my Htmlcsstoimage key
auth = { username: user_id, password: key }
html = '<body>'
html += '<h1>Rose Tattoo</h1>'
html += '<h2>Dropkick Murphys</h2>'
@equivalent
equivalent / README.md
Last active April 8, 2020 05:44
rails reproduce template
@equivalent
equivalent / devise.rb
Created March 30, 2020 12:37
Custom failure app for devise responding to JS
# config/initializers/devise.rb
class CustomFailureApp < Devise::FailureApp
def http_auth_body
case request_format
when :js, 'js'
'alert(" not authorized !");'
when :json, 'json'
{ error: i18n_message }
else
i18n_message
@equivalent
equivalent / README.md
Last active October 25, 2019 06:07
Benchmark for definded? vs nil? discussion
@equivalent
equivalent / README.md
Created October 15, 2019 11:18
ruby collor string

If you want to have color strings for Unix Ruby string and you don't want to use gem like colorize

@equivalent
equivalent / README.md
Last active October 16, 2019 11:03
copy-paste verison of Ruby Inputs gem

This is copy-paste version of Inputs gem

This is helpfull if you just want to paste the Inputs gem functionality to a Ruby script when library install (gem install inputs or bunde install) is not an option.

Just Copy-Paste the code bellow to your script and you'll have all the features of Inputs gem

Color prompt

@equivalent
equivalent / materialize_form.rb
Last active October 1, 2019 21:33
Materialize CSS materialize css Rails form_with input validation
# config/initializers/materialize_form.rb
#
# So that you have Materialize CSS validation message https://materializecss.com/text-inputs.html such as
#
# <div class="input-field">
# <label for="company_title" class="active">Title</label>
# <input type="text" value="" name="company[title]" id="company_title" class="invalid">
# <span data-error="can't be blank" class="helper-text"></span>
# </div>
@equivalent
equivalent / magic.rb
Last active January 10, 2019 18:34
Ruby code brain teaser. Just copy paste to IRB and see for yourself. Question: why did the first example worked ? :)
# this Ruby method definiton will get defined successfuly
def
'magic !'
end
# but this Ruby method definiton will Fail with syntax error: syntax error, unexpected keyword_end, expecting end-of-input
def
'magic !'
end
@equivalent
equivalent / motion.conf
Created October 10, 2018 05:41
Raspberry PI - motion config
# /etc/motion/motion.conf on my Raspberian
# Rename this distribution example file to motion.conf
#
# This config file was generated by motion 4.0
############################################################
# Daemon
############################################################
@equivalent
equivalent / request-model-with-validation-or-error-model.rb
Created August 28, 2018 05:22
Request model with validation on error model
require 'active_model'
class RequestModel
include ActiveModel::Validations
attr_reader :params, :ero
def initialize(params, ero)
@params = params
@ero = ero