Skip to content

Instantly share code, notes, and snippets.

View mebaysan's full-sized avatar
🏠
Working from home

Baysan mebaysan

🏠
Working from home
View GitHub Profile
@mebaysan
mebaysan / warning_ignore.py
Created April 23, 2024 09:39
Warning ignore while working with Python.
# You can also use this section to suppress warnings generated by your code:
def warn(*args, **kwargs):
pass
import warnings
warnings.warn = warn
warnings.filterwarnings('ignore')
import os
@mebaysan
mebaysan / README.md
Last active January 6, 2024 08:22
Django Custom User Event Logging

Custom Event Logging

The Custom Event Logging system is designed to bolster observability, accountability, and security within your application. It offers a structured approach to log diverse user activities and system events. By leveraging this logging mechanism, you can systematically track and monitor user interactions, system operations, and security-related events in the database.

This system comprises models like EventLog and UserLog, alongside essential helper functions such as log_user. These components collectively enable the creation of detailed logs tailored to different system functionalities. The approach utilizes Django's robust framework to categorize and store logs efficiently, enhancing the application's visibility and traceability.

image

Models

@mebaysan
mebaysan / formatter.py
Last active October 11, 2023 11:15
Django custom logging in JSON
# helpers.logging.formatter
import logging
import json
class JSONFormatter(logging.Formatter):
def format(self, record):
log_data = {
"timestamp": self.formatTime(record),
"level": record.levelname,
@mebaysan
mebaysan / convert.sh
Last active June 6, 2023 06:07
Ubuntu Screen Recorder WEBM to MP4
#! /bin/bash
# sudo apt-get install ffmpeg
# if ffmpeg is not installed, install it
if ! [ -x "$(command -v ffmpeg)" ]; then
sudo apt-get install ffmpeg
fi
# if no arguments are given, print usage
@mebaysan
mebaysan / ajax_method_caller.py
Last active January 6, 2024 07:54
Django Ajax Method Caller for Stunning Ajax Calls
# Medium article: https://medium.com/codex/django-ajax-calls-stunning-crafty-method-abaf6b828023
# helpers/dynamic_importer.py
import importlib
class DynamicImporter:
def import_module(self, module_name):
return importlib.import_module(module_name)
@mebaysan
mebaysan / country_state.json
Created February 26, 2023 11:01 — forked from manishtiwari25/country_state.json
List Of Countries With States And Other Useful Information, Updated On 02/01/2023 00:00:07
[
{
"name": "Andorra",
"countryCode": "AD",
"countryCodeAlpha3": "AND",
"phone": "376",
"currency": "EUR",
"stateProvinces": [
{
"name": "Sant Julià de Loria"
# !pip install pandas
import pandas as pd
def read_gsheet(google_sheet_id, work_sheet_name):
# google_sheet_id => You can find the sheet id in the url of your file behind “d/”, copy it from your browser and paste it into your code. The sheet name is the name you gave your sheet.
url = f"https://docs.google.com/spreadsheets/d/{google_sheet_id}/gviz/tq?tqx=out:csv&sheet={work_sheet_name}"
return pd.read_csv(url)
read_gsheet("","")
@mebaysan
mebaysan / fedora-docker-k8s-install-init.sh
Last active December 27, 2022 08:24
Docker and Kubernetes Installation for Fedora
#! /bin/bash
if ! [ $USER = root ]
then
echo run this script with sudo
exit 3
fi
# setting MYOS variable
@mebaysan
mebaysan / README.md
Last active December 6, 2022 17:07
DevOps-101 | Gerçek Bir CI & CD Pipeline: Docker - Jenkins - GitHub Actions - Nginx
@mebaysan
mebaysan / plotly-bar-rounded-edge-chart.js
Created October 15, 2022 16:03
A function to generate rounded-edge bar charts in Plotly
var hr_bar_data = {{hr_bar_data|safe}}; // Django template language syntax
var bar_trace = {
x: [],
y: [],
name: 'HR Bar',
orientation: 'h',
marker: {
color: '#5058B8',
width: 1