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'
@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
*
@marazmiki
marazmiki / gist:69e45ebb8b153e9c2c7040bed8e4917d
Created July 7, 2018 03:57 — forked from Bouke/gist:11261620
Multiple Python installations on OS X

Previous versions used homebrew to install the various versions. As suggested in the comments, it's better to use pyenv instead. If you are looking for the previous version of this document, see the revision history.

$ brew update
$ brew install pyenv
$ pyenv install 3.5.0
$ pyenv install 3.4.3
$ pyenv install 3.3.6
$ pyenv install 3.2.6
$ pyenv install 2.7.10

$ pyenv install 2.6.9

@marazmiki
marazmiki / letsencrypt_2017.md
Created March 15, 2018 15:57 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

@marazmiki
marazmiki / weasyprint_complex_headers.py
Created March 16, 2017 14:53 — forked from pikhovkin/weasyprint_complex_headers.py
Repeat on each page of complex headers (eg, tables) except the first page
# coding: utf-8
from weasyprint import HTML, CSS
def get_page_body(boxes):
for box in boxes:
if box.element_tag == 'body':
return box