Skip to content

Instantly share code, notes, and snippets.

View md-shadhin's full-sized avatar
🏠
Working from home

Shadhin md-shadhin

🏠
Working from home
View GitHub Profile
@md-shadhin
md-shadhin / Dockerfile
Last active December 8, 2018 05:15
Docker with nginx and php
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y nginx php7.0-fpm supervisor && \
rm -rf /var/lib/apt/lists/*
ENV nginx_vhost /etc/nginx/sites-available/default
ENV php_conf /etc/php/7.0/fpm/php.ini
ENV nginx_conf /etc/nginx/nginx.conf
@md-shadhin
md-shadhin / problem-3.ssh
Created December 6, 2018 18:49
Add a new user on Linux
#1 Add user without password non-interactively
adduser --disabled-password --gecos "" username_new_user
#2 Grant root access to the user
usermod -aG sudo username_new_user
#3 Create a folder named .ssh
cd /home/username_new_user
mkdir ~/.ssh
@md-shadhin
md-shadhin / problem-2.py
Created December 6, 2018 17:57
Parse the logs
import itertools as it
from operator import itemgetter
logs = []
with open('mock.log') as all_logs:
for line in all_logs:
line = line.split(' ', 1)[1].strip()
error = line[line.find("[")+1:line.find("]")]
if 'Consumer' in line:
@md-shadhin
md-shadhin / problem-1.py
Created December 6, 2018 14:43
Find geolocation information about an IP
import urllib.request, json
ip = input('Enter an IP:')
if ip.strip():
url = "http://ip-api.com/json/"+ip
response = urllib.request.urlopen(url)
data = json.loads(response.read())
if data['status']=='success':
print(data['city']+', '+data['regionName']+'('+data['country']+')')
@md-shadhin
md-shadhin / problem-4.sql
Created December 5, 2018 18:29
A query to output the names of those students whose best friends got offered a higher salary than them.
SELECT s.name
FROM
(SELECT CASE
WHEN p1.salary<p2.salary THEN p1.salary
ELSE NULL
END AS derived_column
FROM friends f
JOIN packages p1
ON p1.id=f.id
JOIN packages p2