Posts tagged: python
All posts with the tag "python"
The rich console is themeable, I’ve been a long time user of rich and had no
Idea. You can define your own theme keywords and use them just like you use
normal rich keywords in square brackets like'[bold red]'.
from rich.console import Console
from rich.theme import Theme
custom_theme = Theme({
"info": "dim cyan",
"warning": "magenta",
"danger": "bold red"
})
console = Console(theme=custom_theme)
console.print("This is information", style="info")
console.print("[warning]The pod bay doors are locked[/warning]")
console.print("Something terrible happened!", style="danger")
I’m trying to replace my usage of google inline search apps with real apps, today I used a stopwatch to time some things out at work by opening stopwatch. This was something I just wanted running in a tab on another screen, it was not timing running code or anything, I was using it as a reminder to check browser caches every 5 minutes or so for some testing.
So tonight I whipped up a stopwatch, clock and timer, all of which are using the wakelock API to keep the screen on while the app is running.
// Wake Lock support
let wakeLock = null;
async function requestWakeLock() {
try {
if ('wakeLock' in navigator) {
wakeLock = await navigator.wakeLock.request('screen');
console.log("Wake lock acquired");
}
} catch (err) {
console.error("Wake lock error:", err);
}
}
document.addEventListener("visibilitychange", () => {
if (wakeLock !== null && document.visibilityState === "visible") {
requestWakeLock();
}
});
requestWakeLock();
m9a devlog 1
fix feed descriptions
I’ve been using ruff to lint my python code for quite awhile now, I was pretty early to jump on it after release. Some of my projects have had a nice force-single-line setting and some have not. I dug into the docs and it was not clear what I needed to make it work.
[tool.ruff]
select = ['I'] # you probably want others as well
[tool.ruff.isort]
force-single-line = true
Turns out I was missing Isort in the select list.
I was looking back at my analytics page today and wondered what were my posts about back at the beginning. My blog is managed by markata so I looked at a few ways you could pull those posts up. Turns out it’s pretty simple to do, use the markata map with a filter.
from markata import Markata
m.map('title, slug, date', filter='date.year==2016', sort='date')
Note
the filter is python eval that should evaluate to a boolean, all of the
attributes of the post are available to filter on.
Result #
[
('⭐ jupyterlab jupyterlab', 'jupyterlab-jupyterlab', datetime.date(2016, 12, 13)),
('⭐ nickhould tidy-data-python', 'nickhould-tidy-data-python', datetime.date(2016, 12, 9)),
(
'⭐ mikeckennedy write-pythonic-code-demos',
'mikeckennedy-write-pythonic-code-demos',
datetime.date(2016, 11, 22)
),
(
'⭐ mikeckennedy write-pythonic-code-for-better-data-science-webcast',
'mikeckennedy-write-pythonic-code-for-better-data-science-webcast',
datetime.date(2016, 11, 22)
),
('⭐ rajshah4 dlgroup', 'rajshah4-dlgroup', datetime.date(2016, 11, 18)),
('⭐ pandas-dev pandas', 'pandas-dev-pandas', datetime.date(2016, 10, 5))
]
You could use the list command as well right within your shell and the same
map and filters work.
⬢ [devtainer-0.1.3] ❯ markata list --map title --filter='date.year==2016'
[22:35:06] 2088/2145 posts skipped skip.py:36
57/2145 posts not skipped skip.py:37
⭐ pandas-dev pandas
⭐ rajshah4 dlgroup
⭐ mikeckennedy write-pythonic-code-for-better-data-science-webcast
⭐ mikeckennedy write-pythonic-code-demos
⭐ nickhould tidy-data-python
⭐ jupyterlab jupyterlab
You could also do it with jin right inside of a markdown post using the jinja_md plugin.
{% raw %}
{% for title, slug, date in markata.map('title, slug, date', filter='date.year==2016', sort='date') %}
* [{{title}}]({{slug}}) - {{date}}
{% endfor %}
{% endraw %}
Note
You do have to `jinja: true` in the frontmatter of the post.
Result #
{% for title, slug, date in markata.map(’title, slug, date’, filter=‘date.year==2016’, sort=‘date’) %}
- {{title}} - {{date}} {% endfor %}
portal-platformer-devlog-1
I run tailwind for my personal blog, whenever I update it, pre-commit goes in and fixes end of file. I’m sick of these things fighting each other, since it is a generated app it is going to et ignored from pre-commit from now on.
exclude: ^static/app.*\.css$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files