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
function sortByAge(a,b) { | |
if (a.age < b.age) | |
return -1; | |
if (a.age > b.age) | |
return 1; | |
return 0; | |
} | |
students = [{name: 'Axen', age: 12}, {name: 'Mike', age:10}, {name: 'John', age: 11}]; |
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
import pandas as pd | |
from datetime import date | |
today = pd.Timestamp("today").strftime("%Y-%m-%d") | |
date_ranges = pd.date_range(start='2016-01-01', end=today) | |
for date in date_ranges: | |
print(date.strftime('%Y-%m-%d')) |
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 Singleton(object): | |
def __new__(cls): | |
if not hasattr(cls, 'instance') or not cls.instance: | |
cls.instance = super().__new__(cls) | |
return cls.instance | |
obj1 = Singleton() | |
obj2 = Singleton() |
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
def choose_concurrency(): | |
if io_bound: | |
if io_very_slow: | |
print("Use Asyncio") | |
else: | |
print("Use Threads") | |
else: | |
print("Multi Processing") | |
choose_concurrency() |
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
field names | |
<fields> | |
<first_name> | |
<type>string</type> | |
<max_length>50</max_length> | |
</first_name> | |
<last_name> | |
<type>string</type> |
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 SocialLoginSerializer(UserDeviceMixin, serializers.Serializer): | |
PROVIDER_CHOICES = Provider.objects.values_list('name') | |
# first_name = serializers.CharField(required=False, allow_blank=True) | |
# last_name = serializers.CharField(required=False, allow_blank=True) | |
# email = serializers.EmailField() | |
# mac_address = serializers.CharField() | |
name = serializers.CharField(required=False, allow_blank=True) |
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 SessionHistoryCreateSerializer(DocumentSerializer): | |
class Meta: | |
model = SessionHistory | |
fields = '__all__' | |
# check date... | |
def validate(self, data): | |
data = super().validate(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
views.py | |
from rest_framework_mongoengine import generics | |
from rest_framework.response import Response | |
from .serializers import LoginSerializer | |
from configuration.models import User | |
#from captive_portal.models import SessionHistory, Voucher | |
from .models import SessionHistory | |
from rest_framework import serializers |
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
user/models.py | |
from mongoengine import EmbeddedDocument, Document, CASCADE | |
from mongoengine import fields | |
import binascii | |
import os | |
from django.utils import timezone | |
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
{ | |
"id": 1, | |
"name": "Meri Company", | |
"street": "", | |
"city": "", | |
"state": "", | |
"country": "", | |
"lat": "0.00000000000000000000", | |
"lng": "0.00000000000000000000", | |
"site_url": "", |
OlderNewer