Skip to content

Instantly share code, notes, and snippets.

View yshmarov's full-sized avatar
🇺🇦

Yaro Shm yshmarov

🇺🇦
View GitHub Profile
@SamSaffron
SamSaffron / test.rb
Created November 10, 2025 00:02
env_lookup.rb
# frozen_string_literal: true
require "benchmark"
require "memory_profiler"
require "active_support"
require "active_support/core_ext/object/blank"
def test_fast
@cache = ENV["TESTING"].presence if !defined?(@cache)
@cache
end
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 October 9, 2025 20:16
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