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 / .gitignore
Created February 28, 2019 06:28
Gitignore file common uses for Python
# It ignore whole certain directory
env/
instance/*
# It ignore all files in certain directory but not given directory
!instance/.gitkeep
!migrations/__init__.py
# It ignore all files which has certain extension
*.pyc
@vikas-git
vikas-git / decorator.py
Created February 28, 2019 06:37
Django :: Create user define decorator
from django.http import HttpResponseRedirect
def authors_only(function):
def wrap(request, *args, **kwargs):
profile = request.user.get_profile()
if profile.usertype == 'Author':
return function(request, *args, **kwargs)
else:
return HttpResponseRedirect('/')
@vikas-git
vikas-git / jquery.validate.addtional.js
Created February 28, 2019 07:19
Jquery Validate :: Additional validation for different type of value check.
$.validator.addMethod("emailFormat",
function (value, element) {
// return !/[0-9]*/.test(value);
return this.optional(element) || /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/.test(value);
},
//'Please enter a valid email address.'
"Please enter a valid email"
);
$.validator.addMethod("blankSpace",
function (value, element) {
@vikas-git
vikas-git / git_command.txt
Last active December 8, 2019 13:17
Git basic commands
# Git clone from specific branch
git clone -b my-branch git@github.com:user/myproject.git
# Before pushed code need to run given command..
git stash clear; git stash; git pull; git stash apply;
git commit files
git add .
git commit -m "udpate"
git push
@vikas-git
vikas-git / python_interview.txt
Last active September 27, 2023 14:34
My Interview experience on Python
======= Interviews ==========
# Duration July - August 2021
## Django:
* Flow of Django
* Django Middlewares
* Django request/response cycle
* API security(auth based token and others)
* Avoid deadloak in django ( F() )
@vikas-git
vikas-git / dataframe_func_query.txt
Last active August 18, 2019 17:53
Important Query for Pandas Dataframe
# search with and/or condition
df4 = df3.query('(From=="AHH" & To=="BBH") | (From=="BBH" & To=="AHH")')
OR
data.loc[(data["Gender"]=="Female") & (data["Education"]=="Not Graduate") & (data["Loan_Status"]=="Y"), ["Gender","Education","Loan_Status"]]
# Rows to columns
df = df.stack().reset_index().rename(columns={'level_0':'From','level_1':'To', 0:'Hours'})
# Join two df like sql join
df1 = df1.merge(record_df, on='location_code', how='outer', suffixes=('_x', '_y'))
@vikas-git
vikas-git / csv_to_mongo.py
Created July 16, 2019 07:28
Script for import data from csv to mongo DB using Pandas dataframe
import os
import json
import pandas as pd
import pymongo
def import_content(filepath):
mng_client = pymongo.MongoClient('localhost', 27017)
mng_db = mng_client['route_planning']
collection_name = 'lat_long'
@vikas-git
vikas-git / mongo_query.js
Created July 18, 2019 07:51
Some common and important commands for MONGODB
For Dump and Restore :
mongodump --db=<old_db_name> --collection=<collection_name> --out=data/
mongorestore --db=<new_db_name> --collection=<collection_name> data/<db_name>/<collection_name>.bson
Loop on mongodb query:
db.users.find().forEach( function(myDoc) { print( "user: " + myDoc.name ); } );
@vikas-git
vikas-git / get_lat_long_script.py
Created July 22, 2019 04:55
script for get Lat-Long from Address string
"""
Python script for batch geocoding of addresses using the Google Geocoding API.
This script allows for massive lists of addresses to be geocoded for free by pausing when the
geocoder hits the free rate limit set by Google (2500 per day). If you have an API key for paid
geocoding from Google, set it in the API key section.
Addresses for geocoding can be specified in a list of strings "addresses". In this script, addresses
come from a csv file with a column "Address". Adjust the code to your own requirements as needed.
After every 500 successul geocode operations, a temporary file with results is recorded in case of
script failure / loss of connection later.
Addresses and data are held in memory, so this script may need to be adjusted to process files line
@vikas-git
vikas-git / geovis.py
Created August 13, 2019 10:30
Implement folium library
# -*- coding: utf-8 -*-
"""
Created on Tuesday 23-July-2019
@author: Vikas shrivastava
For more info go to official documentation of folium https://python-visualization.github.io/folium/modules.html
"""