Skip to content

Instantly share code, notes, and snippets.

View Derfirm's full-sized avatar

Andrew Grinevich Derfirm

View GitHub Profile
@neumond
neumond / fix_zip.py
Last active July 12, 2020 16:05
Util to fix names in zip files created under Windows
"""
Util to fix names in zip files created under Windows.
Usage:
First decide whether you really need to fix your archive,
or whether this program is able fix it correctly
(operation is read-only):
python fix_zip.py archive.zip
@DusanMadar
DusanMadar / TorPrivoxyPython.md
Last active July 7, 2024 04:59
A step-by-step guide how to use Python with Tor and Privoxy

A step-by-step guide how to use Python with Tor and Privoxy

Latest revision: 2021-12-05.

Tested on Ubuntu 18.04 Docker container. The Dockerfile is a single line FROM ubuntu:18.04. Alternatively, you can simply run docker run -it ubuntu:18.04 bash.

NOTE: stopping services didn't work for me for some reason. That's why there is kill $(pidof <service name>) after each failed service <service name> stop to kill it.

References

@zmts
zmts / tokens.md
Last active July 17, 2024 07:29
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
@vxgmichel
vxgmichel / aioudp.py
Last active July 4, 2024 20:24
High-level UDP endpoints for asyncio
"""Provide high-level UDP endpoints for asyncio.
Example:
async def main():
# Create a local UDP enpoint
local = await open_local_endpoint('localhost', 8888)
# Create a remote UDP enpoint, pointing to the first one
@palankai
palankai / specification.py
Last active March 29, 2024 10:02
Python Specification Pattern
class Specification:
def __and__(self, other):
return And(self, other)
def __or__(self, other):
return Or(self, other)
def __xor__(self, other):
return Xor(self, other)
@rponte
rponte / get-latest-tag-on-git.sh
Last active July 4, 2024 10:55
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@brake
brake / argparse_demo.py
Created March 7, 2015 19:32
2.5 argparse tricks (sample code)
# -*- coding: UTF-8 -*-
"""
CLI скрипт, поддерживающий две ветви параметров:
userdb.py append <username> <age>
userdb.py show <userid>
Заглушка предусматривает, что:
пользователь с именем admin уже существует
по userid = 1 всегда возвращается User(name='admin', age=20)
@ikudriavtsev
ikudriavtsev / gunicorn_restart.py
Created March 12, 2014 20:46
Graceful restart of gunicorn server
# the idea is taken from here: http://unicorn.bogomips.org/SIGNALS.html
import os
import signal
# first we need to get the master process id
# it might be stored in a .pid file, e.g.
# let's assume we have the id in `master_pid`
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active July 16, 2024 15:14
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@koblas
koblas / smtp.py
Created November 11, 2011 15:23
SMTP Client for Tornado
from tornado import ioloop
from tornado import iostream
import socket
class Envelope(object):
def __init__(self, sender, rcpt, body, callback):
self.sender = sender
self.rcpt = rcpt[:]
self.body = body
self.callback = callback