Skip to content

Instantly share code, notes, and snippets.

@dhpour
dhpour / pre-commit
Last active July 19, 2024 09:45
Ban notebook commits if their cell outputs have not been cleared yet! (with underscore-cli help!)
#!/bin/sh
for f in $(git diff --name-only --cached); do
if [[ $f == *.ipynb ]]; then
has_content="$(cat $f | underscore select '.cells' | underscore flatten --shallow | underscore any 'value?.outputs?.length > 0')"
if $has_content
then
echo 'Notebook ' $f ' output cells are not clean!'
echo 'Unstage ' $f ' file and clean its cell outputs'
exit 1
fi
@dhpour
dhpour / gist:cd25e0affff5e921f7ebfb1e40dfe937
Created July 13, 2024 19:26
lucene_persian_stopwords.txt
# originally from Apache Lucene Persian Stop words
# link: https://github.com/apache/lucene/raw/main/lucene/analysis/common/src/resources/org/apache/lucene/analysis/fa/stopwords.txt
# This file was created by Jacques Savoy and is distributed under the BSD license.
# See http://members.unine.ch/jacques.savoy/clef/index.html.
# Also see http://www.opensource.org/licenses/bsd-license.html
# Note: by default this file is used after normalization, so when adding entries
# all arabic occurences of arabic 'ي' are replaced with 'ی'
انان
نداشته
سراسر
@dhpour
dhpour / farsi_normalizer.py
Last active July 9, 2024 14:32
Simple normalizer for Farsi
# converts all possible characters used as Persian to Persian
# converts numbers
# converts punctuations
def normalize(text):
srcLine = ',?%1234567890;“”ﭘﺮﺯﻭﺻكىيﻬ٧ﺍﭙﺚﻖﯿﮎﺗﯼيﺴﻯﮥﺻﯾﺸﺿﻔﻐﻴﺞ٦ﻡےكﻩﺟﺜﻥﺰﻟﭻﻰﻣﻉﻳﺪﻤﺒ٤ﺫﺠﻲﺳﻓﺭﺨﮏﺕﻧﺵﮑ١ﮔﻗ٢ﺘﻱﻭﮯ٥ٱﻫﺩ٨ﻏﻦﻠﺺﺼﭘﺖﺏﻕﺲﺷۀﻎﻝﭽﻮﻑﺶﻨﺮﮕﮐﺣ٩٠٣ةﻍﺝﻒﭼﮓﺹﻌﯽﺛﻄڪﺬﻃﻢﻋﺑﺧﻂﺤﺥﻊﺁﻜﻞﺦﻛﺎﺯﻘﺱﻪہﺐى'
trgLine = '،؟٪۱۲۳۴۵۶۷۸۹۰؛""پرزوصکییه۷اپثقیکتییسیهصیشضفغیج۶میکهجثنزلچیمعیدمب۴ذجیسفرخکتنشک۱گق۲تیویهاهد۸غنلصصپتبقسشهغلچوفشنرگکح۹۰۳هغجفچگصعیثطکذطمعبخطحخعآکلخکازقسههبی'
repl = str.maketrans(srcLine, trgLine)
@dhpour
dhpour / gist:0ea65f1f3a79c0bedb52a5397831b593
Created October 22, 2018 17:34 — forked from ebraminio/gist:5292017
Check Iranian National Code Validity - بررسی صحت کد ملی ایرانی - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin
// Check Iranian National Code Validity - Clojure, C#, Ruby, JavaScript, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin
// بررسی صحت کد ملی ایران - کلوژر، سی‌شارپ، روبی، جاوااسکریپت، پایتون، اسکالا، جاوا ۸، پی‌اچ‌پی، سی، گو، سوئیفت، کاتلین
// در نسخه‌های قبل یکسان بودن اعداد نا معتبر تشخیص داده می‌شد ولی
// اعداد یکسان نامعتبر نیست http://www.fardanews.com/fa/news/127747
// بعضی از پیاده‌سازی‌ها سریع نیستند، می‌توانید نسخهٔ خود را بر پایهٔ
// نسخهٔ سی یا گو ایجاد کنید که بهترین سرعت را داشته باشد
/**