Skip to content

Instantly share code, notes, and snippets.

View spumer's full-sized avatar
🔀
Developing is not your fate, is your choice

spumer

🔀
Developing is not your fate, is your choice
View GitHub Profile
@spumer
spumer / swagger.py
Created November 21, 2022 12:05
pytest fixture for fastapi-jsonrpc. Check returned errors described in swagger (app.method(..., errors=[...]))
import collections
import contextlib
import traceback
import jsonrpcapi
import pytest
from testing import AnyDict
@spumer
spumer / testing.py
Created August 23, 2021 07:48
AnyDict, UnorderedList
import collections
from collections import UserDict
from collections import UserList
def maybe_hdict(value):
if isinstance(value, dict) and not isinstance(value, HDict):
return HDict(value)
return value
@spumer
spumer / testing.py
Last active August 21, 2021 11:38
ReStr - allow you compare string with regular expression (helpful for testing)
import re
class ReStr:
"""
>>> ReStr(r'\d+') == '0000000'
True
>>> ReStr(r'\d.\ds remain') == '0.0s remain'
""" # noqa: W605
@spumer
spumer / wait_db.py
Created April 18, 2021 12:16
django_wait_db_command
import logging
import time
from django.core.management.base import BaseCommand
from django.core.management.base import CommandError
from django.db import connections
from django.db.utils import OperationalError
logger = logging.getLogger(__name__)
@spumer
spumer / db_lock.py
Created September 4, 2020 10:09
SessionLock for PG (pg_try_advisory_lock)
import contextlib
import logging
import time
log = logging.getLogger(__name__)
class SessionLock:
def __init__(self, connection, lock_id: int):
"""
@spumer
spumer / GeoLite2_Import.sh
Created April 22, 2019 09:54
GeoLite2 for HLstatsX
#!/bin/sh
# HLstatsX Community Edition - Real-time player and clan rankings and statistics
# Copyleft (L) 2008-20XX Nicholas Hastings (nshastings@gmail.com)
# http://www.hlxcommunity.com
#
# HLstatsX Community Edition is a continuation of
# ELstatsNEO - Real-time player and clan rankings and statistics
# Copyleft (L) 2008-20XX Malte Bayer (steam@neo-soft.org)
# http://ovrsized.neo-soft.org/
#
@spumer
spumer / celery.py
Created December 4, 2018 09:35
Django celery dlx
class Celery(celery.Celery):
def on_config_ready(self):
"""This method should be called manually after all configuration prepares
"""
assert DeclareDLXnDLQ not in self.steps['worker']
conf = self.conf
@spumer
spumer / gpl.sublime-snippet
Last active August 16, 2021 18:14
Snippet for Sublime Text 2 with GPL License text from http://www.gnu.org/licenses/gpl-howto.html
<snippet>
<content><![CDATA[/**
* ${0:${TM_FILENAME}}
* This file is part of ${1:<program name>}
*
* Copyright (C) ${2:<year>} - ${3:<your name>}
*
* ${1:<program name>} is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
@spumer
spumer / log_strip.sh
Last active December 21, 2015 12:28
Log stripper. Used for strip Sourcemod cmd_*.log files. Line will be skipped if pattern from dictionary will be found. How to use: * Linux: use "log_stripper.sh /path/to/log/dirs/" i recommend create one dir with symlinks to log dirs, for more performance * Windows: drag file to .exe or use command "stripper you_file.log" and stripped version wi…
#!/bin/bash
ionice -c3 -p$$
cd $(dirname $0)
LOGFILE=`find $1 -name "cmd_$(date +%m.%d.%y --date='(date) - 1 day').log"`
for file in $LOGFILE;do
echo $file
cat $file | ./stripper > $file.stripped
done