Skip to content

Instantly share code, notes, and snippets.

View kopylovvlad's full-sized avatar
💭
I ❤️ Ruby

Kopylov Vladislav kopylovvlad

💭
I ❤️ Ruby
  • RamblerGroup
  • Moscow
View GitHub Profile
groceryList = {}
groceryList['Bananas'] = true
groceryList['Apples'] = true
groceryList['Grapes'] = true
groceryList['Kiwis'] = true
groceryList['Pears'] = true
groceryList['Apples'] = true # dublicates will be ignored
console.log(Object.keys(groceryList).length == 5)
console.log(groceryList['Kiwis'] == true)
'use strict'
let groceryList = new Map()
groceryList.set('Bananas', 6)
groceryList.set('Apples', 12)
groceryList.set('Grapes', 2)
groceryList.set('Kiwis', 10)
groceryList.set('Pears', 8)
console.log(groceryList.get('Kiwis') === 10)
console.log(groceryList.size === 5)
groceryList = {}
groceryList['Bananas'] = 6
groceryList['Apples'] = 12
groceryList['Grapes'] = 2
groceryList['Kiwis'] = 10
groceryList['Pears'] = 8
console.log(groceryList['Kiwis'] == 10)
console.log(Object.keys(groceryList).length == 5)
subscribers.each do |subscriber_row|
user = User.find_by(email: subscriber_row[1])
if user.nil?
user = User.create_by_subscribe(
email: subscriber_row[1],
first_name: subscriber_row[2],
last_name: subscriber_row[3]
)
end
subscribers.each do |row|
subscriber_row = SubscriberRow.new(row)
user = User.find_by_or_create_by_subscribe(subscriber_row.user_hash)
subscriptions = Subscription.find(subscriber_row.subsc_ids)
if subscriber_row.subscribe?
user.subscribe(subscriptions)
user.send_greeting_email(subscriptions)
end
if subscriber_row.unsubscribe?
# app/controllers/statistics_controller.rb
class StatisticsController < ApplicationController
# ...
def weekly
@weekly = []
get_date.each do |date_obj|
day = date_obj[:start_day].strftime('%A %d-%m-%Y')
orders = get_orders(date_obj)
orders_sum = orders.map(&:price).reduce(:+)
# app/statistics/weekly.html.slim
table.table
thead
tr
td Day
td Pizza count
td Orders sum
td Users
td Pizza
tbody
# app/model/weekly_day.rb
WeeklyDay = Struct.new(:start_day, :end_day) do
def start_day_string
start_day.strftime('%A %d-%m-%Y')
end
end
# app/model/daily_statistic.rb
DailyStatistic = Struct.new(:day_string, :orders) do
def day
# app/views/statistics/weekly.html.slim
table.table
thead
tr
td Day
td Pizza count
td Orders sum
td Users
td Pizza
tbody
class Latitude
def initialize(value)
@value = value
end
def to_i
@value.to_i
end
end