Skip to content

Instantly share code, notes, and snippets.

: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 / html2image.rb
Created Jul 1, 2020
wkhtmltoimage / IMGKit gem UTF-8 test of Chinese and Arabic characters
View html2image.rb
# IMGKit lib is a Ruby wrapper around wkhtmltoimage
#
# * https://github.com/csquared/IMGKit
# * https://wkhtmltopdf.org/
#
class Html2image
def call
head = '<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>'
div = "<div class='ping'>Pong 读写汉字 - 学中文 ... ﺩ ﻁ ﺽ ﻙ ﻕ. ﻑ ﺙ ﺱ ﺹ ﺵ چ ﺥ ﺡ ﻩ. ڤ ﺫ ﺯ ﻅ ﺝ ﻍ ﻉ ﺓ. ﻡ ﻥ. ﻭ ﻝ ﺭ ﻱ ﻯ. ﺀ ﺃ ﺇ ﺅ ﺉ. ـِﻳ ـِ ـٍ. ـُﻭ ـُ ـٌ. ـَﺍ ✅</</div>" # randomly googled Chinese and Arabic characters, I have no idea what they mean
@equivalent
equivalent / try-out-htmlcsstoimage.com.rb
Created Jun 30, 2020
trying out htmlcsstoimage.com
View try-out-htmlcsstoimage.com.rb
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 = "<div class='ping'>Pong 读写汉字 - 学中文 ... ﺩ ﻁ ﺽ ﻙ ﻕ. ﻑ ﺙ ﺱ ﺹ ﺵ چ ﺥ ﺡ ﻩ. ڤ ﺫ ﺯ ﻅ ﺝ ﻍ ﻉ ﺓ. ﻡ ﻥ. ﻭ ﻝ ﺭ ﻱ ﻯ. ﺀ ﺃ ﺇ ﺅ ﺉ. ـِﻳ ـِ ـٍ. ـُﻭ ـُ ـٌ. ـَﺍ ✅</</div>"
css = ".ping { padding: 20px; font-family: 'sans-serif'; }"
resp = HTTParty.post("https://hcti.io/v1/image", body: { html: html, css: css }, basic_auth: auth)
@equivalent
equivalent / devise.rb
Created Mar 30, 2020
Custom failure app for devise responding to JS
View devise.rb
# 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 Oct 25, 2019
Benchmark for definded? vs nil? discussion
@equivalent
equivalent / README.md
Created Oct 15, 2019
ruby collor string
View README.md

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 Oct 16, 2019
copy-paste verison of Ruby Inputs gem
View README.md

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 Oct 1, 2019
Materialize CSS materialize css Rails form_with input validation
View materialize_form.rb
# 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 Jan 10, 2019
Ruby code brain teaser. Just copy paste to IRB and see for yourself. Question: why did the first example worked ? :)
View magic.rb
# 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 Oct 10, 2018
Raspberry PI - motion config
View motion.conf
# /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
############################################################
You can’t perform that action at this time.