Skip to content

Instantly share code, notes, and snippets.

# Installing python and other essentials
https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-programming-environment-on-an-ubuntu-18-04-server
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install python3.7 libpython3.7-dev python3-all-dev
@neerajgupta2407
neerajgupta2407 / PaytmChecksum.py
Created June 7, 2020 09:32
Paytm python sample code
import base64
import string
import random
import hashlib
import sys
from Crypto.Cipher import AES
iv = '@@@@&&&&####$$$$'
@neerajgupta2407
neerajgupta2407 / export_and_upload_to_s3.sh
Last active January 15, 2021 19:03
Export POstgres db bbackup and upload to S3.
#!/bin/bash
# Written 2018-11-15 by 4410287
# This script will create a backup file of a postgres database and compress it. It is capable of access a local or remote server to pull the backup. After creating a new backup, it will delete backups that are older than 15 days, with the exception of backups created the first of every month. It is recommended to create a seperate database user specifically for backup purposes, and to set the permissions of this script to prevent access to the login details. Backup scripts for different databases should be run in seperate folders or they will overwrite each other.
HOSTNAME=
USERNAME=
PASSWORD=
DATABASE=
FILENAME=$(date +%Y-%m-%d).backup.sql
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04
Steps: 1)
sudo apt-get update
sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
2)
sudo vim /etc/apache2/sites-available/000-default.conf
# Installing ElasticSearch ANd Kibana
# Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update
sudo apt-get install elasticsearch kibana
@neerajgupta2407
neerajgupta2407 / Steps.
Last active May 16, 2020 13:04
Script used to add host machine ip address to Aws security group.
1. Configure Aws with command `aws configure --profile aws_user`
2. Run script to add Ip to security group. 'sh aws_add_ip_to_security_group.sh add'
@neerajgupta2407
neerajgupta2407 / logger_function.py
Created May 12, 2020 07:31
A generic logger decorstor function which is used to log the function input and output at custom directory. @logs_func('dummy') will saves the results into /tmp/logs/dummy/date.txt
"""
A generic logger decorstor function which is used to log the function input and output at custom directory.
@logs_func('dummy') will saves the results into /tmp/logs/dummy/date.txt
"""
import os
from datetime import datetime
BASE_DIR="/tmp"
def get_dir(path):
@neerajgupta2407
neerajgupta2407 / retry_request.py
Created May 12, 2020 07:25
Decorator used to retry the failed request with default retry limit to 3.
"""
Decorator used to retry the failed request with default retry limit to 3.
"""
import time
from functools import wraps
default_timeout = 1 # timeout of 1 sec.
def retry_request(retry_limit=3):
@neerajgupta2407
neerajgupta2407 / Mock_requests_and_functions.py
Last active May 12, 2020 07:19
A custoom decorastor functions which can be used to mock the reqpose for particular function based on a flag called EnableMock. If EnableMock set to True, then mock_response will not execute the underlying function and returns the mock response provided in decorator.
"""
A custoom decorastor functions which can be used to mock the reqpose for particular
function based on a flag called EnableMock.
If EnableMock set to True, then mock_response will not execute the underlying function and returns the mock response provided in decorator.
"""
from functools import wraps
EnableMock = True
DummyRespone = 1000 # could be anything Int, Str, Float, Dict, list...
from datetime import timedelta
import jwt
import requests
from social_core.utils import handle_http_errors
from datetime import datetime, timezone
class AppleOAuth2():
"""apple authentication backend"""