Thursday, August 26, 2021

Python Bytes: #247 Do you dare to press "."?

<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=ujxj1YX7PWM' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>About the show</strong></p> <p>Special guest: <a href="https://twitter.com/qubitron"><strong>Dan Taylor</strong></a></p> <p><strong>Michael #1:</strong> <a href="https://github.com/np-8/wakepy"><strong>Keep your computer awake during long processing</strong></a></p> <ul> <li>For now, use <a href="https://github.com/mikeckennedy/wakepy"><strong>Michael’s fork</strong></a> when on macOS. Until <a href="https://github.com/np-8/wakepy/pull/12"><strong>this PR is merged</strong></a>.</li> <li>Do you have work that will take a long time?</li> <li>Keeping your OS working away is just a context block</li> </ul> <pre><code> from wakepy import keepawake with keepawake(keep_screen_awake=False): ... # do stuff that takes long time </code></pre> <p><strong>Brian #2:</strong> <a href="https://www.dataschool.io/how-to-ask-for-coding-help-online/"><strong>How to write a great Stack Overflow question</strong></a></p> <ul> <li>via Kevin Markham</li> <li>The punchline (but it’s not enough) <ul> <li>Write a brief introduction</li> <li>Provide a self-contained code example</li> <li>Detail the expected results and why I expect those results</li> <li>Add any important notes</li> <li>Link to any relevant questions</li> <li>Write a title that summarizes the question</li> </ul></li> <li>Kevin starts with a question about pandas dataframes and filling in missing values. <ul> <li>The question is really application specific</li> </ul></li> <li>The rewrite of the question is awesome <ul> <li>Simplifies the problem into a toy example, literally, and out of the domain specific context.</li> <li>Includes example code that can copied, pasted, and run that sets up the problem</li> <li>Uses short and simple variable names</li> <li>Talks about expected results. And why he expects those results.</li> <li>Includes a dataset in the sample code that covers cases the solution needs to provide</li> <li>Includes non-obvious requirements or non-requirements</li> <li>Links to related questions and why they don’t solve your problem.</li> </ul></li> <li>I don’t think I’ve ever seen this, but I think it’d be cool to add test code that will pass when the problem is solved. But that might make the question unnecessarily long.</li> </ul> <p><strong>Dan #3:</strong> <a href="https://www.tiktok.com/@vscode/video/6995256325295082757"><strong>Github.dev - press ‘.’ to edit code in any GitHub repo</strong></a> </p> <ul> <li>Fun bonus feature released at the same time as <a href="https://github.com/features/codespaces">GitHub Codespaces</a> </li> <li>Runs VS Code entirely in your browser - supercharged “edit button” <ul> <li>Nothing to install</li> <li>There’s no server to pay for, though functionality is limited</li> <li>The file system is your browser’s local storage and GitHub repo</li> <li>You can add files and commit changes directly to your repo</li> </ul></li> <li>You can install extensions that support running in “VS Code Web”</li> <li>Added basic web support to the Python Extension just yesterday <ul> <li>Syntax checking, auto-complete, go-to-definition</li> <li>Uses type hints for packages (no python interpreter in the browser)</li> </ul></li> <li>You can also install <a href="https://ift.tt/2Wqkx7Y> to run Python code using Jupyter+Pyiodide</li> <li>Overall means you can do more powerful code editing quickly in GitHub.com, I’m looking forward to seeing how this evolves</li> </ul> <p><strong>Michael #4:</strong> <a href="https://twitter.com/junctionapps/status/1425530639621754882"><strong>Log analyzer (minus google analytics)</strong></a></p> <ul> <li><strong>GoAccess</strong> is an open source <strong>real-time web log analyzer</strong> and interactive viewer that runs in a <strong>terminal</strong> in *nix systems or through your <strong>browser</strong>.</li> <li>Features <ul> <li><strong>Fast</strong>, <strong>real-time</strong>, millisecond/second updates, written in C</li> <li><strong>Only</strong> ncurses as a <strong>dependency</strong></li> <li><strong>Nearly all</strong> web log <strong>formats</strong> (Apache, Nginx, Amazon S3, Elastic Load Balancing, CloudFront, Caddy, etc)</li> <li>Simply set the log format and run it against your log</li> <li>Beautiful terminal and bootstrap dashboards (Tailor GoAccess to suit your own color taste/schemes)</li> </ul></li> </ul> <p><strong>Brian #5:</strong> <a href="https://github.com/KMKfw/kmk_firmware"><strong>KMK: Clackety Keyboards Powered by Python</strong></a></p> <ul> <li>recommended by <a href="https://twitter.com/controlpl4n3/status/1429915992650665986?s=20">Blaise</a></li> <li>“firmware for computer keyboards written and configured in CircuitPython.”</li> <li>Cool list of features <ul> <li>Fully configured through a single, easy to understand Python file.</li> <li>Single-piece or two-piece split keyboards are supported</li> <li>Chainable keys such as KC.LWIN(KC.L) to lock the screen on a Windows PC</li> <li>Built-in unicode macros, including emojis</li> <li>RGB underglow and LED backlights</li> <li>One key can turn into many more based on how many times you tap it</li> </ul></li> <li>One writeup I found of someone using it for a 10-key <ul> <li><a href="https://epxx.co/artigos/kmk.html">KMK: run Python on your keyboard</a></li> <li>includes a video</li> </ul></li> <li>Seems like limited hardware so far, and although the coding might not be too difficult, you still gotta swap out of the circuitboard.</li> <li>I’m bringing this topic up because I’m hoping some keyboard kit people will put together something that just starts with the ability to run CircuitPython so I can just skip to the coding part. </li> </ul> <p><strong>Dan #6:</strong> <a href="https://github.com/tiangolo/sqlmodel"><strong>SQLModel - use the same models for SQL and FastAPI</strong></a> </p> <ul> <li>via <a href="https://twitter.com/tiangolo/status/1430252646968004612">Sebastián Ramírez</a> (creator of SQLModel and FastAPI)</li> <li>Write a schema once and use everywhere, reduces a lot of repetitive code <ul> <li>Traditionally have to manage several layers of code to pass your data from database queries, to the backend code, expose to your API and consume from the client</li> <li>Code-first ORMs (SQLAlchemy, Django ORM) make it easy to write code that generates SQL</li> <li>FastAPI makes it easy to expose objects to your API using Pydantic models</li> <li>Before you would need to create both models and convert from ORM to Pydantic using .from_orm</li> </ul></li> <li>SQLModel unifies those: a SQLModel is both a SQLAlchemy model and a Pydantic model <ul> <li>You can use SQLModel to interact with the database (via wrapping SQLAlchemy)</li> <li>You can use that same model as a Pydantic model in FastAPI <a href="https://sqlmodel.tiangolo.com/tutorial/fastapi/simple-hero-api/#create-heroes-path-operation">requests</a> and <a href="https://sqlmodel.tiangolo.com/tutorial/fastapi/response-model/#use-response_model">responses</a></li> <li>FastAPI also uses the Pydantic models to generate an openapi.json, meaning you could generate a client library in any language using <a href="https://github.com/OpenAPITools/openapi-generator">OpenAPI Generator</a></li> </ul></li> <li>Some other cool things: <ul> <li>Designed using type annotations so that editors like VS Code, PyCharm give great auto-complete out of the box, uses the proposed <a href="https://github.com/microsoft/pyright/blob/main/specs/dataclass_transforms.md">dataclass_transforms</a> spec for dynamic typing</li> <li>Supports async database sessions, alembic migrations because it’s based on SQLAlchemy (not yet documented)</li> <li>Should be possible to integrate with postgis, ts_vectors</li> </ul></li> </ul> <p><strong>Extras</strong></p> <p>Brian </p> <ul> <li><a href="https://testandcode.com/163">pip install ./local_directory</a> is pretty interesting. Test &amp; Code 163 <ul> <li>The way pip installs from a local directory is about to change. Stéphane Bidoul joins the show to talk about it.</li> </ul></li> </ul> <p>Dan</p> <ul> <li><a href="https://mirblog.net/index.php/2021/07/31/development-and-release-of-type4py-machine-learning-based-type-auto-completion-for-python/">type4py</a> - using ML to add type annotations to your codebase <ul> <li>retrofitting codebases with types is a pain — static type checkers can only infer so much</li> <li>type4py <a href="http://research paper">research paper</a> outlines a state of the art ML model for inferring types, adopting some techniques used in computer vision </li> <li>Open sourced <a href="https://github.com/saltudelft/type4py">training code</a>, <a href="https://zenodo.org/record/4719447">data set</a>, <a href="https://github.com/saltudelft/type4py-vscode-ext">VS Code extension</a>, and <a href="https://github.com/saltudelft/type4py/tree/server/type4py/server">inferencing server</a></li> <li>If you have a need to add type annotations to a large code base, worth giving this a try!</li> <li><strong>WARNING</strong> the VS Code extension sends code tokens to their API on type4py.com (they do have a <a href="https://github.com/saltudelft/type4py-vscode-ext/blob/master/PRIVACY.md">privacy policy</a>) — if this is a concern be sure to host the inferencing server yourself!</li> </ul></li> </ul> <p><strong>Joke:</strong> <a href="https://geek-and-poke.com/geekandpoke/2017/11/27/simply-explained"><strong>Continuous Deployment</strong></a></p> <p>Also:</p> <p>“If a programmer gets an interview because of a recommendation from a friend, are they being passed by reference?” From <a href="https://twitter.com/CarlaNotarobot">@CarlaNotarobot</a>, via <a href="https://twitter.com/bluefiddleguy/status/1430194434713522182">@bluefiddleguy</a></p>

from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...