Skip to content

Instantly share code, notes, and snippets.

Avatar

Phillip Kigenyi codephillip

View GitHub Profile
View classroom2.py
import csv
import random
import re
"""
Helps us find the number in between two brackets ie (33)
"""
def find_between(text, start, end):
View uat_extractor.py
import csv
import random
import re
"""
Helps us find the number in between two brackets ie (33)
"""
def find_between(text, start, end):
return re.findall(re.escape(start) + "(.*)" + re.escape(end), text)[0].strip()
View classroom.py
class School:
def __init__(self, name, location):
self.name = name
self.location = location
class Student:
def __init__(self, name, age, school):
self.name = name
self.age = age
View event_dataclasses.py
from dataclasses import dataclass, asdict
from typing import List
from ms_foobar_app.utils.utilities import snake_case_dict_to_camel
@dataclass
class SmsMessage:
phone_numbers: List[str]
message: str
View register_event_listeners.py
from django.core.management.base import BaseCommand
from ms_foobar_app.events.event_listener import EventListener
class Command(BaseCommand):
def handle(self, *args, **options):
bus = EventListener()
bus.run()
bus.subscribe()
View event_publisher.py
from ms_foobar_app.events.event_bus_root import EventBus
class EventPublisher(EventBus):
def __init__(self):
super(EventPublisher, self).__init__()
def publish(self, subject, data):
self.loop.run_until_complete(self.__publish(subject, data))
View event_bus_root.py
import json
import os
import random
from nats.aio.client import Client as NATS
from stan.aio.client import Client as STAN
import asyncio
class EventBus:
View event_publisher.py
import traceback
from asgiref.sync import sync_to_async
from ms_foobar_app.constants import EventSubjects, QueueGroupName
from ms_foobar_app.events.event_bus_root import EventBus
from ms_foobar_app.models import User
from ms_foobar_app.serializers import UserSerializer
from ms_foobar_app.utils.utilities import snake_case_dict_to_camel
@codephillip
codephillip / middlewares.py
Created Nov 30, 2021
Custom CORS and CSRF middleware bypasser(used in microservices)
View middlewares.py
from django.utils.deprecation import MiddlewareMixin
# NOTE: This is not best practise, however, api requests from some browser would fail continuous so explains the use
# of this. Enhance this CSRF solution if necessary
class DisableCsrfCheck(MiddlewareMixin):
def process_request(self, req):
attr = '_dont_enforce_csrf_checks'
if not getattr(req, attr, False):
setattr(req, attr, True)
View Q6_v1_find_the_bug.java
package com.codephillip.hello;
public class Main {
public static void main(String[] args) {
divider();
}
}