Skip to content

Instantly share code, notes, and snippets.

View mosquito's full-sized avatar
✍️
just writing some code

Mosquito mosquito

✍️
just writing some code
  • Nebius
  • Netherlands
View GitHub Profile
@mosquito
mosquito / demo.ipynb
Last active February 18, 2019 14:01
LOSSY SOUNDS
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mosquito
mosquito / aiofile.ipynb
Last active December 24, 2018 05:44
aiofile tests
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mosquito
mosquito / rgb_color_console.py
Created October 5, 2017 12:35
Set RGB color to string in terminal
def colorize(text, fg=None, bg=None):
result = ''
def parse_hex(h):
h = h.strip("#").ljust(6, '0')
return [int(h[i+i:i+i+2], 16) for i in range(3)]
if bg:
result += '\x1b[48;2;{};{};{}m'.format(*parse_hex(bg))
@mosquito
mosquito / 00-default.conf
Created October 4, 2017 11:40
Nginx Letsencrypt Config
# cat /etc/nginx/sites-enabled/00-default.conf
server {
listen 80 default deferred;
include default.d/*.conf;
location / {
rewrite ^/(.*)$ https://$host/$1 redirect;
}
}
@mosquito
mosquito / proxy.py
Last active May 5, 2022 05:25
AIOHTTP async proxy streaming
import platform
import unittest
from http import HTTPStatus
from urllib.parse import urlencode, unquote
import aiohttp
import asynctest
from aiohttp import web
from aiohttp.test_utils import TestClient
from multidict import MultiDict
@mosquito
mosquito / async-pipe.ipynb
Created September 27, 2017 11:04
AsyncIO PIPE
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mosquito
mosquito / check-rabbitmq.py
Last active September 27, 2017 08:03
Check status of rabbitmq node
from ast import literal_eval
from contextlib import contextmanager
from subprocess import check_output
import re
import sys
def parse_output(input_string):
input_string = input_string.replace("\"", '\'')
input_string = re.sub('([a-zA-Z\@\<\>\_\"\']+)', r'"\1"', input_string)
import logging
from concurrent.futures import Executor
from functools import partial
from multiprocessing.pool import ThreadPool as ThreadPoolBase
log = logging.getLogger()
class ThreadPool(ThreadPoolBase, Executor):
@mosquito
mosquito / sentry_logger.py
Created August 28, 2017 13:21
Sentry tornado async client
# encoding: utf-8
from tornado.gen import Return, coroutine
from tornado.ioloop import IOLoop
import tornado.web
from raven.contrib.tornado import SentryMixin
class SentryHandler(SentryMixin, tornado.web.RequestHandler):
@coroutine
def _execute(self, transforms, *args, **kwargs):
@mosquito
mosquito / aio_pipe.py
Last active March 1, 2024 16:46
Asyncio PIPE
import asyncio
import fcntl
import os
from functools import partial
class AsyncPIPE:
@staticmethod
def create_pipe():
read_fd, write_fd = os.pipe()