Skip to content

Instantly share code, notes, and snippets.

View Anwarvic's full-sized avatar
🙄
Wasting Time!

✌️ Mohamed Anwar Anwarvic

🙄
Wasting Time!
View GitHub Profile
@Anwarvic
Anwarvic / anwar.om.json
Last active December 18, 2024 05:42
This is my theme for oh-my-posh on windows. It is a modified version of `mojada.omp.json`. To use it, add this line: "oh-my-posh init pwsh --config "C:\Users\mohamedanwar\anwar.om.json" | Invoke-Expression:" into your `Microsoft.PowerSehll_profile.ps1` file
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"newline": true,
"segments": [
{
"background": "#fbfbfb",
"foreground": "#0077c2",
@Anwarvic
Anwarvic / punc_cap_f1_scorer.py
Last active July 27, 2022 08:17
A way to calculate F1 scores for punctuation & capitalization restoration tasks given ASR true & predicted transcriptions,
import os
import edlib
import string
import pandas as pd
from sklearn import metrics
from itertools import chain
from nltk.tokenize import word_tokenize
# HELPFUL FUNCTIONS
@Anwarvic
Anwarvic / install_cuda_on_GCP.md
Last active November 21, 2022 18:16
This file is a concrete summary of how to Install Cuda drivers on any GCP instance from scratch.

I created this GitHub Gist to show how to install Cuda on a newly-created VM instance on GCP. If you don't know which GPU model you should use, check out this stackoverflow question.

Before You Start

Simply put, Cuda is just an API for software to use GPU. So, before you install Cuda you have to make sure that it's compitable with your GPU model. In this link, you can find the following table which summarizes the minimum Cuda for each machine:

GPU type
@Anwarvic
Anwarvic / install_kenlm.sh
Created December 26, 2019 09:33
This gits is used to install Ken Language Model package made by Kenneth Heafield. This package is used to create ARPA language models.
# install dependencies (src: https://kheafield.com/code/kenlm/dependencies/)
sudo apt-get install build-essential libboost-all-dev cmake zlib1g-dev libbz2-dev liblzma-dev
# clone official GitHub repo
git clone https://github.com/kpu/kenlm/
# build the repo using cmake
cd kenlm
mkdir -p build
cd build
@Anwarvic
Anwarvic / colab_mic.ipynb
Last active September 2, 2021 04:23
colab_mic.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from joblib import Parallel, delayed
def post_request(word):
response = requests.post("http://172.18.7.39:8181/stemSentence",
data={'sentence': word})
stem = ''
if '"error":false' in response.text:
response = eval(response.text.replace('false', 'False'))
stem = response['stemmedSentence']
return stem
@Anwarvic
Anwarvic / getEncoding.py
Created January 17, 2019 06:35
Get the encoding of an Arabic text
def getEncoding(rawdata, min_confidence=0.9):
"""
Get the encoding of a stream of BYTES (rawdata)
with a minimum confidence.
In case that the confidence is low, return "cp1256"
as I work with Arabic text!!
"""
det = chardet.detect(rawdata[:1000])
data_encoding, confidence = det["encoding"], det["confidence"]
if confidence > min_confidence:
@Anwarvic
Anwarvic / regex(es).py
Last active August 2, 2018 10:21
In this gist, I will write regular expressions for different purposes (incremental)
"""
extract names like:
Mohamed Anwar
Mohamed Anwar Ghanem
Mohamed Anwar Saeed Ghanem
but not:
Mohamed
Mohamed A. Ghanem
"""
regex = r'(([A-Z]{1}[a-z]+)\s){2,}'
@Anwarvic
Anwarvic / replace_regex_with_regex.py
Last active July 10, 2018 14:03
This gist contains a way to remove a regex (regular expression) using the results from another regex.
import re
"""
Here, I will provide a test case of how to remove a regex with another regex in python.
Our test case will be to extract only the comma within numbers and remove it.
So, this sentence "How a 2,000 year old letter can revolutionize your life, it's really amazing."
should be "How a 2000 year old letter can revolutionize your life, it's really amazing."
As you can see, the comma within 2,000 was removed.
We should notice that this number is small, what about a number like 1,123,456,789,101.
In this regex, I've handled all the cases that came into my mind.
@Anwarvic
Anwarvic / PUNCTUATIONS.txt
Last active April 30, 2018 13:33
This gist contains all the punctuations that I could find. Just becareful because some of these characters are special according to some programming languages
ASCII PUNCTUATIONS:
'",.;:?!-/\
ASCII SPECIAL CHARACTERS:
#$%&*+_=@^|~
BRACKETS
()[]{}<>⟨⟩«»‹›
UNICODE PUNCTUATIONS: