Skip to content

Instantly share code, notes, and snippets.

View BuildWithLal's full-sized avatar
🏠
Working from home

Lal Zada BuildWithLal

🏠
Working from home
  • Upwork
  • Lahore, Pakistan
  • 12:38 (UTC +05:00)
View GitHub Profile
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}];
@BuildWithLal
BuildWithLal / pandas_date_range.py
Last active February 1, 2018 16:52
Get list of dates from a given date to today using Pandas..
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'))
@BuildWithLal
BuildWithLal / python-singleton.py
Last active September 28, 2020 20:10
Create a singleton class using Python 3
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()
@BuildWithLal
BuildWithLal / python-concurrency.py
Last active February 21, 2018 14:01
Choose concurrency from different forms of concurrency in Python
def choose_concurrency():
if io_bound:
if io_very_slow:
print("Use Asyncio")
else:
print("Use Threads")
else:
print("Multi Processing")
choose_concurrency()
field names
<fields>
<first_name>
<type>string</type>
<max_length>50</max_length>
</first_name>
<last_name>
<type>string</type>
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)
class SessionHistoryCreateSerializer(DocumentSerializer):
class Meta:
model = SessionHistory
fields = '__all__'
# check date...
def validate(self, data):
data = super().validate(data)
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
user/models.py
from mongoengine import EmbeddedDocument, Document, CASCADE
from mongoengine import fields
import binascii
import os
from django.utils import timezone
{
"id": 1,
"name": "Meri Company",
"street": "",
"city": "",
"state": "",
"country": "",
"lat": "0.00000000000000000000",
"lng": "0.00000000000000000000",
"site_url": "",