Skip to content

Instantly share code, notes, and snippets.

View oduvan's full-sized avatar
✂️
Cleanup

Alexander Lyabah oduvan

✂️
Cleanup
  • CheckiO Inc.
  • United States
View GitHub Profile
from functools import cached_property
class DataProxy:
def __init__(self, user):
self.user = user
@cached_property
def plan(self):
return DBModel.objects.get(id=67)
@oduvan
oduvan / the_longest_function.py
Created March 3, 2024 16:55
Find Top 10 longest functions in your source folder
import os
import re
def find_functions(file_path):
"""
Extracts functions and their line counts from a given Python file.
"""
with open(file_path, 'r') as file:
lines = file.readlines()
@oduvan
oduvan / django_unused_views.py
Created June 7, 2021 06:38
Showing usused views in Django by parsing nginx acces log
SKIP_MODULES = ('django', 'simple_history')
ACCESS_FILES = [
'/var/log/nginx/access.log',
'/var/log/nginx/access.log.1',
'/var/log/nginx/access.log.2',
] + ['/var/log/nginx/access.log.{}.gz'.format(i) for i in range(3, 31)]
RE_SEARCH_URL = r'(?:(?:POST)|(?:GET)|(?:PATCH)|(?:PUT)|(?:OPTIONS)|(?:DELETE)|(?:HEAD))\s([^\s\?]+)'
def SKIP_MATCH(url):
return requested_url.startswith('/static/')
@oduvan
oduvan / overwrite_default_connection.py
Created March 30, 2020 10:57
Switch django default connection inside of context. It is very useful when you use readonly replica in Jupyter for analytics, but time to time you need to implement changes in master db
from contextlib import ContextDecorator
from django.db import connections
class overwrite_default_connection(ContextDecorator):
prev_default = None
write_connection = None
def __init__(self, write_connection):
self.write_connection = write_connection
@oduvan
oduvan / battle.py
Created December 7, 2019 13:49
battle field configuration for Empire of Code
from gen import players, crystalite_farm, sentry_gun, command_center, attack_craft
PLAYERS = players([
command_center([28, 18], level=2),
crystalite_farm([25, 19], level=2),
sentry_gun('def_code.py', [27, 23], level=1),
attack_craft(1, 'attacker.py', unit_quantity=6)
])
@oduvan
oduvan / attack.py
Created December 7, 2019 13:06
basic code for Python in Empire of Code . com
from battle import commander
# create craft object
craft_client = commander.CraftClient()
# command to craft - start landing units
craft_client.do_land_units()
def unit_landed(data):
# create unit object
unit_client = commander.UnitClient(data['id'])
@oduvan
oduvan / attack.js
Created December 7, 2019 13:00
basic attack code for JS in EmpireofCode.com
var commander = require("battle/commander.js");
// create craft object
var craftClient = new commander.CraftClient();
// command to craft - start landing units
craftClient.doLandUnits();
function unitLanded(data) {
// create unit object
var unitClient = new commander.UnitClient(data['id']);
@oduvan
oduvan / cio_dump.py
Last active October 10, 2019 12:49
json for np.ndarray, range and Iterator
import numpy as np
import json
from collections.abc import Iterator, Sequence
class CiOJSEncoderEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
if isinstance(obj, np.generic):
return obj.item()
$ sudo pip3 install checkio-client
sudo pip3 install checkio-client