Skip to content

Instantly share code, notes, and snippets.

View checkaayush's full-sized avatar

Aayush Sarva checkaayush

View GitHub Profile
@checkaayush
checkaayush / nginxproxy.md
Created May 21, 2017 18:06 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@checkaayush
checkaayush / backup-mongodb-to-s3.sh
Created March 17, 2017 11:54 — forked from caraboides/backup-mongodb-to-s3.sh
Simple script to backup MongoDB to S3, without waste diskspace for temp files. And a way to restore from the latest snapshot.
#!/bin/sh
set -e
HOST=localhost
DB=test-entd-products
COL=asimproducts
S3PATH="s3://mongodb-backups-test1-entd/$DB/$COL/"
S3BACKUP=$S3PATH`date +"%Y%m%d_%H%M%S"`.dump.gz
S3LATEST=$S3PATH"latest".dump.gz
/usr/bin/aws s3 mb $S3PATH
@checkaayush
checkaayush / mongodb-s3-backup.sh
Created March 17, 2017 11:53 — forked from eladnava/mongodb-s3-backup.sh
Automatically backup a MongoDB database to S3 using mongodump, tar, and awscli (Ubuntu 14.04 LTS)
#!/bin/sh
# Make sure to:
# 1) Name this file `backup.sh` and place it in /home/ubuntu
# 2) Run sudo apt-get install awscli to install the AWSCLI
# 3) Run aws configure (enter s3-authorized IAM user and specify region)
# 4) Fill in DB host + name
# 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket)
# 6) Run chmod +x backup.sh
# 7) Test it out via ./backup.sh
@checkaayush
checkaayush / mysql_to_csv.py
Created February 20, 2017 14:10
Exports MySQL tables to .csv
"""Exports MySQL tables to CSV"""
import os
import pymysql
import pandas as pd
HOST = 'database_host_here'
DATABASE = 'database_name_here'
@checkaayush
checkaayush / push_stats.py
Created November 2, 2016 12:35 — forked from prakashpp/push_stats.py
Script to push github commit stats to slack
import os
from datetime import datetime
from slacker import Slacker
from dateutil.relativedelta import relativedelta
import requests
from requests.auth import HTTPBasicAuth
USERNAME = "prakashpp"
GITHUB_TOKEN = os.environ['GITHUB_ACCESS_TOKEN']
@checkaayush
checkaayush / suds_object_to_dict.py
Created October 10, 2016 20:55
Convert Suds object to Python dictionary
# Source: http://stackoverflow.com/questions/17581731/parsing-suds-soap-complex-data-type-into-python-dict
def basic_sobject_to_dict(obj):
"""Converts suds object to dict very quickly.
Does not serialize date time or normalize key case.
:param obj: suds object
:return: dict object
"""
if not hasattr(obj, '__keylist__'):
return obj
@checkaayush
checkaayush / gist:ec14e28aa08343e1e35f47d2c5b2ee3d
Last active October 4, 2016 07:55 — forked from jonleighton/base64ArrayBuffer.js
Encode an ArrayBuffer as a base64 string
// Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then
// use window.btoa' step. According to my tests, this appears to be a faster approach:
// http://jsperf.com/encoding-xhr-image-data/5
function base64ArrayBuffer(arrayBuffer) {
var base64 = ''
var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
var bytes = new Uint8Array(arrayBuffer)
var byteLength = bytes.byteLength
@checkaayush
checkaayush / FRIENDS.py
Created September 18, 2016 15:30
Script I used to rename all F.R.I.E.N.D.S. epsiodes by fetching names from Wikipedia
from bs4 import BeautifulSoup
import requests
import os
def get_episode_names(season):
episodes = {}
print "Making request..."
url = "https://en.wikipedia.org/wiki/Friends_(season_%s)#Episodes" % season
print url
@checkaayush
checkaayush / timer.py
Last active May 14, 2019 08:06
Python decorator function to calculate time taken by function to run
from functools import wraps
import time
def timeit(func):
"""Decorator to calculate time taken by a function to run"""
@wraps(func)
def timed(*args, **kw):
start = time.time()
result = func(*args, **kw)
@checkaayush
checkaayush / magicbricks_property_coords.py
Last active June 20, 2016 06:23
Get Address of properties on Magicbricks.com using Reverse-Geocoding
"""
Project: Apartment Hunt
Get Address of properties on Magicbricks.com using Reverse-Geocoding
This script asks for the target property URL, reverse geocodes it
and prints the address of the property
Need: Magicbricks map functionality doesn't let users get directions.
Even the exact property address is not visible on the webpage.