In the middle of the desert you can say anything you want
Wrote this small wrapper script that (if a global USE_TQDM
parameter is set) uses pretty tqdm lists on lists that have enough elements where it matters. I think I’ll be reusing it.
So when enabled, it will tqdm a list of 150 elements but won’t tqdm a list of 99 elements.
To use:
for el in _tqdm(whatever_list_thing):
do_stuff_to(el)
Function:
def _tqdm(list_like: Sequence, iflarge: bool = False, lsize: int = 100):
"""Use tqdm if it's on, optionally based on length of list.
Args:
list_like: thing to iterate.
iflarge (bool): If on, will use tqdm only for large lists
lsize (int): anything more than this is 'large'
"""
if USE_TQDM:
if not iflarge:
return tqdm(list_like)
else:
# Count size only if it doesn't mean iterating an iterator
if isinstance(list_like, Sequence) and len(list_like) > lsize:
return tqdm(list_like)
return list_like
Setting is per-project and lives in push rules:
I set the credentials to the right ones the usual ways:
git config user.email "my@verified-ema.il"
But the commits were still using the old identity.
Solution to fix the last commit by only setting the author to the new / current one:
git commit --amend --reset-author --no-edit
Hugo summaries are weird.
.Summary
returns whatever summary it has, which is either the .. more ..
tag, then everything before it gets returned including formatting, or whatever is set in the settings as summary length, while removing markdown formatting.
There was no easy way to get an auto-summary with preserved formatting, except manually adding stuff.
What I really wanted is to truncate posts manually when needed, and leave the rest in full by default while preserving formatting.
Setting the limit to infinite made .Summary
returned the full post with stripped formatting.
(I needed this for footnotes in multiple posts all on the home page, they got mixed up and there were no clean solutions. The blackfriday
renderer could fix this, but not the default goldmark
, which I’m using for some layout issues it does better.)
After googling for better ways to truncate with preserved formatting, found Summary .Render · Scott Willsey
It has this code for a better summarization:
{{ if gt ( sub (len (plainify .Content)) (len .Summary)) 10 }}
{{ .Content | replaceRE "<sup.+>.+</sup>" "" | safeHTML | truncate (len .Summary) }}
<p><i>(<a href="{{ .RelPermalink }}">Read More</a>)</i></p>
{{ else }}
{{ .Content | safeHTML }}
{{- end -}}
{{- if .Params.linkurl -}}
<p><a href="{{ .RelPermalink }}"><i class="fas fa-level-down-alt fa-xs"></i> Permalink</a></p>
{{- end -}}
First up is an if statement that checks to see if the post even needs to be truncated into a summary or not, or whether it’s short enough to just show the whole post.
this works nice, but I wanted no summarization for
{{ if .Truncated}}
{{ .Summary }}
<p><i>(<a href="{{ .RelPermalink }}">Read More</a>)</i></p>
{{ else }}
{{ .Content | safeHTML }}
{{- end -}}
{{- if .Params.linkurl -}}
<p><a href="{{ .RelPermalink }}"><i class="fas fa-level-down-alt fa-xs"></i> Permalink</a></p>
{{- end -}}
and setting the summary limit to infinite.
What this does is:
.Truncated
, return its summary. This means that the POST IS TRUNCATED ONLY IF I MANUALLY ADD THE MORE TAG, because the auto-summary limit is set to a big number.safeHTML
is prolly not needed there but whatever.When downloading a Google Colab (and prolly a classic Jupyter Notebook) as .py it preserves the plain-text cells as python comments!
From No more disk space: How can I find what is taking up the space? - Ask Ubuntu, run this as root:
du -cha --max-depth=1 | grep -E "M|G"
The grep is to limit the returning lines to those which return with values in the Megabyte or Gigabyte range.
Next one would be /var
etc.
Then there’s ncdu
and friends too.
From SO’s credentials - How can I save username and password in Git? - Stack Overflow:
git config --global credential.helper store
Then on the next git pull
the credentials entered will be saved in plain text on disk.
Wow. WOW.
Wrote a program accepting a LONG --yes_delete_all_data_completely
, without a short version, to make sure no one does an error and deletes everything.
Today I mistyped a --y
parameter, it started in the mode above.
Then I learned that argparse does prefix matching.
python - How to share global variables between tests? - Stack Overflow:
import pytest
def pytest_configure():
pytest.my_symbol = MySymbol()
allows then to use pytest.my_symbol
elsewhere, it’s a part of global pytest namespace now.
That said, fixtures are still the preferred way it seems (todo - how are they shared between files?)
Playing with
Spacy and it’s as nice and I thought it’d be.
Interesting bits and general dump of first impressions:
Doc
and Span
are heavily token-based, including for NER stuff. Can’t set a sub-token entity, for example.Doc.char_span()
supports creating a Span based on characters and various alignment methods! Doc · spaCy API Documentation
Example
class for individual training instances can do neat stuff with BIO mapping, aligning of NER tokens etc: Example · spaCy API DocumentationOkay, this blew my mind. Taskwarrior can have lowercase +t
tags, along with the +T
-uppercase ones I’ve been using my entire life.
Wow.