Skip to content

Instantly share code, notes, and snippets.

View sergii's full-sized avatar

Serhii Ponomarov sergii

View GitHub Profile
index
home
top
help
about
security
contact
connect
support
faq
@sergii
sergii / gist:3e13bdcd02e7a05b19d8e9d8e582693f
Created May 23, 2022 23:14
SVG button which toggle on hover (clipboard button)
<button type="button" class="hidden sm:flex sm:items-center sm:justify-center relative w-9 h-9 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-teal-500 text-gray-400 hover:text-gray-600 group ml-2.5" :style="copied ? 'color:#06B6D4' : ''" @click="navigator.clipboard.writeText(snippets.find(s=>s.language===activeSnippet).snippet).then(()=>{copied=true;clearTimeout(copyTimeout);copyTimeout=setTimeout(()=>{copied=false},1500)})" style="">
<span class="sr-only">Copy code</span>
<span x-show="copied" class="absolute inset-x-0 bottom-full mb-2.5 flex justify-center" x-transition:enter="transform ease-out duration-200 transition origin-bottom" x-transition:enter-start="scale-95 translate-y-0.5 opacity-0" x-transition:enter-end="scale-100 translate-y-0 opacity-100" x-transition:leave="transition ease-in duration-100" x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0" style="display: none;">
<span class="bg-gray-900 text-white rounded-md text-[0.625rem] leading-4 tr
@sergii
sergii / sidekiq.yml
Created May 13, 2022 09:50
Example of queues names for Sidekiq
# sidekiq.yml
---
:verbose: false
:concurrency: 10
:timeout: 25
:queues:
- critical
- mailers
- default
- active_storage_analysis
# app/filters/base_filter.rb
class BaseFilter
include ActiveModel::Model
include ActiveModel::Attributes
def initialize(session)
@_session = session
super(@_session.fetch(:filters, {})[filter_resource_class])
end
@sergii
sergii / 01-board.rb
Created May 6, 2022 09:50 — forked from julianrubisch/01-board.rb
StimulusReflex Patterns - 1 Forms
# app/models/board.rb
class Board < ApplicationRecord
has_many :embeds
end
@sergii
sergii / membership_product.rb
Created May 6, 2022 09:49 — forked from seanharmer/membership_product.rb
Example usage of new delegated_type facility
class MembershipProduct < ApplicationRecord
include Sellable
# Other stuff...
end
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["source"];
copy() {
const range = document.createRange();
window.getSelection().removeAllRanges();
@sergii
sergii / git-commit-template.md
Created January 14, 2022 16:14 — forked from lisawolderiksen/git-commit-template.md
Use a Git commit message template to write better commit messages

Using Git Commit Message Templates to Write Better Commit Messages

The always enthusiastic and knowledgeable mr. @jasaltvik shared with our team an article on writing (good) Git commit messages: How to Write a Git Commit Message. This excellent article explains why good Git commit messages are important, and explains what constitutes a good commit message. I wholeheartedly agree with what @cbeams writes in his article. (Have you read it yet? If not, go read it now. I'll wait.) It's sensible stuff. So I decided to start following the

@sergii
sergii / description.markdown
Created December 21, 2021 16:56 — forked from runemadsen/description.markdown
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@sergii
sergii / html_safe.md
Created November 16, 2021 12:23 — forked from joekur/html_safe.md
Proper Use of `html_safe`

Proper use of html_safe

Let's look at an innocuous piece of ruby. Consider some view code showing a user's name and phone number:

"#{first_name} #{last_name} #{phone}"

Great - this is very succinct, readable, and can easily be extracted to a method in a