Skip to content

Instantly share code, notes, and snippets.

@vinayakg
vinayakg / apache.conf
Created October 19, 2020 09:01
Caching fonts and images, css, js, svg
#RewriteEngine On
# Redirect to https
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# End https redirect
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php/$1 [L]
#SetEnv CI_ENV production
#Require all granted
@vinayakg
vinayakg / find-address-live-traffic.sh
Last active March 24, 2024 14:23
find ip address and their location from live traffic on machine
lsof -iTCP -P | grep Spark | awk '{print $9}' | cut -d '>' -f2 | cut -d ':' -f1 | uniq | xargs -I% curl ipinfo.io/%/org
@vinayakg
vinayakg / download-file-with-retry.sh
Created February 8, 2021 19:49
download-file-with-retry.sh
while read line; do
# wait for the file to download infinitely, since we are getting 303 HTTP status
while [ ! -f "NDCDoc-$line.pdf" ]
do
# curl request fetched from browser
curl -sS -O -J "https://abc.com/admin/l/down/$line" \
-H 'authority: abc.com' \
-H 'upgrade-insecure-requests: 1' \
@vinayakg
vinayakg / redirect-ipaccess-to-website-apache.conf
Last active June 6, 2021 03:07
redirect-ipaddress-to-domain-apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
</IfModule>
@vinayakg
vinayakg / find-all-tables-columns-time-timestamp-datetime.sql
Created August 9, 2021 07:28
To find all tables in your database that have datetime, time, or timestamp column
SELECT DISTINCT CONCAT('ALTER TABLE `',
REPLACE(is_tables.TABLE_SCHEMA, '`', '``'), '`.`',
REPLACE(is_tables.TABLE_NAME, '`', '``'), '` FORCE;')
FROM information_schema.TABLES is_tables
INNER JOIN information_schema.COLUMNS col ON col.TABLE_SCHEMA = is_tables.TABLE_SCHEMA
AND col.TABLE_NAME = is_tables.TABLE_NAME
LEFT OUTER JOIN information_schema.INNODB_SYS_TABLES systables ON
SUBSTRING_INDEX(systables.NAME, '#', 1) = CONCAT(is_tables.TABLE_SCHEMA,'/',is_tables.TABLE_NAME)
LEFT OUTER JOIN information_schema.INNODB_SYS_COLUMNS syscolumns ON
syscolumns.TABLE_ID = systables.TABLE_ID AND syscolumns.NAME = col.COLUMN_NAME
@vinayakg
vinayakg / linux-commands.sh
Last active March 24, 2024 14:24
Handy Linux commands that have been using for years
Find files size excluding folders in the current directory
`find . -name "*.*" -type f -depth 1 -exec du -ch {} +`
Batch file to delete files older than N days
`forfiles -p "C:\what\ever" -s -m *.* -d <number of days> -c "cmd /c del @path"`
Running a batch program in one line
@vinayakg
vinayakg / downloadfiles.sh
Last active August 20, 2021 20:50
Download files EDU
if [ "$#" -ne 1 ]; then
echo "Enter the full path of the file containing loanids"
exit
fi
inputfilename=$1
while read line; do
# wait for the file to download infinitely, since we are getting 303 HTTP status
while [ ! -f "NDCDoc-$line.pdf" ]
do
@vinayakg
vinayakg / NLP_Recommender_Modeling_task1.md
Last active December 9, 2021 16:32
NLP & Recommender Modeling

You need to build a simple recommender - Top-K choices (say, 10 recommendations for each customer)

You may use content, collaborative filtering models on any category of your choice from Amazon dataset

You may use the public dataset available here and also visualize the output recommendations using streamlit.io - An opensource WebApp.

@vinayakg
vinayakg / computer_vision_task2.md
Last active December 9, 2021 16:36
Computer Vision Task

Identify Prominent Color

Identify the prominent colour of the image (logo) and set it as the background.

  • Image Dimension Ratio to be minimum at (350*200)

  • Handle both JPEG & PNG format

The program should handle edge cases such as:

  • If only one color is present in the image, set the background to the opposite color (dark/light)
@vinayakg
vinayakg / Build_with_Terraform.md
Last active May 31, 2022 13:55
Build with Terraform

Create a terraform template which should create the below:

  • Create a Vnet / VPC named "xyz-vnet" in any region.
  • Create 2 subnets -named "xyz-app-subnet" & "xyz-db-subnet" within "xyz-vnet", each having 16 Ip addresses.
  • Create 2 network security groups named "xyz-app-subnet-nsg" & "xyz-db-subnet-nsg", where "xyz-db-subnet-nsg" nsg should allow connections only from "xyz-app-subnet-nsg" (Only required database ports).
  • Create 2 linux based VMs on each subnet.
  • VMs on "xyz-app-subnet" should have Ubuntu 18.04 as OS with all updated packages & client of the database (which you create on xyz-db-subnet) & have nginx/apache up and running (dockerized).
  • VMs on "xyz-db-subnet" should have Ubuntu 18.04 as OS with all updated packages & have a database up and running (should be dockerized with volume properly mounted. Preferably can have high availabilty for data storage. Can be any database, preferably postgres)
  • Create a load balancer and map nginx/apache running on the VMS hosted on xyz-app-subnet.