Skip to content

Instantly share code, notes, and snippets.

View sergii's full-sized avatar

Serhii Ponomarov sergii

View GitHub Profile
@sergii
sergii / index.html
Created May 11, 2024 23:06 — forked from johnmeehan/index.html
Stimulus js Checkbox toggle
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main.css">
<script src="bundle.js" async></script>
</head>
<body>
<div data-controller="toggler">
<label>Toggle Me</label>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sergii
sergii / phlex_element.rb
Created January 3, 2024 22:21 — forked from bradgessler/phlex_element.rb
The Phlex::Element class makes creating simple Phlex components easier
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "phlex"
end
require "phlex/testing/view_helper"
include Phlex::Testing::ViewHelper
@sergii
sergii / _form.html.erb
Created October 2, 2023 23:19 — forked from ahmad19/_form.html.erb
Render inline errors in Rails forms after submit and hotwire changes
<%= form_for customer, html: { id: dom_id(customer), class: 'row g-3' } do |f| %>
<% presenter = InlineErrorRenderer.new(customer, self, 'form-control-lg form-control-solid mb-3 mb-lg-0') %>
<div class='col-md-6'>
<%= f.label :full_name %>
<%= f.text_field :full_name, presenter.html_options_for(:full_name) %>
<%= presenter.error_container_for(:full_name) %>
</div>
<div class='col-md-6'>
<%= f.label :phone_number, 'Phone Number' %>
<%= f.text_field :phone_number, presenter.html_options_for(:phone_number) %>
@sergii
sergii / stories.rb
Created September 8, 2023 21:37 — forked from robzolkos/stories.rb
story.rb refactor
# Original code https://twitter.com/robinbortlik/status/1699524286568964440?s=20
# app/controllers/stories.rb
class StoriesController < ApplicationController
before_action :check_authorizationa # this should check and return a 401
def create
story = Story.new(story_params)
if story.save
@sergii
sergii / Rakefile
Created September 8, 2023 21:33 — forked from bradgessler/Rakefile
Setups up repos in `./gems` from the root of a Rails project as local gems. This makes framework development much easier.
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative "config/application"
Rails.application.load_tasks
desc "Set local gems"
task :gems do
Dir["gems/**"].each do |path|
@sergii
sergii / random_string.rb
Created January 7, 2023 23:03 — forked from umutakturk/random_string.rb
Generate random string in Ruby.
def random_string(length = 6)
rand(36**length).to_s(36)
end
CREATE TABLE posts (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL
);
CREATE TABLE comments (
id INTEGER PRIMARY KEY,
content TEXT NOT NULL,
post_id INTEGER NOT NULL,
@sergii
sergii / ddd-rails-tree.txt
Created June 23, 2022 10:56 — forked from replaid/ddd-rails-tree.txt
A Rails directory tree that expresses DDD layers and bounded contexts.
components/
my_bounded_context/
app/
presentation/ # This is called the "UI" layer in DDD literature, but it is also
# where things like JSON interfaces live -- any kind of presentation
# or handshake to anything outside. So "presentation" rather than "ui".
assets/
helpers/
mailers/
views/
@sergii
sergii / select_controller.js
Created June 4, 2022 23:27 — forked from tabishiqbal/_form.html.erb
Tom-Select Example with Stimulus
import { Controller } from "stimulus"
import TomSelect from "tom-select"
export default class extends Controller {
static values = { url: String }
connect() {
this.initTomSelect()
}