Skip to content

Instantly share code, notes, and snippets.

View aditya-gupta-sde's full-sized avatar

Aditya Gupta aditya-gupta-sde

  • Spotdraft
  • India
View GitHub Profile
@aditya-gupta-sde
aditya-gupta-sde / adding_default_values_for_date_fields.sql
Created January 27, 2021 06:18
Adding created_at and modified_at columns in MySQL5.5 and below as DATETIME fields. These versions didn't allow default for any date/datetime column to be the value of a function such as NOW() or CURRENT_DATE. This can be alternatively achieved using triggers.
-- Add the columns created_at & modified_at to your required table.
ALTER TABLE
table_name
ADD
COLUMN created_at DATETIME NULL
ADD
COLUMN modified_at DATETIME NULL;
-- Initialize the data with the current timestamp.
UPDATE
@aditya-gupta-sde
aditya-gupta-sde / Django App Hosting
Created January 27, 2021 06:20
Hosting Django Application in AWS or GCloud using Nginx and uwsgi[emperor mode]
(Reference:https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04)
Create an instance, make sure you have allowed HTTP and HTTPS ports.
sudo apt-get update
sudo apt-get install python-pip python-dev
sudo -H pip install virtualenv virtualenvwrapper
sudo nano .bashrc
Add the following:
export WORKON_HOME=/home/ubuntu/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
@aditya-gupta-sde
aditya-gupta-sde / add_ssh_key.md
Created January 27, 2021 06:22
Generating a new SSH key and adding it to the ssh-agent & to your github account

Checking for existing SSH keys

Before you generate an SSH key, you can check to see if you have any existing SSH keys.
1. Open Terminal
2. Enter ls -al ~/.ssh to see if existing SSH keys are present. This lists the files in your .ssh directory, if they exist. Check the directory listing to see if you already have a public SSH key.

If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key.

If you receive an error that ~/.ssh doesnt exist, dont worry! We will create it when we generate a new SSH key.

Generating a new SSH key

After you've checked for existing SSH keys, you can generate a new SSH key to use for authentication
1. Open Terminal

@aditya-gupta-sde
aditya-gupta-sde / nginx.conf
Last active January 27, 2021 06:28
Nginx SSL/TLS configuration for getting "A+" in Qualys SSL Labs test
# Configuration options are limited to SSL/TLS
# Enable SSL session caching for improving performance by avoiding the costly session negotiation process where possible
# SSL Labs doesn't assume that SNI is available to the client, so it only tests the default virtual server
# setting this globally to make it work across all the nginx virtual servers (including the default virtual server)
ssl_session_cache shared:ssl_session_cache:10m;
ssl_session_timeout 10m;
server {
listen 443 ssl;
@aditya-gupta-sde
aditya-gupta-sde / proxy_ip.py
Created January 27, 2021 06:25
Get a list of proxy IP Addresses (useful for IP Rotation during scraping)
from lxml.html import fromstring
import random
import requests
def get_proxies():
"""
Gather a list of some active proxies from https://free-proxy-list.net/
:return: List of IP Addresses
"""
@aditya-gupta-sde
aditya-gupta-sde / proxy_user_agents.py
Created January 27, 2021 06:25
Get a list of proxy User Agents (useful for User Agent Rotation during scraping)
from bs4 import BeautifulSoup
import random
import requests
USER_AGENT_SCRAPER_BASE_URL = 'http://www.useragentstring.com/pages/useragentstring.php?name='
POPULAR_BROWSERS = ['Chrome', 'Firefox', 'Mozilla', 'Safari', 'Opera', 'Opera Mini', 'Edge', 'Internet Explorer']
def get_user_agent_strings_for_this_browser(browser):
"""
@aditya-gupta-sde
aditya-gupta-sde / singleton_class.py
Created January 27, 2021 06:27
An example Code for Singleton Class
class Singleton:
objects_created = 0
def __new__(cls,*args,**kwargs):
if cls.objects_created >= 1:
raise ValueError("This is a Singleton Class, can't create more objects!")
@aditya-gupta-sde
aditya-gupta-sde / github-run-tests-button.user.js
Created January 3, 2025 05:08
This Tampermonkey script adds a custom "Run Tests" button to GitHub Pull Request (PR) pages. When clicked, it automatically adds a comment saying "run tests" to the PR. This is especially useful for teams using comment-based triggers for CI/CD workflows or testing pipelines.
// ==UserScript==
// @name Add "Run Tests" Button to GitHub PRs
// @namespace https://github.com/
// @version 1.0
// @description Adds a button to GitHub PRs to comment "run tests"
// @author Your Name
// @match https://github.com/*/pull/*
// @grant none
// @downloadURL https://gist.githubusercontent.com/<your-username>/<gist-id>/raw/run-tests-button.user.js
// @updateURL https://gist.githubusercontent.com/<your-username>/<gist-id>/raw/run-tests-button.user.js