Skip to content

Instantly share code, notes, and snippets.

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();
}
}
def download_invoice(self, request, pk=None):
"""
Download Invoice Endpoint
---
omit_serializer: True
omit_parameters:
- query
"""
current_url = '{}?{}'.format(
reverse(request.resolver_match.url_name, kwargs={'pk': pk}),
QUESTION 5
CREDIT: http://www.cs.unc.edu/~stotts/COMP204/refactor/chap1.html
TIME: 15 minutes
Refactor the following code
public class DomainObject {
public DomainObject (String name) {
_name = name;
QUESTION 4
TIME: 5 minutes
What will be the output of this code?
var x = 21;
var girl = function () {
console.log(x);
var x = 20;
QUESTION 3
TIME: 5 minutes
Consider the following code. What will the output be, and why?
(function () {
try {
throw new Error();
} catch (x) {
var x = 1, y = 2;
QUESTION 2
TIME: 5 minutes
What is the output of this line of code?
console.log((function x(n){return ((n > 1) ? n * x(n-2) : n)})(10));
@codephillip
codephillip / Q1_number_palindrome
Last active July 15, 2021 13:32
number_palindrome
QUESTION 1
TIME: 10 minutes
Number is a palindrome if it is equal to the number with digits in reversed order. For example, 5, 44, 171, 4884 are palindromes and 43, 194, 4773 are not palindromes.
Write a method palindrome_chain_length which takes a positive number and returns the number of special steps needed to obtain a palindrome. The special step is: "reverse the digits, and add to the original number". If the resulting number is not a palindrome, repeat the procedure with the sum until the resulting number is a palindrome.
If the input number is already a palindrome, the number of steps is 0.
Input will always be a positive integer.
For example, start with 87: