Skip to content

Commit

Permalink
♻️ reorganize assets
Browse files Browse the repository at this point in the history
  • Loading branch information
mason3k committed Sep 26, 2023
1 parent 648b26a commit 2baf8ed
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 20 deletions.
6 changes: 3 additions & 3 deletions _posts/2022-12-22-wwbd-extension.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ categories:
- extensions
- dev-environment
header:
teaser: /assets/markus-spiske-code.jpg
teaser: /assets/2022-12-22/markus-spiske-code.jpg
---

This functionality is now part of the standard Python extension - [check it out](https://code.visualstudio.com/docs/python/environments)!
Expand All @@ -21,7 +21,7 @@ If you're like me, you know that even for small Python projects and scripts, you

This post is aimed at those of you who *know* you should be using venvs for your one-off apartment-hunt screenscraper/fantasy football stat aggregator/\*gasp\* real work script but don't because, let's face it, the typical venv workflow is not as simple as it could be (was that `/Scripts/Activate.ps1` or `scripts/activate.ps1`??).

![st-augustine]({{ "/assets/staugustine.jpeg" | relative_url }}){: .align-center}
![st-augustine]({{ "/assets/2022-12-22/staugustine.jpeg" | relative_url }}){: .align-center}
*Lord, make me a good venv user, but not yet*
{: .text-center}

Expand All @@ -32,7 +32,7 @@ Lately, I've been living up to my venv ideals almost entirely due to a little [e
Jesus, in this formulation, has been replaced by Python Jesus/Python core developer [Brett Cannon](https://fosstodon.org/@brettcannon
), who has spent quite a bit of time thinking about Python packaging, environment strategy, and developer best practices. He's now allowing us live a day (ok, fine, maybe just a second) in the life via this extension, which essentially automates venv creation, activation, and VS Code integration according to his virtual environment philosophy.

![ridealong]({{ "/assets/ridealong.webp" | relative_url }}){: .align-center}
![ridealong]({{ "/assets/2022-12-22/ridealong.webp" | relative_url }}){: .align-center}
*Kind of like a Python ride-along*
{: .text-center}

Expand Down
16 changes: 8 additions & 8 deletions _posts/2023-01-06-uncurl.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ categories:
- til
- scripting
header:
teaser: /assets/html.avif
teaser: /assets/2023-01-06/html.avif
---

### Uncurl
Expand All @@ -16,7 +16,7 @@ Today I learned about a handy little project called [`uncurl`](https://github.co

No, this is not a tool to take the [coolest sport](https://olympics.com/en/video/edin-makes-a-curling-spin-o-rama-in-sweden-s-last-shot) out of the Olympics or de-Hermione Anne Hathaway. It takes the text of a curl command and converts it to Python code using the [Requests library](https://requests.readthedocs.io/en/latest/).

![anne-hathaway]({{ "/assets/anne_hatheway_pre.png" | relative_url }}){: .align-center}
![anne-hathaway]({{ "/assets/2023-01-06/anne_hatheway_pre.png" | relative_url }}){: .align-center}
*Julie Andrews hates volume??*
{: .text-center}

Expand Down Expand Up @@ -44,19 +44,19 @@ So this is a nice little tool. But pair it with the option in your browser's Dev

In solidarity with the curly-haired women maligned by the 2000s glow-up montage ✊, we'll head over to `functionofbeauty.com`'s hair profile builder and prepare to lock in some moisture.

![joke_husky]({{ "/assets/joke_husky_small.jpeg" | relative_url }}){: .align-center }
![joke_husky]({{ "/assets/2023-01-06/joke_husky_small.jpeg" | relative_url }}){: .align-center }
*If this post is a mini-class, would that make it METHODofbeauty.com?*
{: .text-center}

Let's say the information we want to parse only appears when we select curl type "3B" and click "Submit".
![curl-type-submit.jpg]({{ "/assets/curl_type_submit.jpg" | relative_url }}){: .align-center}
![curl-type-submit.jpg]({{ "/assets/2023-01-06/curl_type_submit.jpg" | relative_url }}){: .align-center}

We'll open up DevTools and navigate to the Network tab to see what request is made so we can replicate it in our Python code.
![curl-type.jpg]({{ "/assets/curl_type.jpg" | relative_url }}){: .align-center}
![curl-type.jpg]({{ "/assets/2023-01-06/curl_type.jpg" | relative_url }}){: .align-center}

And there it is! But it's not just a trivial little GET, but a POST. We actually have to send some form-encoded data, and we'll get the full HTML we need back, ready for parsing. We could write our request manually in Python, but why bother? We have conditioning to get back to. All we need to do is use this handy little option to copy the request we triggered as curl:

![curl-type.jpg]({{ "/assets/copy_as_curl.jpg" | relative_url }}){: .align-center}
![curl-type.jpg]({{ "/assets/2023-01-06/copy_as_curl.jpg" | relative_url }}){: .align-center}

Now we have our full curl command, locked and loaded in our clipboard!

Expand All @@ -83,7 +83,7 @@ curl 'https://www.functionofbeauty.com/order/ajax/update_curl_options.php' \

We'll head over to the terminal, feed this whole command (in quotes) to `uncurl`, and watch the uncurl magic happen:

![uncurl_terminal]({{ "/assets/uncurl_terminal.jpg" | relative_url }}){: .align-center}
![uncurl_terminal]({{ "/assets/2023-01-06/uncurl_terminal.jpg" | relative_url }}){: .align-center}

Copy and paste this output to a file, drop an `import requests` at the the top, pip install `requests` into your venv (you are using a [per-project venv]({{ site.baseurl }}{% post_url 2022-12-22-wwbd-extension %}) aren't you 👀), and you have a functioning little Python script!

Expand Down Expand Up @@ -170,4 +170,4 @@ Plus, if you're using this functionality to screen scrape, some sites block requ

I'd say that's pretty fabulous.

![anne_smiley]({{ "/assets/anne_smiley.jpeg" | relative_url }}){: .align-center}
![anne_smiley]({{ "/assets/2023-01-06/anne_smiley.jpeg" | relative_url }}){: .align-center}
18 changes: 9 additions & 9 deletions _posts/2023-01-10-rich-repl.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ categories:
- tools
- dev-environment
header:
teaser: /assets/rainbow.avif
teaser: /assets/2023-01-10/rainbow.avif
---

### Your REPL, Colorized
Expand All @@ -18,7 +18,7 @@ When I want to do a quick verification on syntax or try a snippet of code, my to

While some developers take pride in using the least attractive, least GUI-fied interface possible, I actually like tech that reflects we've made it past Pong.

![pong]({{ "/assets/Pong.webp" | relative_url }}){: .align-center}
![pong]({{ "/assets/2023-01-10/Pong.webp" | relative_url }}){: .align-center}

On the other hand, I love the terminal. The versatility, speed, and kindd of just the fact it's always around makes it the tool of choice for a ton of little admin tasks, including, as I mentioned, playing around in Python.

Expand All @@ -28,19 +28,19 @@ Enter: Rich! Brought to us by the prolific [Will McGugan](https://www.willmcguga

But for our purposes, we're going to rely on just a handful of lines to go from this:

![before-rich]({{ "/assets/before_rich.jpg" | relative_url }}){: .align-center}
![before-rich]({{ "/assets/2023-01-10/before_rich.jpg" | relative_url }}){: .align-center}
{: .text-center}

To this:

![after-rich]({{ "/assets/richafter.jpg" | relative_url }}){: .align-center}
![after-rich]({{ "/assets/2023-01-10/richafter.jpg" | relative_url }}){: .align-center}
{: .text-center}

### The Setup

So now you're feeling like Dorothy pre technicolor-house-manslaughter. So let's get into how to set this up.

![dorothy]({{ "/assets/dorothy.gif" | relative_url }}){: .align-center}
![dorothy]({{ "/assets/2023-01-10/dorothy.gif" | relative_url }}){: .align-center}
*I don't think we're in MS-DOS anymore, Toto*
{: .text-center}

Expand All @@ -59,13 +59,13 @@ As documented in the [Rich docs](https://rich.readthedocs.io/en/stable/introduct

Trying out some built-in types:

![rich]({{ "/assets/builtins-ex.jpg" | relative_url }}){: .align-center}
![rich]({{ "/assets/2023-01-10/builtins-ex.jpg" | relative_url }}){: .align-center}

#### Make it Permanent

But we are developers. We are, per our sacred text XKCD, automators to a fault.

![rich]({{ "https://imgs.xkcd.com/comics/automation.png" }}){: .align-center}
![rich]({{ "<https://imgs.xkcd.com/comics/automation.png>" }}){: .align-center}
*Sob*
{: .text-center}

Expand Down Expand Up @@ -100,7 +100,7 @@ export PYTHONSTARTUP=~/.pythonrc

Restart your shell, enter the Python REPL, and taste the rainbow.

![pythonrc]({{ "/assets/post-boilerplate.jpg" | relative_url }}){: .align-center}
![pythonrc]({{ "/assets/2023-01-10/post-boilerplate.jpg" | relative_url }}){: .align-center}

### Bonus

Expand All @@ -112,6 +112,6 @@ from rich import print

This will cause any normal `print` statements in your code to be rendered with the same beauty that you're now accustomed to in the REPL.

![pythonrc]({{ "/assets/horse-oz.gif" | relative_url }}){: .align-center}
![pythonrc]({{ "/assets/2023-01-10/horse-oz.gif" | relative_url }}){: .align-center}

And you're off! Happy coloring.
26 changes: 26 additions & 0 deletions _posts/2023-09-25-code-smell-too-many-arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: "Code Smell: Too Many Arguments"
date: 2023-09-26T01:56:26.439Z
categories:
- design
header:
teaser: ""
---

### The Problem

- example:

### Containing the Beast

- dataclasses
- frozen
- single responsibility principle

### Adding Pydantic

- coercing user/API data

### Putting it All Together

- go back to example and walk through
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
Binary file removed assets/httpx_example.jpg
Binary file not shown.
Binary file removed assets/requests_example.jpg
Binary file not shown.

0 comments on commit 2baf8ed

Please sign in to comment.