Answer by Louis Maddox for R Markdown - variable output name
You can keep the simplicity of using the RStudio Knit button and reproducibility of a YAML header by using the undocumented knit hook to redefine what the button does (default function called is...
View ArticleAnswer by Louis Maddox for Is there an easy way to convert ISO 8601 duration...
Great question, obviously the "right" solution depends on your expectations for the input (a more reliable data source doesn't need as much input validation).My approach to parse an ISO8601 duration...
View ArticleAnswer by Louis Maddox for Dynamic inheritance in Python
As an alternative to Chris's answer implementing the memoisation suggestion for shx2's answer, I'd prefer to use a memoize decorator (the end result is still a class but it's clearer to me that the...
View ArticleAnswer by Louis Maddox for Python doctest how to match single or double quote...
I imagine you could achieve this with blacken-docs but I haven't seen an example of this done yet...Either the approach of:Leave the strings in black standard (double quoted) and find a way to...
View ArticleAnswer by Louis Maddox for How do I set up custom styles for...
I don't know which is most "official" but if you go to the "customisation" page of the Furo theme (developed by one of the Sphinx developers) and then scroll to "Custom CSS Files" it links to a guide...
View ArticleAnswer by Louis Maddox for Download only a range of bytes or a specific file...
Yes, it’s possible for an uncompressed tarball, the file format has header records about the files you can use to check its contents.I'm more of a Python than a Java guy, but take a look at my...
View ArticleAnswer by Louis Maddox for How to read a file in reverse order?
Here's a Python 3.8+ approach, using two string buffers, with grep-like substring matching (or just simply iterating each and every line if the empty substring is passed). I'd expect this to be more...
View ArticleAnswer by Louis Maddox for Asynchronous Requests with Python requests
I second the suggestion above to use HTTPX, but I often use it in a different way so am adding my answer.I personally use asyncio.run (introduced in Python 3.7) rather than asyncio.gather and also...
View ArticleAnswer by Louis Maddox for Close asyncio loop on KeyboardInterrupt - Run stop...
You want to add a signal handler as shown in this example in the docs:import asyncioimport functoolsimport osimport signaldef ask_exit(signame, loop): print("got signal %s: exit" % signame)...
View ArticleAnswer by Louis Maddox for python asyncio & httpx
Here's a nice pattern I use (I tend to change it a little each time). In general, I make a module async_utils.py and just import the top-level fetching function (e.g. here fetch_things), and then my...
View ArticleAnswer by Louis Maddox for Read webhook payload in Gitlab CI
If you run compgen -v to show the environment variables when triggering the pipeline in the UI (without JSON payload) you get 3 fewer lines in your job log than when POSTing a JSON payload.The...
View ArticleMultiple assignments via walrus := operator?
I've attempted to make multiple assignments with the walrus operator, and seen questions on StackOverflow such as this which also fail to assign multiple variables using a walrus operator, and am just...
View ArticleAnswer by Louis Maddox for Changing file permission in Python
In Python 3.4+, when working with pathlib.Path objects, you can call chmod() directly as a method on the path object. The following example is given in the docs:>>> p =...
View ArticleAnswer by Louis Maddox for GITLAB CI Error loading key "/dev/fd/63": invalid...
As mentioned in this thread on GitLab's bug tracker, the issue can arise when carriage return characters (\r) are added to the variable (a.k.a. "secret"). This can be worked around by piping to tr -d...
View ArticleAnswer by Louis Maddox for Git clone changes file modification time
To do this in Python is simpler than some of these other options, as os.utime accepts the Unix timestamp output by the git log command. This example uses GitPython but it'd also work with...
View ArticleAnswer by Louis Maddox for FFMPEG- Convert video to images
In addition to the select filter in Gyan's answer (which I use with eq rather than between), I came across another filter in the manual: thumbnailSelect the most representative frame in a given...
View ArticleHow to see logs of Dockerfile build when using custom AWS Lambda container image
AWS Lambda supports container images rather than using the standard Amazon Linux (2) image, but I can't figure out where the logs from the Dockerfile build are stored.I can find and see the logs for...
View ArticlePiping Rscript gives error after output
I wrote a small R script to read JSON, which works fine but upon piping withRscript myscript.R | headthe (full, expected) output comes back with an errorError: ignoring SIGPIPE signalExecution...
View ArticleCreate a new file in git bash
I've got Git for Windows running, I'm not sure if it's supposed to function as a text editor though?I think I installed it with the Vim editor, but in a Git Bash shell how do I create a file, such as...
View ArticleAnswer by Louis Maddox for Counting commas in a line in bash
An example Python command you could run (since it's going to be installed on most modern shells) is:python -c "import pathlib; print({l.count(',') for l in...
View Article