Skip to content

Instantly share code, notes, and snippets.

View marazmiki's full-sized avatar

Mikhail Porokhovnichenko marazmiki

View GitHub Profile
@marazmiki
marazmiki / stream_response.py
Created August 16, 2024 18:30 — forked from obskyr/stream_response.py
How to stream a requests response as a file-like object.
# -*- coding: utf-8 -*-
import requests
from io import BytesIO, SEEK_SET, SEEK_END
class ResponseStream(object):
def __init__(self, request_iterator):
self._bytes = BytesIO()
self._iterator = request_iterator
@marazmiki
marazmiki / compress_tar_gzip.go
Created March 5, 2024 03:53 — forked from mimoo/compress_tar_gzip.go
How to compress a folder in Golang using tar and gzip (works with nested folders)
package main
import (
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"io"
"os"
"path/filepath"
@marazmiki
marazmiki / nginx.conf
Created February 24, 2024 16:40 — forked from Voronenko/nginx.conf
nginx proxy private s3 bucket
worker_processes 1;
daemon off;
error_log /dev/stdout info;
pid /usr/local/var/nginx/nginx.pid;
events {
worker_connections 1024;
}
@marazmiki
marazmiki / Ansible Let's Encrypt Nginx setup
Created January 23, 2023 11:51 — forked from mattiaslundberg/Ansible Let's Encrypt Nginx setup
Let's Encrypt Nginx setup with Ansible
Ansible playbook to setup HTTPS using Let's encrypt on nginx.
The Ansible playbook installs everything needed to serve static files from a nginx server over HTTPS.
The server pass A rating on [SSL Labs](https://www.ssllabs.com/).
To use:
1. Install [Ansible](https://www.ansible.com/)
2. Setup an Ubuntu 16.04 server accessible over ssh
3. Create `/etc/ansible/hosts` according to template below and change example.com to your domain
4. Copy the rest of the files to an empty directory (`playbook.yml` in the root of that folder and the rest in the `templates` subfolder)
@marazmiki
marazmiki / spinner.py
Created August 6, 2022 06:21 — forked from nicodebo/spinner.py
Simple Python CLI Spinner
from enum import Enum
import itertools
import sys
import time
import threading
class Sequence(Enum):
"""Enumeration of spinner sequence
@marazmiki
marazmiki / upload_to_s3.py
Created July 23, 2022 05:49 — forked from skonik/upload_to_s3.py
Asyncio S3 Multipart Upload
# Details https://skonik.me/uploading-large-file-to-s3-using-aiobotocore/
import asyncio
import math
import os
import aiobotocore
import aiofiles
AWS_S3_HOST = 'http://localhost:9000'
AWS_SECRET_ACCESS_KEY = 'SECRET_KEY'
import re
class AcceptLanguage:
__regex = re.compile(r";q=([\d.]+),?", re.I)
__jail = object()
@classmethod
def parse(cls, string: str) -> "AcceptLanguage":
instance = cls(cls.__jail, string)
instance.__do_parse()
import pytest
import psycopg2
from pytest_docker_containers.fixtures import docker_container_fixture
pytest_plugins = [
'pytest_docker_containers.plugin',
]
@marazmiki
marazmiki / is-private-mode.js
Created August 3, 2020 04:41 — forked from jherax/is-private-mode.js
Detect if the browser is running in Private mode (Promise based)
/**
* Lightweight script to detect whether the browser is running in Private mode.
* @returns {Promise<boolean>}
*
* Live demo:
* @see https://output.jsbin.com/tazuwif
*
* This snippet uses Promises. If you want to run it in old browsers, polyfill it:
* @see https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js
*
const Loader = {
require (scripts, callback) {
this.loadCount = 0;
this.callback = callback;
this.totalRequired = scripts.length;
scripts.forEach((src) => {
this.writeScript(src)
});
},
loaded (evt) {