Skip to content

Instantly share code, notes, and snippets.

@Hunk13
Hunk13 / 1 Gist conventions
Created August 22, 2016 08:52 — forked from PavloBezpalov/1 Gist conventions
Deploy Rails 5.0.0.beta3 to VPS(Ubuntu 14.04.4 LTS). Nginx, Puma, Capistrano3, PostgreSQL, RVM.
<<APP>> change this variables
@Hunk13
Hunk13 / gist:4949b30a1c4679b7650e91024febb748
Created October 12, 2016 06:35 — forked from arjunvenkat/gist:1115bc41bf395a162084
Seeding a Rails database with a CSV file

How to seed a Rails database with a CSV file

1. Setup

First, Create a folder inside of lib called seeds

Put your CSV file example.csv into the lib/seeds folder. In the example below, the file is called real_estate_transactions.csv

Make sure you've created a resource with the appropriate columns to match your seed data. The names don't have to match up.

@Hunk13
Hunk13 / gist:7919491470e20783fd2d1ce898d0ea71
Created October 16, 2016 09:30 — forked from ryansobol/gist:5252653
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

FROM ruby:2.2.3
RUN apt-get update -qq
RUN apt-get install -y -qq build-essential
RUN apt-get install -y -qq nodejs
RUN apt-get install -y -qq libpq-dev
ENV APP_HOME /app
ENV BUNDLE_PATH /bundle
ENV BUNDLE_JOBS 5
class CustomerSearchTerm
attr_reader :where_clause, :where_args, :order
def initialize(search_term)
search_term = search_term.downcase
@where_clause = ""
@where_args = {}
if search_term =~ /@/
build_for_email_search(search_term)
else
@Hunk13
Hunk13 / chrome.txt
Created October 3, 2017 17:31
disable chrome extension in dev tools
-scheme:chrome-extension
@Hunk13
Hunk13 / css_reset.css
Created January 27, 2018 07:39 — forked from freetonik/css_reset.css
Eric Meyer’s CSS Reset 2.0
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@Hunk13
Hunk13 / test.rb
Last active July 15, 2018 07:24 — forked from Mehonoshin/test.rb
# вроде должен наследовать от ApplicationController и название во множественном числе
# class BasketsController < ApplicationController
class BasketController
# метод очень большой, можно разложить частьи в модель, в приватные методы или совсем убрать
def add_to_basket
# Можно сделать приватный фильтр и поместить в before_action
# скорее всего поиск по параметру будет использоваться не только в этом методе
# еще параметром идет название и если в базе будет несколько одинаковых,
# то в item будет массив. Поэтому можно добавить к выборке .limit(1) или .first
# чтобы отобралось только одно значение
@Hunk13
Hunk13 / my_awesome_rspec_hacks.rb
Created October 1, 2018 11:30 — forked from jalkoby/my_awesome_rspec_hacks.rb
My awesome RSpec hacks
## Context + metadata
shared_context 'Logged as a user', role: true do
let(:user) { |example| create :user, example.metadata[:role] }
before { login_as user }
end
scenario "Login as a client", role: :client
scenario "Login as a customer", role: :customer
scenario "Login as an admin", role: :admin
Ruby
What is a class? - Каркас для объектов, содержит данные, методы, инстансы.
What is the difference between a class and a module? - Модуль - пространство имен, не может иметь экземпляров.
What is an object? - Экземпляр класса.
How would you declare and use a constructor in Ruby?
def initialize(some, data)
p "Initializer #{some} #{data}"
end