Skip to content

Instantly share code, notes, and snippets.

View ahmedshahriar's full-sized avatar
🏠
Working from home

Ahmed Shahriar Sakib ahmedshahriar

🏠
Working from home
View GitHub Profile
@ahmedshahriar
ahmedshahriar / date_time_parse_from_few_social_media_post_cases.py
Last active November 28, 2020 14:59
Code snippet to calculate exact date-time from a text using date-time denoted numbers(1,2,3,4...) and words('week', 'a week', 'day', 'hour') . Applied for some social media posts texts which denotes time such as "1 hour ago" , '3 weeks ago' etc
from datetime import datetime, timedelta
import re
'''
examples cases:
4 DAYS AGO
1 HOUR AGO
Listed 4 days ago in East Wenatchee, WA
Listed a week ago in East Wenatchee, WA
@ahmedshahriar
ahmedshahriar / .ignore
Created November 27, 2020 16:43
gitignore for python, django , pycharm , env files
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.DS_Store
.idea
.env
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
"""
code snippet for selenium with fake user agent
selenium : https://selenium-python.readthedocs.io/
fake user agent : https://github.com/hellysmile/fake-useragent
https://github.com/ahmedshahriar
"""
from time import sleep
from selenium import webdriver
"""
simplify price with currency sign to number
"""
# sample
txt = "$5,200"
txt[1:].replace(',','')
# output
# 5200
"""
code snippet to add/subtract datetime object
https://github.com/ahmedshahriar
"""
from datetime import datetime, timedelta
# addition
d = datetime.now() + timedelta(days=1, weeks=1, hours=19,seconds=1,milliseconds=1,microseconds=1)
"""
@ github.com/ahmedshahriar
This code will remove remove non-English words from text
"""
import nltk
# download nltk english corpus
nltk.download('wordnet')
wordnet = set(nltk.corpus.wordnet.words())
import requests
import re
headers = {
'authority': 'www.amazon.com',
'pragma': 'no-cache',
'cache-control': 'no-cache',
'dnt': '1',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36',
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
start_urls = [
'http://quotes.toscrape.com/page/1/',
]
def parse(self, response):
@ahmedshahriar
ahmedshahriar / tpr_fpr_binary_class.py
Created June 8, 2020 17:52
This sample code works on binary classification to generatre True Positive Rate and False Positive Rate (TPR, FPR) by class.
"""This sample code works on binary classification to generatre True Positive Rate and False Positive Rate (TPR, FPR) by class.
Yes denotes positive class and No denotes negative class.
Default value 0 and 1.
Created by Ahmed Shahriar Sakib @ahmedshahriar on 06.08.2020 """
yes_tp = 0
yes_fp = 0
no_tp = 0
no_fp = 0
yes_instances =0
int searchBinary(int arrayList[],int findNum,int first , int last ){
while(first<=last){
int middle =( last+first)/2;
if(arrayList[middle]==findNum)
return middle;