Skip to content

Instantly share code, notes, and snippets.

View priyankvex's full-sized avatar
💭
Chilling 🍺

Priyank Verma priyankvex

💭
Chilling 🍺
View GitHub Profile
class TwiMLDialConferenceView(APIView):
"""
This view responds with a Conference Dial which puts the call in scope in the specified conference room
"""
def post(self, request, *args, **kwargs):
response = VoiceResponse()
dial = Dial()
end_conference_on_exit = request.GET.get("end_conference_on_exit", '').lower() == 'true'
dial.conference(request.GET["conference_room"], end_conference_on_exit=end_conference_on_exit)
response.append(dial)
class FirstLegDisconnectedView(APIView):
def post(self, request, *args, **kwargs):
call_sid = request.POST['CallSid']
conference_room = get_conference_room() # get the conference same as the customer's one
response = VoiceResponse()
dial = Dial()
dial.conference(request.GET["conference_room"], end_conference_on_exit=False)
def connect_second_agent_to_conference(cls, second_agent_number, conference_room):
response = TwilioClient.conferences(conference_room).participants.create(
from_=twilio_caller_id,
to=second_agent_number,
early_media=True
)
return response
@priyankvex
priyankvex / the_command_pattern.py
Created September 17, 2018 07:06
A smart home system implementation to showcase the usage of the command pattern.
class Home(object):
def __init__(self):
self._fan_state = "OFF"
self._fan_speed = 0
def turn_fan_on(self):
self._fan_state = "ON"
def turn_fan_off(self):
@priyankvex
priyankvex / generate_power_set.py
Created December 11, 2018 14:26
Scamming the Coding Interview: Problem #1: Generate Power Set
"""
Scamming the Coding Interview
"""
def generate_super_sets(power_set, elements, running_set, start_index):
if start_index > len(elements):
return
"""
Scamming the coding interview
"""
def is_valid(sudoku_grid, i, j):
is_board_valid = check_the_grid(sudoku_grid, i, j) and \
check_row(sudoku_grid, i, j) and \
check_col(sudoku_grid, i, j)
@priyankvex
priyankvex / url_shortner.py
Created December 14, 2018 15:10
Scamming the coding interview: Problem 003: URL shortner
"""
Scamming the coding interview
"""
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
memory_db = {}
def get_shorten_url(long_url, url_id):
@priyankvex
priyankvex / graph_coloring.py
Created December 15, 2018 14:09
Scamming the coding interview: Problem 004: Graph Coloring
"""
Scamming the coding interview
"""
def color_graph(graph_adjacency, number_of_vertices):
# First vertex gets the first color
vertex_to_color_map = {
0: 0
}
@priyankvex
priyankvex / file_syncing.py
Created December 17, 2018 17:35
Scamming the coding interview: Problem 005: File Syncing
"""
Scamming the coding interview
"""
from hashlib import md5
class MerkerFile(object):
def __init__(self):
@priyankvex
priyankvex / partition_sets_of_equal_sum.py
Created December 18, 2018 15:36
Scamming the coding interview: Problem 006: Partition into sets of equal sum
"""
Scamming the coding interview
"""
def generate_all_combinations(nums, combinations, start_index, running_set):
"""
Generates all the combinations a given list of numbers
"""
if start_index >= len(nums):
return