- https://docs.pydantic.dev/latest/api/types/#pydantic.types.SecretStr
- https://github.com/pydantic/pydantic/blob/main/pydantic/types.py#L1527
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
""" | |
Pydantic Secrets | |
https://docs.pydantic.dev/latest/api/types/#pydantic.types.SecretStr | |
- Why does the "Box'ed" secret container understand (or leak) information of the secret? | |
- Internally, the "Box" shouldn't use `.get_secret_value()`. Otherwise, it's leaking info. | |
- Mixing up the Box and `.get_secret_value()` undermines the point of using `.get_secret_value()` | |
- Why is the hash value leaking? Comparing two secrets should require and explicit `s1.get_secret_value() == s2.get_secret_value()` call. | |
- Why does the repr/str communicate "non-empty" values? This is encouraging and enabling an anti-pattern. |
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
""" | |
https://github.com/pydantic/pydantic/issues/10724 | |
Example of using complex keys in Dict using Pydantic for Serialization | |
There's a two different approaches | |
1. Fundamentally hook into the core serialization and map the structure into a list[{Key, Value}] (or similar) to get the Obj -> Json -> Obj working | |
2. Create an intermediate Object in Pydantic and add `to_X` method and `from_X` classmethod to get the Obj -> Obj2 -> Json -> Obj2 -> Obj | |
Method 2 is shown below |
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
""" | |
Different workarounds for setting a configuration file path at runtime. | |
https://github.com/pydantic/pydantic-settings/issues/259 | |
There's an explicit step of validating the file path to make the errors more obvious. | |
Otherwise, a cryptic pydantic error will be raised. | |
""" | |
import argparse |
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
.PHONY: compile run extract | |
default: compile ; | |
compile: | |
scala-cli compile gibson.scala | |
fmt: | |
scala-cli fmt . | |
run: | |
./gibson scraper -o . |
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
//> using platform "jvm" | |
//> using scala "2.13.8" | |
//> using lib "dev.zio::zio:1.0.14" | |
//> using lib "com.monovore::decline:2.2.0" | |
//> using mainClass "DeclinedApp" | |
// Runnable using `scala-cli run Declined.scala -- --user Ralph --alpha 3.14` | |
import zio.{ExitCode, ZEnv, ZIO, Task, RIO, IO, UIO, URIO} | |
import zio.console._ |
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 sys | |
import json | |
import logging | |
from typing import List, Tuple, Dict, Any | |
from selenium import webdriver | |
from bs4 import BeautifulSoup | |
import pandas as pd | |
log = logging.getLogger(__name__) |
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 of Using a Subparser | |
Demonstration of using two Pydantic data models to | |
build a subparser and sharing options. | |
The major friction point and limitation is the order in which the options appear in --help. | |
For example, |
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
"""PyBites Amazon book affiliation link generator. | |
Uses the link pasted to clipboard and puts the generated link back onto the | |
clipboard. https://pybit.es/pyperclip.html | |
Set the AMAZON_AFFILIATE_CODE variable to your own Amazon affiliate code. | |
From https://twitter.com/pybites/status/1277141497117323266 | |
Separate concerns and enable other AF codes to be registered and |
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 $ivy.`com.zaxxer:nuprocess:2.0.0`, com.zaxxer.nuprocess._ | |
import scala.collection.JavaConverters._ | |
import java.nio.ByteBuffer | |
import scala.concurrent.{Future, Promise} | |
class ProcessHandler extends NuAbstractProcessHandler { | |
private var nuProcess: NuProcess = null | |
override def onStart(nuProcess: NuProcess): Unit = { |
NewerOlder