Skip to content

Instantly share code, notes, and snippets.

View tribals's full-sized avatar

Anthony tribals

  • Тамбов
View GitHub Profile
@tribals
tribals / task.py
Last active July 11, 2017 19:39 — forked from anonymous/task.py
Task
"""
В таблице 'orders' находится 15млн записей. Необходимо проверить все заказы в статусе 'hold' пачками по 100шт.
Статус заказа проверяется в функции 'mark_random_orders_accepted', эта функция ставит рандомное кол-во заказов
в статус 'accepted', т.е. '1'. Кол-во, переведенных в статус 'accepted' заказов неизвестно.
Необходимо написать оптимальное решение. Нельзя выгружать все заказы в память(вызов .all() в SQLAlchemy).
"""
class Order(Base):
__tablename__ = 'orders'
@tribals
tribals / threads.py
Last active March 12, 2018 19:13
Simple watcher/worker implementation using threads (study)
#!/usr/bin/env python3
import argparse
import signal
import threading
import time
from queue import Queue
sentinel = object() # guaranteed to be unique
@tribals
tribals / fuzzbuzz.rb
Last active October 3, 2020 10:02
OO-style FuzzBuzz solution in Ruby
class FuzzBuzz
attr_reader :n, :fuzzbuzzable
def initialize(n, fuzzbuzzable)
@n = n
@fuzzbuzzable = fuzzbuzzable
end
def do_it
n.times do |i|
# assuming that `things` is an array of hashes which we want to process in some way
things = [
{ one: 42, two: 'spam' },
# ... and so on
{ one: 24, two: 'maps' }
]
things.map do |thing|
hsh = {}
hsh[:number] = thing[:one] * 2 + 3 # or whatewer
errors = []
items = %w(one two three)
items.each do |i|
if i == 'two'
errors << 'ZOMG TEH ERRR!11'
end
puts i
end if errors.empty?