Skip to content

Instantly share code, notes, and snippets.

@jugmac00
jugmac00 / main.py
Last active January 29, 2020 07:08
No need for mocking?
from datetime import date
END_OF_EARLY_BIRD = date(2020, 6, 1)
def calculate_price(current_day):
# if today() > END_OF_EARLY_BIRD:
# no more call to today() => easy to test => no mock necessary
if current_day > END_OF_EARLY_BIRD:
return 1000
# coding=utf-8
import pytest
from Products.Libs.string_utils import try_to_convert_list_to_windows_1252_text
@pytest.mark.parametrize("list_, encoding", [
(["abc", "d€f"], "Windows-1252"),
(["我犀角鳥啄忘我", "我犀角鳥啄忘我"], "UTF-16")
])
import os
import telegram
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin
DAREBEE_URL = "https://www.darebee.com/"
API_KEY = os.getenv("API_KEY")
ID_JUERGEN = os.getenv("ID_JUERGEN")
# fun_with_pdb.py
if __name__ == '__main__':
import pdb;pdb.set_trace()
# create a text file: input.txt
"hello from text file"
# then enter following command in your terminal
# python3 fun_with_pdb.py < input.txt

check support status of installed packages

ubuntu 18.04

$ ubuntu-support-status

ubuntu 20.04

$ ubuntu-security-status

diff --git a/Grammar/Grammar b/Grammar/Grammar
index 170518af74..25067147bf 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -138,7 +138,7 @@ not_test: 'not' not_test | comparison
comparison: expr (comp_op expr)*
# <> isn't actually a valid comparison operator in Python. It's here for the
# sake of a __future__ import described in PEP 401 (which really works :-)
-comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
+comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'~='|'in'|'not' 'in'|'is'|'is' 'not'
@jugmac00
jugmac00 / factory.py
Created June 25, 2020 12:24
converting the type comments in this module to annotations with com2ann breaks the code, cf. postponed evaluation of annotations
from typing import Optional
from typing import List
class Pizza:
def __init__(self, ingredients=None):
# type: (Optional[List[str]]) -> None
if ingredients is None:
self.ingredients = []
else:
self.ingredients = ingredients
@jugmac00
jugmac00 / conftest.py
Created July 9, 2020 14:02
Zope and pytest
import os
import os.path
import sys
import gocept.httpserverlayer.plonetestingzope as gc_httpserverlayer_zope
import gocept.selenium
import plone.testing.layer
import plone.testing.zodb
import plone.testing.zope as plone_testing_zope
import Products.MailHost.tests.testMailHost
branch: 3.9.0b5
@jugmac00
jugmac00 / simple_cache.py
Last active October 10, 2020 10:31
simple cache
from time import sleep
cache = dict()
def get_data():
if not cache.get("items"):
sleep(10) # simulates waiting for data
items = ["a", "b", "c"]
cache["items"] = items