Skip to content

Instantly share code, notes, and snippets.

View secretpray's full-sized avatar
🎯
Focusing

Aleksander secretpray

🎯
Focusing
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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";
https://www.robinwieruch.de/react-hooks-fetch-data
useEffect(() => {
let didCancel = false;
async function fetchMyAPI() {
let url = 'http://something/' + productId;
let config = {};
const response = await myFetch(url);
if (!didCancel) { // Ignore if we started fetching something else
@secretpray
secretpray / Install Bootstrap 5 without jQuery
Last active February 8, 2024 08:00
Install Bootstrap 5 with tooltip, popover and toasts in Ruby on Rails 6+ (without jQuery)
1) yarn add bootstrap
2) yarn add @popperjs/core
3.1) in folder 'app/javascript/' create new folder 'stylesheets':
mkdir app/javascript/stylesheets/
3.2) in new folder 'stylesheets' create file 'application.scss'
cd app/javascript/stylesheets/
touch application.scss

Algo 1

Before

git status
git add .
git commit
git push Stage_xx
git checkout main
git branch -D Stage_xx
// Timer 5 sec -> count = 5000
// stop timer -> running = false
var count = 5000,
running = true,
secondsNode = document.getElementById("seconds"),
millisecondsNode = document.getElementById("milliseconds"),
mOld,
mNew;