Skip to content

Instantly share code, notes, and snippets.

View sirrobot01's full-sized avatar
👽
Daemonic

Mukhtar Akere sirrobot01

👽
Daemonic
View GitHub Profile
package common
import (
"bytes"
"encoding/json"
"encoding/xml"
"io"
"net/http"
gourl "net/url"
"strings"
@sirrobot01
sirrobot01 / celery_email_sender.py
Created January 11, 2022 11:10
Async email sender using Django
@app.task
def send_email(*args, **kwargs):
time.sleep(1000000)
return send_mail(*args, **kwargs)
class SendEmail:
def __call__(self, *args, **kwargs):
return self.run(*args, **kwargs)
@sirrobot01
sirrobot01 / actions.py
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': datetime.now()}, 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
sirrobot01 / manager.py
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
sirrobot01 / conftest.py
Created July 2, 2021 10:54
Pytest auto_login fixture
import pytest
@pytest.fixture
def password():
return 'my-password-is-stronger-than-yours'
@pytest.fixture
def create_user(db, django_user_model, password):
def _user(**kwargs):
@sirrobot01
sirrobot01 / task_runner.py
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
sirrobot01 / mmodel.py
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):