Skip to content

Instantly share code, notes, and snippets.

View Pomeha's full-sized avatar
💎
Keep calm and code

Vladislav Akimenko Pomeha

💎
Keep calm and code
View GitHub Profile
@Pomeha
Pomeha / example.sql
Created March 1, 2021 14:20
Limit by record type on table
SELECT * FROM
(
SELECT (CASE WHEN post_id IS NOT NULL THEN ROW_NUMBER() OVER (PARTITION BY (post_id IS NOT NULL)::integer) END) AS r_post,
(CASE WHEN event_id IS NOT NULL THEN ROW_NUMBER() OVER (PARTITION BY (event_id IS NOT NULL)::integer) END) AS r_event,
t.*
FROM feed_items t)
feed_items
WHERE r_post <= VALUE OR r_event <= VALUE;
@Pomeha
Pomeha / paginate.rb
Created April 7, 2020 10:27
Infinite scroll example
# frozen_string_literal: true
class Paginate
def call(
scope,
direction: 'asc',
field: nil,
last_id: nil,
field_value: nil,
limit: nil
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Comments::List do
subject do
service.(
client,
recommendation_id: 'REC_ID',
last_id: 'LAST_ID',
@Pomeha
Pomeha / weights_task.rb
Last active February 19, 2020 10:04
Решения задачи про гири. Условие: Сумма весов гирь с левой стороны никогда не будет равна сумме весов гирь с правой
class WeightTask
def call
max = 32
(1..max-6).each do |a|
(a.next..max-5).each do |b|
(b.next..max-4).each do |c|
(c.next..max-3).each do |d|
(d.next..max-2).each do |e|
(e.next..max-1).each do |f|
@Pomeha
Pomeha / json_parse.go
Last active September 11, 2019 14:49
var dat map[string]interface{}
var parseString string
if cachedPosts != nil {
parseString = fmt.Sprintf("%s", someJsonString)
if err = json.Unmarshal([]byte(parseString), &dat); err != nil {
panic(err)
}
}
def hello(data)
author = role_checker(current_user)
create_comment.(
author,
author.recommendations.find(data['recommendation_id']),
data['message']
)
ActionCable.server.broadcast "client_#{current_user.client.id}_channel", {
ApplicationRecord.connection.execute('SELECT clients.*,
(CASE WHEN agents_clients.id is NULL then 0 else 1 END)
AS joined FROM clients
LEFT JOIN agents_clients
on clients.id = agents_clients.client_id
INNER JOIN users ON users.id = clients.user_id
WHERE agents_clients.id is NULL OR agents_clients.agent_id = 4
ORDER BY joined, users.name'
)
@Pomeha
Pomeha / recieve_recent.rb
Last active June 21, 2019 21:29
Simple new emails parcer with IMAP for rails with gem 'mail'
# frozen_string_literal: true
class Mails::ReceiveRecent
def call
client = Mails::SetClient.new.call
receive_messages(client)
end
private
# frozen_string_literal: true
class LuckyTickets
def self.call(n)
n = n/2
n2 = 10 ** n - 1
a = Array.new(9 * n + 1) { 0 }
(0..n2).each do |l|
a[l.to_s.chars.map(&:to_i).sum] += 1
end
before do
paypal_payout_object = double
payout_batch = double
allow(payout_batch).to receive_message_chain(:batch_header, :payout_batch_id).and_return(payout_batch_id)
allow(payout_batch).to receive_message_chain(:batch_header, :batch_status).and_return(payout_batch_status)
allow(PayPal::SDK::REST::DataTypes::Payout).to receive(:new).and_return(paypal_payout_object)
allow(paypal_payout_object).to receive(:create).and_return(payout_batch)
end
let(:payout_batch_id) { 1_337 }