This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query | |
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails | |
#payload: [{"kind"=>"person"}] | |
Segment.where("payload @> ?", [{kind: "person"}].to_json) | |
#data: {"interest"=>["music", "movies", "programming"]} | |
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json) | |
Segment.where("data #>> '{interest, 1}' = 'movies' ") | |
Segment.where("jsonb_array_length(data->'interest') > 1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Publisher | |
def subscribe(subscribers) | |
@subscribers ||= [] # if @subscribers is nil, we initialize it as empty array, else we do nothing | |
@subscribers += subscribers | |
end | |
def broadcast(event, *payload) | |
@subscribers ||= [] # @subscribers is nil, we can't do each on it | |
@subscribers.each do |subscriber| | |
# If event is :item_added occured with payload item itself |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ComponentHelper | |
def react_component(name, props: {}) | |
content_tag(:div, nil, id: name, data: { props: props.to_json, handler: "react" }) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Проект "Подземелье драконов" | |
Задание 1 | |
Генератор подземелья | |
Напишите скрипт, который генерирует подхемелье с комнатами. | |
Подземелье – квадрат 10x10 (массив). | |
Комната – элемент массива. Каждая комната должна иметь хотя-бы одну дверь в другую комнату (сверху, справа, слева, снизу). Максимум четыре двери в комнате. Дверь не может выводить из подземелья. Поэтому комната в массиве с индексом [0][0] может иметь дверь только внизу и справа. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Photosession.all.each do |p| | |
p.photos.each do |ph| | |
begin | |
p.process_photos_upload = true | |
ph.cache_stored_file! | |
ph.retrieve_from_cache!(ph.cache_name) | |
ph.recreate_versions!(:xl, :l, :m, :s, :xs) | |
p.save! | |
rescue => e | |
puts "ERROR: YourModel: #{e.to_s}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/breadcrumbs/admin_breadcrumbs.rb | |
AdminBreadcrumbs = Crumbs.build do | |
framework :rails | |
namespace :admin | |
crumb 'welcome#index' do | |
link 'Дашборд' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
include AASM | |
aasm do | |
state :newone, initial: true | |
state :activated | |
state :blocked | |
state :deleted | |
event :activate do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const usersCreate = data => (dispatch) => { | |
dispatch(usersCreateStart()); | |
postUser(data) | |
.then( | |
(res) => { | |
dispatch(usersCreateSuccess()); | |
dispatch(push(`/admin/users/${res.user.id}`)); | |
dispatch(showSuccess('user_create')); | |
}, | |
(err) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Формула по умолчанию | |
ОКРУГЛИТЬ(СРЕДНЕЕ_ЗНАЧЕНИЕ(все_оценки)) | |
# У оценок можно поставить тег. Т.е. может быть стандартная оценка, а может быть экамен, экскурсия и т.д. | |
# Отдельно считаем все оценки по журналу, отдельно по экзамену и равнозначно их высчитываем, округляем в ближайщую сторону | |
ОКРУГЛИТЬ((СРЕДНЕЕ_ЗНАЧЕНИЕ(обычная_оценка) + СРЕДНЕЕ_ЗНАЧЕНИЕ(экзамен)) / 2 ) | |
# есть разные типы оценок (5-бальная, 100-бальная, зачет/незачет и т.д.), могут встречаться прямо в одном журнале, в одном уроке и даже в одной ячейке при комбинированных оценках. 5/79 (на одном уроке 5 за диктант, 79 за тест по грамматике). | |
# Тут мы берем в расчет только оценки пятибальные, игнорируем все остальные | |
ОКРУГЛИТЬ(СРЕДНЕЕ_ЗНАЧЕНИЕ(ВЫБРАТЬ_ПЯТИБАЛЬНЫЕ(все_оценки))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DestroyUser | |
include Dry::Transaction | |
include Dry::Transaction(container: Containers::RecordOperations) | |
step :find, with: 'operations.find' | |
step :destroy, with: 'operations.destroy' | |
end |
NewerOlder