Skip to content

Instantly share code, notes, and snippets.

@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:')
@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 / 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 / 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 / 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
"""A simple script to unignore all the ignored words in a specific course in memrise.
You need to provide USERNAME, PASSWORD, and COURSE_URL below.
"""
from selenium.webdriver import Chrome
USERNAME = ''
PASSWORD = ''
COURSE_URL = 'https://app.memrise.com/course/{number}/{name}/'
@5j9
5j9 / 3rr.js
Last active July 31, 2020 05:28
detecting 3rr on wikipedia using the selected revisions
var checked_revs = document.querySelectorAll('#pagehistory input[type=checkbox]:checked');
var user_revs = {};
var user, parent, date, revs;
checked_revs.forEach(function(check){
parent = check.parentNode;
user = parent.querySelector('.mw-userlink').innerText;
date = new Date(parent.querySelector('.mw-changeslist-date').innerText);
rev = {"date": date, "parent": parent};
revs = user_revs[user];
if (!revs) {
@5j9
5j9 / wsgiref_flask.py
Created December 21, 2020 16:13
running flask app using python's built-in wsgiref
# call this server using the following js command from the browser console:
# (await fetch('http://localhost:5000/', {method: "POST", body: '5'})).text()
# note: wsgiref is only good for development and in that case Werkzeug is
# usually preferred. See http://mitsuhiko.pocoo.org/wzdoc/wsgihowto.html
from wsgiref.simple_server import make_server
from flask import Flask, request, Response
app = Flask(__name__)
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 1.
Intended Graduate Major,"VR 130-
134","VR 135-
139","VR 140-
144","VR 145-
149","VR 150-
154","VR 155-
159","VR 160-
164","VR 165-
169",VR 170,VR N,VR M,VR SD,"QR 130-
134","QR 135-
<!doctype html><html lang=en><head><meta charset=utf-8><meta http-equiv=cleartype content="on"><meta http-equiv=x-ua-compatible content="ie=edge"><meta name=viewport content="width=device-width,initial-scale=1"><meta name=HandheldFriendly content="True"><meta name=MobileOptimized content="320"><meta name=apple-itunes-app content="app-id=504631398, app-argument=https://www.usatoday.com/story/entertainment/movies/2019/11/12/star-wars-disney-plus-changes-controversial-han-solo-greedo-scene/2576097001/entertainment/movies"><meta content="#ffffff" name=theme-color><meta content="article" property="og:type"><meta property="article:content_tier" content="free"><meta property="article:opinion" content="false"><meta property="fb:pages" content="13652355666"><meta property="og:title" content="The infamous 'Han shot first' scene in 'Star Wars' has changed yet again on Disney+"><meta name=description content="\" did han shoot first?\" has been debated for years among \"star wars\" fans and the controversy is stoked again