Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Schepanovski Suor

View GitHub Profile
@Suor
Suor / sizes.py
Last active Oct 30, 2021
Different way to calculate struct size
View sizes.py
import gc
import sys
import types
from collection import deque
import random
def getsize(obj):
BLACKLIST = type, types.ModuleType, types.FunctionType
if isinstance(obj, BLACKLIST):
@Suor
Suor / INSTALL.markdown
Created Nov 7, 2011
open_file_at_cursor sublime command
View INSTALL.markdown
cd ~/.config/sublime-text-2/Packages/User/
curl -O https://raw.github.com/gist/1344471/open_file_at_cursor.py

Open keyboard bindings file, and add a line to it

[
    ...
    { "keys": ["alt+o"], "command": "open_file_at_cursor" } // this one
@Suor
Suor / mod_fix_ambitions.nut
Created Jan 21, 2021
Battle Brothers: debug ambitions not happening
View mod_fix_ambitions.nut
::mods_registerMod("mod_fix_ambitions", 0.1, "Fix ambitions not fullfilling");
::mods_queue("mod_fix_ambitions", "mod_hooks(>=19)", function() {
this.logInfo("fa: loading");
::mods_hookNewObject("ambitions/ambition_manager", function(obj) {
this.logInfo("fa: hook ambition manager");
local update = obj.update;
obj.update = function() {
this.logInfo("fa: ambitions.update available=" + this.isAvailable() + " ambition=" + this.m.ActiveAmbition);
@Suor
Suor / getsize.py
Created Jan 15, 2021
Get python structure total memory size
View getsize.py
def getsize(obj):
import sys
from types import ModuleType, FunctionType
from gc import get_referents
BLACKLIST = type, ModuleType, FunctionType
if isinstance(obj, BLACKLIST):
raise TypeError('getsize() does not take argument of type: '+ str(type(obj)))
seen_ids = set()
size = 0
objects = [obj]
@Suor
Suor / hook_on_init.nut
Last active Dec 5, 2020
Hook enemy onInit
View hook_on_init.nut
local gt = this.getroottable();
::mods_hookNewObject("entity/tactical/enemies/orc_berserker", function(o) {
this.logInfo("tb: hook orc_berserker");
local init = o.onInit;
o.onInit = function() {
this.logInfo("tb: orc_berserker onInit");
View tb_orc_berserker_agent.nut
this.tb_orc_berserker_agent <- this.inherit("scripts/ai/tactical/orc_berserker_agent", {
m = {},
function create()
{
this.orc_berserker_agent.create();
this.m.Properties ...
}
function onAddBehaviors()
{
this.orc_berserker_agent.create();
@Suor
Suor / pprint.nut
Created Nov 11, 2020
Logger pretty printer in Squirrel
View pprint.nut
::mods_registerMod("mod_standout_foes", 0.1, "Standout foes");
local gt = this.getroottable();
// Alias to make it easier for us inside. Things are still global and accessible from outside,
// so if anyone will want to write a mod for this mod then it should be easy enough.
local sf = gt.StandoutFoes <- {};
local Debug = gt.StandoutFoes.Debug <- {};
@Suor
Suor / web-app.md
Last active Mar 2, 2020
Web App doc
View web-app.md

Application

Language: Python 3.7.
Framework: Django, Django Rest Framework
Libraries: [django-allauth][], celery
Storage: PostgreSQL, Redis for cache and queues. May also use lazy queues over PostgreSQL, may shift non-lazy queues to RabbitMQ.

Front-end:

  • any popular framework chosen by front-end team,
@Suor
Suor / log_requests.py
Last active Feb 3, 2020
Log HTTP requests in Django
View log_requests.py
import re, logging
from django.conf import settings
from django.core.handlers.wsgi import STATUS_CODE_TEXT
req_handler = logging.FileHandler(settings.HOME_DIR + '/logs/requests.log')
req_handler.setLevel(logging.INFO)
formatter = logging.Formatter('[%(asctime)s] %(message)s')
req_handler.setFormatter(formatter)
@Suor
Suor / scrape.py
Created Feb 1, 2020
aioscrape perekrestok example
View scrape.py
from aioscrape import settings, fetch, run
from parsechain import C
async def scrape():
resp = await fetch('https://www.perekrestok.ru/')
print(resp.css('.xf-product').map({
'id': C.attr('data-id').int,
'name': C.attr('data-gtm-product-name')
}))