Skip to content

Instantly share code, notes, and snippets.

View MichalMazurek's full-sized avatar
😁

Michal Mazurek MichalMazurek

😁
View GitHub Profile
@MichalMazurek
MichalMazurek / mock_file.py
Created March 30, 2017 12:25
Pytest fixture for mocking file open
# author: michal@mazurek-inc.co.uk
@pytest.fixture
def mock_file():
"""Mock file open."""
@contextlib.contextmanager
def contextmanager(file_name: str, content: bytes, obj):
"""
Context manager for mocking file.
#!/bin/env python
import fire
import random
import humanize
import sys
def make_large_file(file: str, size: int, random: bool=False) -> None:
"""
Create a file with random bytes
"""
Version retrieving.
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
import click
from subprocess import run
import os
@click.command()
@click.argument("source_repo", type=str)
@click.argument("source_branch", default="master", type=str)
@click.argument("target_repo", type=str)
@click.argument("target_directory", type=str)
# print only nth column from output
ps ax | awk '{printf "%s\n", $5}'
zsh
ps
tail
awk
# join each line with ","
cat file.txt | awk '{printf (NR>1?",":"") $0}'
from typing import Dict, List
def some_func(value: str, data: List = []) -> Dict or List[str]:
data.append(value)
return data
d = some_func("test")
some_func("test2", d)
print(d)
if not two_factor:
for key_filename in key_filenames:
for pkey_class in (RSAKey, DSSKey, ECDSAKey, Ed25519Key):
try:
key = self._key_from_filepath(
key_filename, pkey_class, passphrase
)
allowed_types = set(
self._transport.auth_publickey(username, key)
)
def _read_private_key(self, tag, f, password=None):
lines = f.readlines()
start = 0
beginning_of_key = "-----BEGIN " + tag + " PRIVATE KEY-----"
while start < len(lines) and lines[start].strip() != beginning_of_key:
start += 1
if start >= len(lines):
raise SSHException("not a valid " + tag + " private key file")
# parse any headers first
...
from typing import Dict, List
import aiohttp
import asyncio
import time
JOKE_URL = "http://api.icndb.com/jokes/random"
async def download_joke(session: aiohttp.ClientSession) -> Dict[str, str]:
@MichalMazurek
MichalMazurek / init.vim
Last active February 27, 2021 16:56
init.vim
:inoremap <C-e> <C-o>$
:inoremap <C-a> <C-o>0
" https://medium.com/better-programming/setting-up-neovim-for-web-development-in-2020-d800de3efacd
" https://jdhao.github.io/2018/12/24/centos_nvim_install_use_guide_en/#the-difference-between-nvim-and-vim
" curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
call plug#begin('~/.local/share/nvim/plugged')