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 / dataframe_queries.txt
Last active September 9, 2019 05:05
In this gist trying to explain how to use sql queries on dataframes.
Source Blog: https://medium.com/jbennetcodes/how-to-rewrite-your-sql-queries-in-pandas-and-more-149d341fc53e?source=search_post---------0
-> Sql queries vs pandas queries
* select Query
-> select * from airports;
-> airports.head()
* select query with limit
-> select * from airports limit 3
@vikas-git
vikas-git / query.txt
Created September 10, 2019 06:01
Some tricks of pandas for working more fast
# source: https://towardsdatascience.com/10-python-pandas-tricks-that-make-your-work-more-efficient-2e8e483808ba
pd.read_csv('file_name.csv', nrows = 5, usecols=['c1', 'c2'], dtype = {‘c1’: str, ‘c2’: int, …})
argument
* nrows = 5 (it will select only 5 rows from dataframe)
* usecols (select certain columns on df creation)
* dtype (specify col data type)
*
@vikas-git
vikas-git / only_number.js
Created September 18, 2019 10:47
js code for allow only number in textbox...
$(document).on('keypress', '.only-numbers', function(e){
var keycode = (e.which) ? e.which : e.keyCode;
if (!(keycode==8 || keycode == 46)&&(keycode < 48 || keycode > 57)){
return false;
}
});
@vikas-git
vikas-git / generic_views.txt
Last active October 9, 2019 09:00
Different types of Generic views
LIST VIEW:
from django.views.generic import ListView
** Simple example
class UsersListView(ListView):
model = User
** You can add attributes to change the default behaviour.
class UsersListView(ListView):
model = User
@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
@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 / 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 / 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 / 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 / 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