Skip to content

Instantly share code, notes, and snippets.

Avatar

Yaroslav Shmarov yshmarov

View GitHub Profile
@yshmarov
yshmarov / config.yml
Created May 17, 2022 12:10
notes about deploying on render
View config.yml
### 1. Database setup
Create a new Postgresql database on Render [link](https://dashboard.render.com/new/database)
Copy "Internal Connection String"
Locally, add "Internal Connection String" to credentials `bin/rails credentials:edit`:
```ruby
# config/credentials.yml
@yshmarov
yshmarov / mailer.html.erb
Created June 29, 2021 09:24
email layout styling example
View mailer.html.erb
<% # frozen_string_literal: true %>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<scss>
body {
font-family: Helvetica, Arial, sans-serif;
.message {
width:600px;
border-top: 2px dashed;
@yshmarov
yshmarov / _form.html.erb
Created May 30, 2021 17:28
show or hide div based on a form value (d-none is a bootstrap5 class for hiding)
View _form.html.erb
<%= form_with(model: post) do |form| %>
<%= content_tag :div, nil, data: { controller: "showhide", showhide_show_if_value: "lorem", showhide_hide_class: "d-none" } do %>
<%= form.select :content, [nil, "lorem", "150"], {}, {data: { showhide_target: "field", action: "change->showhide#change" }} %>
<div data-showhide-target="output">
you can see this text if selected value = lorem
</div>
<% end %>
<% end %>
@yshmarov
yshmarov / _form.html.haml
Created May 30, 2021 17:26
conditional dropdowns with stimulus and jquery (bad approach)
View _form.html.haml
= simple_form_for @valuation, html: { data: { controller: 'valuation' } } do |f|
= f.input :tenure_id, collection: Tenure.all, input_html: { id: 'tenure_dropdown', data: { action: 'change->valuation#toggleTenure' } }
#tenure
= f.input :is_remaining_term_less_than_85_years, as: :select, input_html: { id: 'timeleft_dropdown', data: { action: 'change->valuation#toggleTimeleft' } }
#timeleft
= f.input :remaining_term_details
@yshmarov
yshmarov / blob active_Storage
Created May 14, 2021 10:15
blob active_Storage
View blob active_Storage
app/views/active_storage/blobs/_blob.html.haml
<%= render "active_storage/blobs/blob", blob: @post.avatar %>
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
<% if blob.representable? %>
<%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
<% elsif blob.image? %>
<%= image_tag blob, width: "200px" %>
<% elsif blob.audio? %>
@yshmarov
yshmarov / bootstrap_card.html
Created January 21, 2021 13:47
bootstrap card syling
View bootstrap_card.html
<div class="card shadow">
<div class="card-header">
<h2>
</h2>
</div>
<div class="card-body">
</div>
<div class="card-footer">
</div>
</div>
View gist:85a9a3e4572cac1b5cf682d42fb5449d
constraints SubdomainRequired do
root to: 'dashboards#show', as: 'subdomain_root'
end
class SubdomainRequired
def self.matches?(request)
request.subdomain.present? && request.subdomain != "www"
end
end
@yshmarov
yshmarov / _thumbnail.html.erb
Last active September 22, 2022 19:36
embed Youtube in ActionText
View _thumbnail.html.erb
app/views/youtubes/_thumbnail.html.erb
<div>
<%= image_tag youtube.thumbnail_url, style: "max-width:400px" %>
</div>
@yshmarov
yshmarov / 0 AWS Cloud9
Last active January 9, 2023 18:07
Ruby on Rails 6: Learn 25+ gems and build a Startup MVP 2020
View 0 AWS Cloud9
# All AWS C9 envments
https://eu-central-1.console.aws.amazon.com/cloud9/home?region=us-east-1
# Instance management
https://console.aws.amazon.com/ec2/home?region=eu-central-1#Instances:sort=instanceId
# Create AWS C9 environment
https://eu-central-1.console.aws.amazon.com/cloud9/home/create
Setting - set tabs to 2
@yshmarov
yshmarov / database.yml
Last active November 11, 2020 19:46
commands for activating pg (postgresql) for rails on c9.io platform
View database.yml
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: yaro
password: pass
host: <%= ENV['IP'] %>
development:
<<: *default