Skip to content

Instantly share code, notes, and snippets.

View zobayer1's full-sized avatar
🚧
What should I do next?

Zobayer Hasan zobayer1

🚧
What should I do next?
View GitHub Profile
@zobayer1
zobayer1 / elastic_scroll.py
Last active November 14, 2020 23:26
Simple generator function to download Elasticsearch index data using scroll query
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
class ElasticScroll(object):
"""Manages scroll contexts for elasticsearch scroll queries.
Args:
host (str): Elasticsearch host url. Example: ``http://localhost:9200``.
index (str): Elasticsearch index name. Example: ``my_index``.
@zobayer1
zobayer1 / fedora_post_install.md
Last active April 4, 2024 12:06
Fedora 36 post installation notes for software developers. Things you should do after installing your new Fedora 36 workstation.

Fedora 36 Post Installation (For Software Developers)

Top N things you should do after installing or upgrading to your new Fedora 36 workstation.


Settings

Change Hostname

@zobayer1
zobayer1 / fedora_install_python3.md
Last active June 24, 2024 17:17
Install Python 3.6, 3.7, 3.8 in your Fedora system

Python 3.9 comes as a default with Fedora 34. However, sometimes you may wish to install older versions for development and test purposes. Apart from groupinstall command, these instructions work for CentOS and REHL systems as well.

Prerequisites

Install python development dependencies.

sudo dnf groupinstall "Development Tools"
sudo dnf install python3-devel openssl-devel zlib-devel bzip2-devel sqlite-devel libffi-devel

Note: You will need to rebuild and reinstall if you install new source or development libraries for python. Do not create or modify symlinks for python, python3, etc, as that may and will break many dependent libraries in your system.

@zobayer1
zobayer1 / pytest_parametrize.md
Last active August 26, 2022 04:13
Using pytest parametrize with indirect for multiple test functions

Using pytest.mark.parametrize with other fixtures

Introduction

When you want to run tests against multiple test parameters, but you have to use other pytest.fixture objects, you can use pytest.mark.parametrize with indirect parameter to target a fixture for extracting request.param from parametrize list.

Example

@zobayer1
zobayer1 / Makefile
Last active May 24, 2024 08:53
Generic Makefile for C++ projects with multiple cpp and h files
# Pre-compiler and Compiler flags
CXX_FLAGS := -Wall -Wextra -std=c++17 -ggdb
PRE_FLAGS := -MMD -MP
# Project directory structure
BIN := bin
SRC := src
LIB := lib
INC := include
MAINFILE := $(SRC)/main.cpp
@zobayer1
zobayer1 / Elasticsearch Bulk Indexing
Last active June 28, 2022 23:43
Elasticsearch bulk API usage example
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import requests
class ElasticBulk(object):
"""Class for indexing documents in bulk"""
@zobayer1
zobayer1 / cron_job_checklist.md
Created November 22, 2020 15:43
WTF! My cron job doesn't run?!$#%

WTF??? My cron job doesn't run?!$#%

Source: This SO Answer

Here's a checklist guide to debug not running cronjobs:

  • Is the Cron daemon running?
    • Run ps ax | grep cron and look for cron.
  • Debian: service cron status, if not running, service cron start or service cron restart
@zobayer1
zobayer1 / paho_mqtt.py
Created January 18, 2021 14:48
Wrapper class for Python Paho MQTT client with callbacks and auto reconnect.
# -*- coding: utf-8 -*-
import click
from paho.mqtt.client import Client
class MQTTClient(object):
"""Manages Paho MQTT client lifecycle and callbacks"""
def __init__(self, config: dict, message_processor=None):
self.config = config
@zobayer1
zobayer1 / htpasswd.md
Created January 25, 2021 21:17
Bcrypt password generator for htpasswd with Python

Generator:

# file: gen.py

import bcrypt

def encrypt_password(username, password):
    bcrypted = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt(rounds=12)).decode("utf-8")
 return f"{username}:{bcrypted}"
@zobayer1
zobayer1 / loader.py
Last active December 1, 2023 16:01
Parsing environment variables in an YAML file using PyYAML library
"""A simple yaml loader
Load the content of an yaml file into a python dict. Environment variable can be specified with ${VAR_NAME}. A
default string value can be specified with ${VAR_NAME:DEFAULT}. Able to process multiple occurrences.
requirement: PyYAML
run: python loader.py
"""
import os