Skip to content

Instantly share code, notes, and snippets.

import csv
import random
import re
"""
Helps us find the number in between two brackets ie (33)
"""
def find_between(text, start, end):
@codephillip
codephillip / uat_extractor.py
Created August 27, 2022 15:39
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()
@codephillip
codephillip / classroom.py
Created August 25, 2022 06:27
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
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
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()
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))
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:
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 November 30, 2021 12:46
Custom CORS and CSRF middleware bypasser(used in microservices)
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)
package com.codephillip.hello;
public class Main {
public static void main(String[] args) {
divider();
}
}