This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import shuffle as rand_shuffle | |
class Card: | |
... | |
class DeckOfCards(Card): | |
def __init__(self): | |
self.deck = { | |
"hearts":["A",2,3,4,5,6,7,8,9,10,"J","Q","K"], | |
"diamond":["A",2,3,4,5,6,7,8,9,10,"J","Q","K"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models.signals import post_save | |
from django.dispatch import receiver | |
from projects.models import Project | |
from access_management.utils import generate_groups_and_permission | |
from django.contrib.contenttypes.models import ContentType | |
from project_calendars.models import CalendarBriefMapping | |
from access_management.constants.project_constants import * | |
from django.contrib.auth.models import Group | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import Group, Permission | |
PERMISSION_GROUP_SUFFIX = '_permission_group' | |
current_module_variables = vars() | |
def generate_groups_and_permission(model_name, instance_name, content_type): | |
groups = current_module_variables[model_name + PERMISSION_GROUP_SUFFIX] | |
for k, v in groups.items(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Permissions name and code | |
archive_permission = ('_project_can_archive_permission', 'Can archive permission') | |
all_crud_permission = ('_project_can_do_all_crud_permission', 'Can do all crud') | |
view_only_permission = ('_project_can_view_only_permission', 'Can view only permission') | |
view_classified_information_permission = ('_project_can_view_classified_information', | |
'Can view classified information') | |
document_management_permission = ('_project_can_upload_or_delete_documents', | |
'Can upload or delete documents') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NAME="Socket_app" # Name of the application | |
DJANGODIR= Your project directory | |
SOCKFILE=Location of the socket file | |
USER=ubuntu # the user to run as | |
GROUP=ubuntu # the group to run as | |
NUM_WORKERS=1 # how many worker processes should Gunicorn spawn | |
DJANGO_SETTINGS_MODULE=Socket_app.settings # which settings file should Djangouse | |
DJANGO_WSGI_MODULE=Socket_app.wsgi # WSGI module name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from socketio_app.views import sio | |
import socketio | |
application = socketio.WSGIApp(sio, application) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async_mode = None | |
import os | |
from django.http import HttpResponse | |
import socketio | |
basedir = os.path.dirname(os.path.realpath(__file__)) | |
sio = socketio.Server(async_mode='eventlet')\ | |
@sio.on('connection-bind') | |
def connection_bind(sid, data): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new_schedule = {ts1, ts2, ..., ts24} # time-slots from new schedule | |
booked_schedule = {ts10, ts11, ..., ts18} # time-slots from booking schecdule | |
# Following line gives us all the timeslots which are in booking_schedule but not in new_schedule | |
conflicting_timeslots = booking_schedule - new_schedule | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
TimeSlot = namedtuple('TimeSlot', 'hour price') | |
t0 = TimeSlot(0, 20) | |
t1 = TimeSlot(1, 20) | |
# .... | |
t10 = TimeSlot(10, 50) | |
# .... | |
t18 = TimeSlot(18, 50) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeSlots: | |
def __init__(self, time, price): | |
self.time = time | |
self.price = price | |
def __str__(self): | |
return "time|price : "+str(self.time)+"|"+str(self.price) | |
def __repr__(self): | |
return self.__str__() |
NewerOlder