Skip to content

Instantly share code, notes, and snippets.

Avatar
🌰
In progress

Ivan Nemytchenko inem

🌰
In progress
View GitHub Profile
View _show.html.erb
<div style='display: flex; width: 120px; height: 70px;'>
<%= image_tag field.to_s, style: 'width: 100%; height: 100%; object-fit: contain;' %>
</div>
View _show.html.erb
<div style='display: flex; width: 120px; height: 70px;'>
<%= image_tag field.to_s, style: 'width: 100%; height: 100%; object-fit: contain;' %>
</div>
View Makefile
setup:
rails db:create
rails db:migrate
rails db:seed
rails db:fixtures:load
db:
rails db:migrate
fix:
View 1001.rb
require 'oga'
require 'open-uri'
require 'pry'
url = './index.html'
html = open(url)
class FilmLibrary
def initialize(films)
@films = films
@inem
inem / .dockerignore
Last active May 8, 2020
Improving speed of docker builds with two Gemfiles
View .dockerignore
ansible
vendor/cache
log/*
tmp/cache/*
test
@inem
inem / Simple Form.md
Created Jan 13, 2020 — forked from stevenyap/Simple Form.md
Simple Form Cheatsheet
View Simple Form.md

Gemfile

gem 'simple_form'

Installation

rails generate simple_form:install
@inem
inem / clean_code.md
Created Jan 13, 2020 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin
View clean_code.md

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

View material-views.md

Material Views as a first class citizens in Rails app

Abstract

Material Views are highly underrated in Rails community. They can save you a lot of time when you deal with a database of complex structure.

Demonstrated solution is cheap, contains no plain SQL, helps to keep business logic within main app. and requires no migrations/versioning

Description

View meteo_data.rb
require 'uri'
require 'rexml/document'
require 'net/http'
require_relative 'cloth'
require_relative 'smart_wardrobe'
class MeteoService
CITIES = {'Москва' => '37', 'Рига' => '312', 'ГонКонг' => '256', 'Женева' => '374', 'Вашингтон' => '384', 'Каир' => '334'}
def initialize(url = "https://xml.meteoservice.ru/export/gismeteo/point")
View friendly_urls.markdown

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.