Skip to content

Instantly share code, notes, and snippets.

View elmoiv's full-sized avatar
:shipit:
Busy...

Khaled ElMorshedy elmoiv

:shipit:
Busy...
View GitHub Profile
@elmoiv
elmoiv / count_repeated_numbers_in_any_file.py
Last active March 12, 2020 09:17
Count repeated numbers in any file [plain-text and binary]
import re, mimetypes
def extract(file_name):
get_type = mimetypes.guess_type(file_name)[0]
type = 'rb' if get_type != 'text/plain' else 'r'
unicode = 'utf-8' if type == 'r' else None
raw_data = str(open(file_name, type, encoding=unicode).read())
return re.findall(r'\d+\.*\d*', raw_data)
def counter(extracted_data):
@elmoiv
elmoiv / is_int.py
Created December 7, 2019 11:38
[Python Tricks #1] Check if number is integer.
is_int = lambda n: not n % 1
@elmoiv
elmoiv / facebook_user_id.py
Last active November 5, 2020 09:55
Getting ID of any facebook user without scraping.
import re, urllib.request
query = input()
rgx = re.split(r'((http|https):\/\/)?(www\.)?(facebook|fb)\.com\/([.a-z0-9]+)', query.lower())
name = rgx[0] if len(rgx) == 1 else rgx[5]
redirected = urllib.request.urlopen(f'https://m.me/{name}').geturl().split('%2F')