Skip to content

Instantly share code, notes, and snippets.

View bhuiyanmobasshir94's full-sized avatar
🎖️
Focused on achievement

Mobasshir Bhuiya bhuiyanmobasshir94

🎖️
Focused on achievement
View GitHub Profile
@bhuiyanmobasshir94
bhuiyanmobasshir94 / problem-1.py
Created December 9, 2018 13:26
Solutions to the problem of getting geo information against IP address
import requests
class Scraper:
''' Request information and Scrape data class '''
def __init__(self,ip=None):
self.address = 'http://ip-api.com/json/'
self.ip = ip
def get_geo_ip_info(self):
'''Collect geo ip info'''
@bhuiyanmobasshir94
bhuiyanmobasshir94 / problem-2.py
Created December 9, 2018 13:30
Log file parsing and sorting demonstration
import re
log_list = []
hosts = set()
hosts_status = set()
test_str = ''
filepath = 'problem-2.txt'
with open(filepath) as fp:
test_str = fp.read().strip()
@bhuiyanmobasshir94
bhuiyanmobasshir94 / problem-3.txt
Created December 9, 2018 13:32
Linux basic commands dist - Ubuntu 16.04
# Add User Non-interactively without password
1. sudo adduser --disabled-password --gecos "" username
# Grant root access to the user so s/he can execute sudo without a password.
1. sudo visudo
#After includedir /etc/sudoers.d put-.
2. username ALL=(ALL) NOPASSWD: ALL
# Create a folder named .ssh in the user’s home directory.
1. mkdir /home/username/.ssh
@bhuiyanmobasshir94
bhuiyanmobasshir94 / problem-4.txt
Last active December 11, 2018 17:50
Basic SQL Commands
BEGIN TRANSACTION;
CREATE TABLE Students (ID integer PRIMARY KEY, Name varchar(255));
CREATE TABLE Friends (ID integer PRIMARY KEY, Friend_ID integer);
CREATE TABLE Packages (ID integer PRIMARY KEY, Salary float(23,19));
INSERT INTO Students (ID,Name)
VALUES (1,'Ashley');
INSERT INTO Students (ID,Name)
VALUES (2,'Samantha');
@bhuiyanmobasshir94
bhuiyanmobasshir94 / index.html
Created December 9, 2018 13:42
Folium heatmap demonstration of Bashundhara Area
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script>L_PREFER_CANVAS=false; L_NO_TOUCH=false; L_DISABLE_3D=false;</script>
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.3.4/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.3.4/dist/leaflet.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>
@bhuiyanmobasshir94
bhuiyanmobasshir94 / populate_feature.py
Created December 11, 2018 17:53
A sample django population script
import os
import pandas as pd
import numpy as np
import random
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'categorized_affect_map.settings')
django.setup()
from classification.models import Category, Feature
from django.utils import timezone
@bhuiyanmobasshir94
bhuiyanmobasshir94 / population_script.py
Created December 11, 2018 23:28
A multi table and foreign key demonstrated django db population script
import os
import pandas as pd
import numpy as np
import random
import django
from django.utils import timezone
from populate_weather import get_location,get_weather
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'categorized_affect_map.settings')
django.setup()
@bhuiyanmobasshir94
bhuiyanmobasshir94 / populate_weather.py
Created December 11, 2018 23:30
Open Weather Map data and Open street map data demonstration
import requests
def get_weather(latitude_,longitude_):
# latitude = latitude_
# longitude = longitude_
# url = 'http://api.openweathermap.org/data/2.5/weather?lat={}&lon={}&appid=8f47bbfcc82517d109015de292ab80cd&units=metric'.format(latitude, longitude)
# res = requests.get(url)
# data = res.json()
response = dict(main="Haze",desc="haze",temp=18,pressure=1014,humidity=72,temp_min=18,temp_max=18,wind_speed=1.5,wind_degree=310,datetime=1544556600,clouds_all=20,sys_sunrise=1544488256,sys_sunset=1544526753)
return response
@bhuiyanmobasshir94
bhuiyanmobasshir94 / cull.py
Created December 13, 2018 19:00 — forked from jsundram/cull.py
Check if lat long is inside the bounds of the continental US (box model, not shape)
# http://en.wikipedia.org/wiki/Extreme_points_of_the_United_States#Westernmost
top = 49.3457868 # north lat
left = -124.7844079 # west long
right = -66.9513812 # east long
bottom = 24.7433195 # south lat
def cull(l):
c = []
for (lat, lng) in l:
if bottom <= lat <= top and left <= lng <= right:
@bhuiyanmobasshir94
bhuiyanmobasshir94 / gist:ce7061424a61f9fd3f582a8ec925787c
Created January 25, 2019 18:14
How to create a class using variable number of variables in python
There is a known method to emulate a container for variables, which support both methods of access: by a variable's name and a string key.
class Vars:
def __init__(self, **kw):
self.__dict__.update(kw)
def __getitem__(self, key):
return self.__dict__[key]
def __setitem__(self, key, val):