mirror of
https://github.com/lavafroth/lavafroth.github.io.git
synced 2026-06-06 17:31:15 -03:00
chore: keep yapping succinct
This commit is contained in:
@@ -9,12 +9,10 @@ tags:
|
||||
- Algebraic Data Types
|
||||
---
|
||||
|
||||
As much as I like Rust for its ergonomic features, university has forced me to
|
||||
use Python for the past couple of months, especially because of the hype for
|
||||
machine learning and data science.
|
||||
|
||||
One of the biggest things that I missed from the rust experience was enumerable
|
||||
data types whose variants can wrap around different datatypes.
|
||||
University has compelled me to utilize Python despite my fondness for Rust,
|
||||
primarily due to the prevalence of machine learning and data science. One
|
||||
aspect of Rust that I dearly miss is the availability of enumerable data types
|
||||
that can encapsulate various data types.
|
||||
|
||||
Although Python has the answer to creating structs as
|
||||
[dataclasses](https://peps.python.org/pep-0557/), including support for
|
||||
@@ -240,10 +238,12 @@ def AlgebraicEnum(cls):
|
||||
```
|
||||
|
||||
The inheritance means all methods of the outer class are available on the nested
|
||||
classes _and_ any object of a nested class `isinstance` of the outer class.
|
||||
classes via the method resolution order chain _and_ any object of a nested class
|
||||
`isinstance` of the outer class.
|
||||
|
||||
That's all there is to the magic! Now we can simply add this decorator above the previous class declaration
|
||||
and the variants like `Glass.Empty` and `Glass.Full` would be of the type `Glass`.
|
||||
That's all there is to the magic! Simply adding this decorator above the
|
||||
previous class declaration make variants like `Glass.Empty` and `Glass.Full`
|
||||
inherit `Glass`.
|
||||
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
@@ -272,13 +272,9 @@ class Glass:
|
||||
return False
|
||||
```
|
||||
|
||||
As a bonus, the variants will also inherit any methods defined on the `Glass` type.
|
||||
|
||||
Note how the `report_drink` method accepts a `self` of type `Glass` and the match arms
|
||||
compare it with `Glass.Empty` and `Glass.Full`.
|
||||
|
||||
These methods get automatically called via the method resolution order chain due to the inheritance.
|
||||
|
||||
The following code runs just fine.
|
||||
|
||||
```python
|
||||
|
||||
@@ -12,9 +12,8 @@ Additionally some might even keep `builtins` and `eval` out of reach.
|
||||
|
||||
[Here](https://www.youtube.com/watch?v=SN6EVIG4c-0) is a cool video explanation by @pwnfunction on server side template
|
||||
injection wherein he mentions a way to "gadget" our way out of Flask's Jinja2 backend to get remote code execution.
|
||||
Kudos to him for sharing this technique.
|
||||
|
||||
For those of you reluctant to watch a 10 minute video (although I'd highly recommend watching it), here's the gist of it:
|
||||
Here's the gist of it:
|
||||
|
||||
```python
|
||||
''.__class__
|
||||
|
||||
@@ -81,9 +81,7 @@ caused by the GPU also deteriorated the signal strength. I mean, what was I
|
||||
thinking back when I bought this? I knew I was going to use Linux because I
|
||||
distinctly remember my previous Arch + i3wm. The reason behind a gaming laptop
|
||||
was not to play games, Linux did not have great tooling for gaming then. No, I
|
||||
needed the beefy GPU to crack password hashes for capture the flag challenges
|
||||
😉. In retrospect, social engineering and educated guesses turned out to be a
|
||||
way less resource intensive means to, ahem, crack password hashes.
|
||||
needed the beefy GPU to mine coins.
|
||||
|
||||
Speaking of the GPU, I severly underestimated how heavy it would make the box. If not for the shape of the laptop, I could easily use
|
||||
it for weights during workouts.
|
||||
|
||||
Reference in New Issue
Block a user