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
@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)
}
}
# 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
@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
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 }
jQuery.datetimepicker.setLocale('ru');
$.validate({
lang : 'ru',
errorElementClass : 'is-invalid'
});
// script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"
.chat-messages
.row.flex-nowrap.message-row.contact.p-4
img.avatar.mr-4[src="../assets/images/avatars/Barrera.jpg"]
.bubble
.message
| Quickly come to the meeting room 1B, we have a big server issue
.time.text-muted.text-right.mt-2
| 20 Mar 16 15:14
.row.flex-nowrap.message-row.user.p-4
img.avatar.mr-4[src="../assets/images/avatars/profile.jpg" alt="John Doe"]
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'
)