This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Example HTTPS server that obtains a certificate using ACME `http-01` | |
challenge and auto-renews ahead of expiry. | |
Taken from https://gist.github.com/mmalone/12f5422b2ec68e64e9d11eae0c6ca47d | |
and updated for Python 3. | |
The workflow consists of: | |
(Account creation) | |
- Create account key | |
- Register account and accept TOS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/md5" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"os" | |
"path/filepath" | |
"regexp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ibm_db | |
from ibm_db_dbi import Connection | |
ibm_db_conn = ibm_db.pconnect( | |
"", | |
"", | |
"", | |
) | |
conn = Connection(ibm_db_conn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(db2-3.8b) $ python3 --version | |
Python 3.8.13 | |
(db2-3.8b) $ pip3 install ibm_db==3.1.2 --no-build-isolation -v | |
Using pip 22.1.2 from /a/plape03/python_venv/db2-3.8b/lib/python3.8/site-packages/pip (python 3.8) | |
Collecting ibm_db==3.1.2 | |
Downloading ibm_db-3.1.2.tar.gz (1.1 MB) | |
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 2.1 MB/s eta 0:00:00 | |
Running command Preparing metadata (pyproject.toml) | |
oput 'DB2.DB2C10.SDSNMACS(DSNAO64C)' '/z/masserv/python38/tmp/pip-install-c0bkdl6h/ibm-db_7824cf0483e3460b9b259a1636d1c875/libdsnao64c.x' | |
Detected 64-bit Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(db2-3.8b) $ pip3 install wheel | |
Collecting wheel | |
Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB) | |
Installing collected packages: wheel | |
Successfully installed wheel-0.37.1 | |
[notice] A new release of pip available: 22.1.2 -> 22.2.2 | |
[notice] To update, run: pip install --upgrade pip | |
(db2-3.8b) $ pip3 install ibm_db==3.1.1 --no-build-isolation -v | |
Using pip 22.1.2 from /a/plape03/python_venv/db2-3.8b/lib/python3.8/site-packages/pip (python 3.8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ibm_db | |
userid = ... | |
password = ... | |
ibm_db_conn = ibm_db.pconnect( | |
"database=DATABASE;hostname=your.system.net;port=1234;protocol=tcpip;uid=%s;pwd=%s" | |
% (userid, password), | |
"", | |
"", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colors = ["red", "green", "blue", "orange"] | |
# ❌ | |
found = False | |
for color in colors: | |
if color == "orange": | |
found = True | |
break | |
if not found: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colors = ["cyan", "magenta", "yellow", "black"] | |
def compare_length(c1, c2): | |
if len(c1) < len(c2): | |
return -1 | |
if len(c1) > len(c2): | |
return 1 | |
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colors = ["cyan", "magenta", "yellow", "black"] | |
for color in sorted(colors): | |
print(color) | |
for color in sorted(colors, reverse=True): | |
print(color) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
names = ["Pierre", "Per", "Peter"] | |
colors = ["cyan", "magenta", "yellow", "black"] | |
# ❌ | |
n = min(len(names), len(colors)) | |
for i in range(n): | |
print(f"{names[i]} --> {colors[i]}") | |
# ✔️ | |
for name, color in zip(names, colors): |
NewerOlder