Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sirrobot01's full-sized avatar

Mukhtar Akere sirrobot01

View GitHub Profile
package common
import (
gourl "net/url"
sirrobot01 /
Created January 11, 2022 11:10
Async email sender using Django
def send_email(*args, **kwargs):
return send_mail(*args, **kwargs)
class SendEmail:
def __call__(self, *args, **kwargs):
return*args, **kwargs)
sirrobot01 /
Last active September 13, 2021 09:03
Multi-action endpoint
from .multi_action_view import BaseAction
# Sample action
class CheckDateView(BaseAction):
def print_date(self, *args, **kwargs):
r = Response(data={'current_date':}, status=200)
return r
from django.db import models
class MentionModel(models.Model):
text_field_name = "text"
mention_handler = "handle_mention"
class Meta:
abstract = True
sirrobot01 /
Last active August 29, 2021 19:24
SQLAlchemy model manager
from sqlalchemy.orm import Session
class Manager:
def __init__(self, Model, database: Session):
self.db = database
self.Model = Model
self._query = {} # Instantiate a query, update it on get/filter call
sirrobot01 /
Created July 2, 2021 10:54
Pytest auto_login fixture
import pytest
def password():
return 'my-password-is-stronger-than-yours'
def create_user(db, django_user_model, password):
def _user(**kwargs):
sirrobot01 /
Last active June 11, 2021 15:52
Celery Task runner
from celery.utils.log import get_logger
from django.conf import settings
logger = get_logger(__name__)
class TaskRunner:
def __init__(self, func_code, func, args=[], kwargs={}, task_kwargs={}):
self.func_code = func_code # This could be used to save to db
self.func = func
sirrobot01 /
Last active August 29, 2021 19:38
Checking accuracy score using different ML algorithms
class MultiModel:
test_scores = {}
train_scores = {}
models = {}
def __init__(self, n_models, typeof):
self.n_models = n_models
self.typeof = typeof
def load(self, X_train, X_test, y_train, y_test):