Skip to content

Instantly share code, notes, and snippets.

View secretpray's full-sized avatar
🎯
Focusing

Aleksander secretpray

🎯
Focusing
View GitHub Profile
@secretpray
secretpray / TomSelect.md
Last active October 31, 2022 06:37
Create and select Tag with JS library TomSelect (tom-select) without jQuery
  1. Add tom-select to Rails app
yarn add tom-select
  1. Add to 'app/javascript/stylesheets/application.scss'
@import "tom-select/dist/css/tom-select.bootstrap5";
@secretpray
secretpray / AWS S3 SDK
Last active September 1, 2021 09:20
AWS S3 actions
require 'aws-sdk-s3'
# Create s3 instance
====================
s3 = Aws::S3::Resource.new(access_key_id: Rails.application.credentials.dig(:aws, :access_key_id),
secret_access_key: Rails.application.credentials.dig(:aws, :secret_access_key),
region: 'us-east-1' )
# Create client instance
========================
client = Aws::S3::Client.new(access_key_id: Rails.application.credentials.dig(:aws, :access_key_id),
@secretpray
secretpray / gem invisible_captcha with devise
Last active July 25, 2021 05:54
Install and use gem invisible_captcha with devise
Quick guide to add gem invisible_captcha (https://github.com/markets/invisible_captcha) to your devise registrations.
------- for model User ---------
1) gemfile:
============
gem 'invisible_captcha'
2) console:
===========
bundle
@secretpray
secretpray / FontAwesome in Rails 6
Created July 25, 2021 05:48
How to Install FontAwesome with Yarn and Webpacker in Rails 6?
1) Local terminal
=================
yarn add @fortawesome/fontawesome-free
2) javascript/packs/application.js
==================================
import "@fortawesome/fontawesome-free/css/all"
@secretpray
secretpray / Tabs (html css)
Last active June 26, 2021 07:43
Add tabs for user edit profile (html/css)
html section (erb)
==================
<div class="wrapper">
<h3 class='text-center mt-3 mb-4'><%= t('.edit_profile') %></h3>
<input type="radio" name="slider" checked id="home">
<input type="radio" name="slider" id="code">
<input type="radio" name="slider" id="about">
<nav class='mx-auto mb-4'>
<!-- Icon and name Tab 1 ('Main') -->
@secretpray
secretpray / Preview Avatar
Last active June 20, 2021 10:18
Add preview avatar with vanila JS
1) Create:
==========
app/javascript/utilities/preview_avatar.js
------------------------------------------
document.addEventListener("turbolinks:load", function(event) {
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader()
reader.onload = function (e) {
document.getElementById(input.id + "_medium").setAttribute('src', e.target.result)
@secretpray
secretpray / Infinity scroll
Last active October 20, 2021 19:04
Infinite scrolling with pagination (pagy)
-------------------- model Recipe + Favorites -----------------------
1. Add pagination:
===============
Gemfile
-------
gem 'pagy'
$bundle
@secretpray
secretpray / Omniauth (service method)
Last active June 13, 2021 08:55
Omniauth (Facebook, Github, Google) with confirmation real email with Devise
=================
1. Add to Gemfile
=================
gem 'omniauth'
gem 'omniauth-facebook'
gem 'omniauth-github'
gem 'omniauth-google-oauth2'
gem 'activerecord-session_store'
gem 'omniauth-rails_csrf_protection'
0. Gemfile: (опционально/optional)
===========
gem 'hamlit-rails'
gem 'erb2haml'
gem 'simple_form'
1. Terminal
===========
yarn add choices.js