Skip to content

Instantly share code, notes, and snippets.

@6aditya8
6aditya8 / adding_default_values_for_date_fields.sql
Last active April 1, 2020 14:05
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
@6aditya8
6aditya8 / proxy_user_agents.py
Created August 27, 2019 15:55
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):
"""
@6aditya8
6aditya8 / proxy_ip.py
Created August 27, 2019 14:41
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
"""
@6aditya8
6aditya8 / add_ssh_key.md
Last active April 2, 2019 09:51
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

@6aditya8
6aditya8 / nginx.conf
Last active July 7, 2022 08:00
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;
@6aditya8
6aditya8 / hosting
Created August 7, 2018 14:02
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
@6aditya8
6aditya8 / singleton_class_example.py
Last active August 7, 2018 13:40
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!")