Skip to content

Instantly share code, notes, and snippets.

View vikas-git's full-sized avatar

Vikas Shrivastava vikas-git

  • Gurgaon
View GitHub Profile
@vikas-git
vikas-git / python_imp_topics.md
Last active March 2, 2020 18:09
This gist is used only for find some internal functionality questions in python lang.
@vikas-git
vikas-git / drf_error_handler.js
Last active January 23, 2020 09:18
JS/Jquery Error parser for Django-rest-framework errors structure.
/*
* Handle Django serializers errors and return error in html (ul/li) format.
*
* Error structure examples
* // The most simple case
* { detail: "Authentication is required" }
*
* // Simple form validation error
* { title: ["This field is required."], "description": ["This field is required."]}
*
@vikas-git
vikas-git / AbstructModel.py
Created December 17, 2019 06:33
Use some common fields in every django modal
from django.db import models
class AbstractDateTime(models.Model):
'''
Abstract model for created_on and updated_on field in models
'''
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
@vikas-git
vikas-git / logger.py
Created December 12, 2019 10:59
Use of logger in django project
# setting.py file
'''
JS logger configuration used in application
'''
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
@vikas-git
vikas-git / exception.py
Created December 11, 2019 11:55
How to make custom Exception class
'''
Ref blog
- https://www.programiz.com/python-programming/user-defined-exception
- https://stackoverflow.com/questions/1319615/proper-way-to-declare-custom-exceptions-in-modern-python
'''
# Basic use
class CustomError(Exception):
pass
@vikas-git
vikas-git / aws_cli.txt
Created December 6, 2019 05:33
Basic setup and commands of AWS_CLI in python virtualenv
pip install boto3
python manage.py runserver
pip install awscli
aws --version
aws configure # set configuration of user
aws s3 ls # get listing of all buckets
aws s3 ls s3://imageprocess-python/ # access certain bucket
@vikas-git
vikas-git / distance_and_folium.py
Created December 5, 2019 06:49
find distance between two points using google map api and plot it on folium.
# check attachment files
# find_distance.py
import os
from datetime import datetime
import googlemaps
from django.conf import settings
from packages.common_func import get_or_none, convert_float
from network.models import Distance, LatLong
@vikas-git
vikas-git / Geo_dist.py
Created November 28, 2019 10:24
Basic script for find distance between two points using googlemaps api
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 8 17:19:13 2019
@author: 63315
"""
import googlemaps
from datetime import datetime
@vikas-git
vikas-git / util_func.py
Last active December 5, 2019 06:46
Some important functions
import os
from datetime import datetime
from django.conf import settings
from django.db import connection
from django.core.files.storage import FileSystemStorage
def get_dict_wise_data(columns,cursor):
results = []
for row in cursor.fetchall():
@vikas-git
vikas-git / boto_script.py
Last active November 25, 2019 05:22
Basic operation to push object on AWS S3
'''
For more information visit official documents
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-examples.html
'''
import boto3
from botocore.errorfactory import ClientError
from boto3.s3.transfer import S3Transfer