Skip to content

Instantly share code, notes, and snippets.

View ahmetkotan's full-sized avatar
🗿
stone age

ahmet kotan ahmetkotan

🗿
stone age
View GitHub Profile
@ahmetkotan
ahmetkotan / OctoxlabsBackendEngineerCaseStudy.md
Last active March 14, 2024 09:01
Octoxlabs Backend Engineer Case Study

Octoxlabs Backend Engineer Case Study

We aim to develop a composite application utilizing Docker and docker-compose, which comprises two services: your Django REST Framework endpoint and an Elasticsearch service. The Django REST Framework endpoint should include minimum two features:

  • Authentication Mechanism: We are looking for an authentication method similar to JWT. For instance, if there is a user with the username "octoAdmin," we would add an Authorization header as "Octoxlabs base64(octoAdmin)". This token should uniquely identify the user "octoAdmin".
  • Endpoint: Consider having data structured as an array like [{"Hostname": "octoxlabs01", "Ip": ["0.0.0.0"]}] stored in the Elasticsearch service. We expect to query your endpoint with "Hostname = octoxlabs*" and have this query translated into the JSON format for Elasticsearch. Please avoid using query_string in Elasticsearch, if possible. The scenario involves the endpoint converting the "Hostname = octoxlabs*" query into an Elas
@ahmetkotan
ahmetkotan / OctoxlabsSeniorBackendEngineerCaseStudy.md
Last active March 11, 2024 10:21
Octoxlabs Senior Backend Engineer Case Study

Octoxlabs Senior Backend Engineer Case Study

We aim to develop a composite application utilizing Docker and docker-compose, which comprises minimum five services: your Django REST Framework endpoint, query converter service(django, flask, fastapi etc.), logger service(celery or implement your handler if possible), a message queue service and an Elasticsearch service. The Django REST Framework endpoint should include minimum two features:

  • Authentication Mechanism: We are looking for an authentication method similar to JWT. For instance, if there is a user with the username "octoAdmin," we would add an Authorization header as "Octoxlabs base64(octoAdmin)". This token should uniquely identify the user "octoAdmin".
  • Endpoint: Consider having data structured as an array like [{"Hostname": "octoxlabs01", "Ip": ["0.0.0.0"]}] stored in the Elasticsearch service. We expect to query your endpoint with "Hostname = octoxlabs*" and have this query translated into the JSON format for Elasticsearch
@ahmetkotan
ahmetkotan / find_deleted_string.py
Last active November 7, 2023 11:28
Find new string for unique fields in django soft delete operation
# Standard Library
from typing import Dict
# Django Stuff
from django.apps import apps
def find_deleted_string(model_name: str, **kwargs) -> Dict[str, str]:
parameters = {key: f"{value}<d>" if isinstance(value, str) else value for key, value in kwargs.items()}
model_class = apps.get_model(model_name)
@ahmetkotan
ahmetkotan / celery_with_multi_tenant.py
Last active October 20, 2023 08:54
Implement Celery to Multi-Tenant Architecture
# Standard Library
import logging
# Third Party
from celery import Celery
from celery.app.amqp import AMQP
from celery.app.task import Task
from django_tenants.utils import schema_context
# Django Stuff
"""
Name Generator with Python.
Ref; https://github.com/moby/moby/blob/c90254c7464cac5c56e7ab9e6b1857c119d5d263/pkg/namesgenerator/names-generator.go
"""
import random
left = ["admiring", "adoring", "affectionate", "agitated", "amazing", "angry", "awesome", "beautiful", "blissful",
"bold", "boring", "brave", "busy", "charming", "clever", "cool", "compassionate", "competent", "condescending",
@ahmetkotan
ahmetkotan / kubernetes_api_exec.py
Last active November 1, 2020 11:55
Run command on container from another container on same pod with kubernetes api
from kubernetes import client
from kubernetes.stream import stream
import os
import sys
if len(sys.argv) < 4:
print(f"Usage: {sys.argv[0]} <pod_name> <container_name> <command>")
sys.exit(1);
@ahmetkotan
ahmetkotan / mmdb_to_csv.py
Last active April 2, 2020 22:22
MMDB Geo Location DB to CSV
import argparse
import os
import sys
import re
import geoip2.database
from geoip2.errors import AddressNotFoundError
# pip install geoip2
@ahmetkotan
ahmetkotan / parse_elf.c
Created February 10, 2020 05:42
ELF Parser in C
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <sys/mman.h>
#include <elf.h>
#include <assert.h>
/**
@ahmetkotan
ahmetkotan / README.md
Last active April 14, 2018 23:02
Python Argument Parser and Creater from Raw String/Text

Raw String Argument Parser

Example

parser = RawParser('example.py -x Xparam1 -y Yparam1-0,Yparam1-1 -y "Yparam 2" -z Zparam1 --zet=Zparam2 --zet="Zparam 3"')
parser.add_arg('-x')
parser.add_arg('-y', splitter=",")
parser.add_arg('-z', 'zet')
parser.parse_args()