Skip to content

Instantly share code, notes, and snippets.

@5j9
5j9 / pip-upgrade-all.sh
Last active November 30, 2018 03:12
Upgrade all non-editable pip packages
pip list -o --exclude-editable --format freeze | cut -d= -f1 | xargs -n1 pip install -U
@5j9
5j9 / mytest.py
Last active August 6, 2018 04:52
Comparing different nested dictionary access methods; 50% key availablity
from timeit import *
try_method = '''
try:
d[1][2]
except KeyError:
pass
'''
get_method = 'd.get(1, {}).get(2, {})'
if_method = '''
@5j9
5j9 / test.py
Last active May 30, 2018 23:42
timings for a is_mixed_case(string) function
from timeit import timeit
name = 'common_case'
def f0(name): # 0.38833552993028425
stripped_name = name.strip('_')
tail = stripped_name[1:]
return stripped_name[:1].islower() and tail.lower() != tail
def f1(name): # 0.5023811628120246
@5j9
5j9 / worldscienceu_downloader.py
Created December 25, 2017 07:45
A script to download WorldScienceU coarse videos
"""Download WorldScienceYou coarse videos.
Requirements:
* python 3.6+
* pip install youtube-dl requests
* create a config.py file with USERNAME and PASSWORD variables.
Running the script:
Make sure the coarse number at the last line of the script is correct and
then run...
@5j9
5j9 / khayyam_vs_jdatetime.py
Last active June 26, 2017 08:02
Python's khayyam vs jdatetime performance comparison
from jdatetime import date as jd, GregorianToJalali, JalaliToGregorian
import khayyam, jdatetime
from khayyam import JalaliDate
from datetime import date
from timeit import timeit
print('khayyam.__version__:', khayyam.__version__)
print('jdatetime.__VERSION__:', jdatetime.__VERSION__)
print('Jalali to Gregorian:')