Skip to content

Instantly share code, notes, and snippets.

View yshmarov's full-sized avatar
🇺🇦

Yaro Shm yshmarov

🇺🇦
View GitHub Profile
class BaseClient
class APINotFound < StandardError; end
attr_reader :auth_strategy
def initialize(auth_strategy: :headers, headers: {})
@auth_strategy = auth_strategy
@headers = headers
end
@bopm
bopm / ferrum.rb
Created February 17, 2024 14:00
format.pdf do
html = ApplicationController.new.render_to_string(
template: 'pdfs/test',
formats: [:pdf],
layout: 'layouts/pdf',
assigns: { user: @user },
encoding: 'UTF-8'
)
Ferrum::Browser.new(timeout: 7).tap do |browser|
browser.content = html
@donnfelker
donnfelker / attached_validator.rb
Last active October 28, 2023 02:51
Custom Active Storage Validator
class AttachedValidator < ActiveModel::EachValidator
# Active Storage validator to ensure that an attachment is attached.
#
# usage:
# validates :upload, attached: true
#
def validate_each(record, attribute, _value)
return if record.send(attribute).attached?
errors_options = {}

Для интеграции ChatGPT в приложение Rails вам потребуются следующие шаги:

  1. Получите API-ключ GPT, откройте сайт https://openai.com/ и зарегистрируйте аккаунт, елкгда будут инструкции по получению ключа.

  2. Добавьте библиотеку 'httparty' в файл Gemfile вашего приложения и запустите

bundle install
  1. Создайте класс в папке 'lib' вашего приложения для обращения к сервису GPT:

Algo 1

Before

git status
git add .
git commit
git push Stage_xx
git checkout main
git branch -D Stage_xx
@levelsio
levelsio / git_graph.php
Last active June 5, 2023 03:49
GitHub style graph in PHP + CSS
<style>
.git-graph {
text-align: left;
line-height: 1;
}
.git-graph-row {
clear: both;
text-align: left;
}
.git-graph-cell {
@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 / Infinity scroll
Last active October 20, 2021 19:04
Infinite scrolling with pagination (pagy)
-------------------- model Recipe + Favorites -----------------------
1. Add pagination:
===============
Gemfile
-------
gem 'pagy'
$bundle
--------- model Recipe -------------
1) Controllers: Recipes
=======================
class RecipesController < ApplicationController
after_action :register_visit, only: :show
attr_accessor :recipe
helper_method :recently_recipes
// DISCLAIMER : You can now probably use `data-turbo-action="advance"` on your frame to perform what this controller is aiming to do
// https://turbo.hotwired.dev/handbook/frames#promoting-a-frame-navigation-to-a-page-visit
// Note that you probably want to disable turbo cache as well for those page to make popstate work properly
import { navigator } from '@hotwired/turbo'
import { Controller } from '@hotwired/stimulus'
import { useMutation } from 'stimulus-use'
export default class extends Controller {
connect (): void {