Skip to content

Instantly share code, notes, and snippets.

View tribals's full-sized avatar

Anthony tribals

  • Тамбов
View GitHub Profile
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?
# 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
@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|
@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 / 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 / Pipfile
Last active October 19, 2017 13:54
Flask app.config in different thread
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[dev-packages]
@tribals
tribals / Pipfile
Last active January 11, 2024 16:22
Understanding SQL row locking - `SELECT FOR UPDATE`
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[packages]
SQLAlchemy = "*"
"psycopg2-binary" = "*"
[dev-packages]
@tribals
tribals / imports.py
Created March 7, 2019 11:50
Crude implementation of tool which helps to analyze Python imports: find unused, find used, etc...
import ast
import logging
import operator as op
import signal
import sys
import astor
logging.basicConfig(level=logging.INFO, stream=sys.stdout, format='%(message)s')
@tribals
tribals / docker-compose.yml
Last active August 13, 2020 11:29
Usage of Pendulum's `DateTime` in SQLAlchemy columns of type `DateTime`
version: '3.7'
services:
postgres:
image: postgres:12.3
environment:
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
(use-modules (gnu packages base))
(use-modules (guix build-system copy))
(use-modules (guix download))
(use-modules (guix packages))
(use-modules (guix licenses))
(define-public u-boot-khadas-vim3l
(package
(name "u-boot-khadas-vim3l")
(version "2020.04")