simonw / til

Today I Learned
https://til.simonwillison.net
Apache License 2.0
1.02k stars 81 forks source link

What's meaning of the magic numbers? #52

Closed stefanzweig closed 1 year ago

stefanzweig commented 1 year ago

in https://github.com/simonw/til/blob/704ad30c4b7eb6d6009790261e2209331cce7917/metadata.yaml#L24

I wonder what 'b4de2a49c8' and '8c94a2ed4b' mean. Would you explain me this?

Thank you very much.

simonw commented 1 year ago

Those are the sequences that get used to wrap highlighted text - for example:

https://til.simonwillison.net/tils?sql=select%0D%0A++snippet%28%0D%0A++++til_fts%2C%0D%0A++++-1%2C%0D%0A++++%27b4de2a49c8%27%2C%0D%0A++++%278c94a2ed4b%27%2C%0D%0A++++%27...%27%2C%0D%0A++++60%0D%0A++%29+as+snippet%0D%0Afrom%0D%0A++til%0D%0A++join+til_fts+on+til.rowid+%3D+til_fts.rowid%0D%0Awhere%0D%0A++til_fts+match+case%0D%0A++++%3Aq%0D%0A++++when+%27%27+then+%27nomatchforthisterm%27%0D%0A++++else+escape_fts%28%3Aq%29%0D%0A++end%0D%0Aorder+by%0D%0A++til_fts.rank%0D%0Alimit%0D%0A++20&q=pyodide

This returns the following:

b4de2a49c8Pyodide8c94a2ed4b provides "Python with the scientific stack, compiled to WebAssembly" - it's an incredible project which lets you run a full working Jupyter notebook, complete with complex packages such as numpy and pandas, entirely in your browser without any server-side Python component running at all.

Then later I can turn b4de2a49c8Pyodide8c94a2ed4b into <strong>Pyodide</strong>

I could use <strong> and </strong> directly instead, like this:

https://til.simonwillison.net/tils?sql=select%0D%0A++snippet%28%0D%0A++++til_fts%2C%0D%0A++++-1%2C%0D%0A++++%27%3Cstrong%3E%27%2C%0D%0A++++%27%3C%2Fstrong%3E%27%2C%0D%0A++++%27...%27%2C%0D%0A++++60%0D%0A++%29+as+snippet%0D%0Afrom%0D%0A++til%0D%0A++join+til_fts+on+til.rowid+%3D+til_fts.rowid%0D%0Awhere%0D%0A++til_fts+match+case%0D%0A++++%3Aq%0D%0A++++when+%27%27+then+%27nomatchforthisterm%27%0D%0A++++else+escape_fts%28%3Aq%29%0D%0A++end%0D%0Aorder+by%0D%0A++til_fts.rank%0D%0Alimit%0D%0A++20&q=pyodide

But then I'd have to think really hard about HTML escaping: I want to HTML escape any tags that show up in the result, but NOT the strong tags themselves.

So it's easier to use a random token that won't show up in any of the TIL content.