Youtube video in popup modal

It is simple iframe similar to this solution just with stop video after modal is closed with Esc

<div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="videoModal" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <iframe width="100%" height="350" src=""></iframe>

 <a href="#" class="btn btn-default" data-toggle="modal" data-target="#videoModal" data-theVideo="" >VIDEO</a>

$('[data-theVideo]').click(function () {
  var theModal = $(this).data( "target" ),
  videoSRC = $(this).attr( "data-theVideo" ), 
  videoSRCauto = videoSRC+"?autoplay=1" ;
  $(theModal+' iframe').attr('src', videoSRCauto);
  $(theModal+' button.close').click(function () {
      $(theModal+' iframe').attr('src', videoSRC);

$('#videoModal').on('', function() {
  $(this).find('iframe').attr('src', null);

Google pdf preview

If you want to preview pdf or image file, you can use Google

$('#viewerBox').attr('src','<%= %>' );

or you can use directly pdf.js

yt gem access youtube api. Creators Private or non existing video url raise exceptions so you need to rescue Yt::Errors::NoItems, Yt::Errors::RequestError. Video could be public but not accessible (because of deactived account).

Gmail API

Someone can break to your account simple by adding his email as recovery email. Than he can easily change password.

Gmail shortcuts

  • ? to open keyboard shortcut help
  • Ctrl+Enter to send email
  • j and k to older and newer conversation
  • o to open conversation, u to back to threadlist
  • g+a go to all mail, g+t to sent emails, g+i to inbox
  • c to compose
  • / to search


Register on and you can use in in javascript <div class="g-recaptcha" data-sitekey="6LdrgFQUAAAAALvyQvT3fpoagmnb-ik9f73Y0Zaz"></div> but on rails and devise follow and gem

Example is

# Gemfile
# captcha on contact form
gem 'recaptcha'

# config/locales/en.yml
      verification_failed: reCAPTCHA verification failed, please try again.

# app/form_objects/contact_form.rb
class ContactForm
  include ActiveModel::Model
  include Recaptcha::Adapters::ControllerMethods

  attr_accessor :email, :text, :g_recaptcha_response, :current_user, :remote_ip
  validates_format_of :email, with: Devise.email_regexp
  validates :text, :email, presence: true

  def save
    verify_recaptcha model: self, response: g_recaptcha_response
    return false if errors.present?
    return false unless valid?


  def request remote_ip: remote_ip

  def env

  def _send_notification
    Notify.message("contact_form #{email} @ #{}", email, text, remote_ip, current_user)

# app/controllers/pages_controller.rb
  def contact
    @contact_form =
      email: current_user&.email

  def submit_contact
    @contact_form =
      email: current_user&.email || params[:contact_form][:email],
      text: params[:contact_form][:text],
      g_recaptcha_response: params['g-recaptcha-response'],
      current_user: current_user,
      remote_ip: request.remote_ip,
    if[:notice] = t('contact_thanks')
    else[:alert] = @contact_form.errors.full_messages.join(', ')
    render :contact

# app/assets/javascripts/
window.enableRecaptchaButtons = (e) ->
  console.log 'enableRecaptchaButtons'
  $('[data-recaptcha-button]').prop('disabled', false)

# config/initializers/recaptcha.rb
Recaptcha.configure do |config|
  config.site_key = Rails.application.secrets.google_recaptcha_site_key
  config.secret_key = Rails.application.secrets.google_recaptcha_secret_key

# config/secrets.yml
  # Google recaptcha
  google_recaptcha_site_key: <%= ENV['GOOGLE_RECAPTCHA_SITE_KEY'] %>
  google_recaptcha_secret_key: <%= ENV['GOOGLE_RECAPTCHA_SECRET_KEY'] %>

Use Checkbox v2 (Invisible is similar, just you need to trigger using js and use callback to receive results). V3 is for scoring.

It is not possible to edit configuration using api so use selenium script to update redirect URIs. You can use 50 domain with one key.

I had an error when using STMP

  555 5.5.2 Syntax error. u25sm6671019wml.4 - gsmtp
  /home/orlovic/.rbenv/versions/2.6.3/lib/ruby/2.6.0/net/smtp.rb:969:in `check_response'

and the issue was because email was not properly formated (it used latin letters) for example orlović

GCS Google Cloud Storage

You need to create Service account keys for communication between server and google API keyfile.json. Private key id and private key are secret properties so you need to put them in credentials

# rails credentials:edit
  private_key_id: 23e0,,,
  private_key: -----BEGIN PRIVATE KEY-----\nMIIEvgIBADA,,,

Other values can be in code but copy from your json file

# config/storage.yml
  service: GCS
  project: move-index
  bucket: move-index
    type: service_account
    project_id: move-index
    private_key_id: <%= Rails.application.credentials.dig(:gcs, :private_key_id) %>
    private_key: <%= Rails.application.credentials.dig(:gcs, :private_key) %>
    client_email: [email protected],
    client_id: 123...,

Credentials are explained here so on development it is enough to export GOOGLE_APPLICATION_CREDENTIALS with the key or the json file

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"

or you can pass file path like

key_file   = "path/to/service-account.json"
storage = project: project_id, keyfile: key_file

or in ruby, you can find example for each API

require "google/cloud/translate"

Google::Cloud::Translate.configure do |config|
  config.credentials = "path/to/keyfile.json"

  # or content
  config.credentials = Rails.application.credentials.google_cloud_credentials
# or for V2
ENV["TRANSLATE_CREDENTIALS"] = Rails.application.credentials.google_cloud_credentials.to_json

Google Translate API

require "google/cloud/translate/v3"

client =
request = my_create_request
response = client.translate_text request

(do not know how to create request contents: ['home'], source_language_code: 'en', target_language_code: 'sr'


so I still use v2

require "google/cloud/translate/v2"

client =

translation = client.translate "Hello world!", to: "la"