-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from int3l/main
Examples for episodes 547 & 548
- Loading branch information
Showing
11 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# [shell vs environment variables (and env, export, etc.) (intermediate)](https://youtu.be/h36Xc38SDHg) | ||
|
||
Today we talk about environment variables, shell variables, shorthand(s) for setting them and unsetting them! | ||
|
||
## Interactive examples | ||
|
||
### Python | ||
|
||
```python | ||
import os | ||
'X' in os.environ | ||
``` | ||
|
||
### Bash | ||
|
||
```bash | ||
NOSHOW=1 python3 -um scripts.swsh.da --pokemon da-targets --quiet | ||
|
||
X=1 | ||
echo "$X" | ||
|
||
python3 | ||
|
||
bash -c 'echo $X' | ||
echo $X | ||
|
||
export X | ||
bash -c 'echo $X' | ||
|
||
export X=2 | ||
bash -c 'echo $X' | ||
|
||
export -n X | ||
bash -c 'echo $X' | ||
|
||
unset X | ||
echo $X | ||
|
||
X=1 bash -c 'echo $X' | ||
echo $X | ||
|
||
X=1 Y=1 Z= bash -c 'echo $X $Y $Z' | ||
|
||
man test | ||
|
||
which env | ||
|
||
env X=1 bash -c 'echo $X' | ||
env X=1 Y=1 bash -c 'echo $X $Y' | ||
|
||
env bash -c 'echo $USER' | ||
env -i bash -c 'echo $USER' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# [python 3.12 release highlights (beginner - advanced)](https://youtu.be/IV8OZY4194U) | ||
|
||
It's here! with ugly new typing syntax and infinitely nestable fstrings and one of the funniest changes I've seen in a while -- python 3.12! | ||
|
||
## Interactive examples | ||
|
||
### Python | ||
|
||
```python | ||
import calendar | ||
calendar.January | ||
calendar.February | ||
calendar.March | ||
|
||
hi = 3 | ||
f'hi{f'{hi}'}' | ||
|
||
f'hi{ | ||
3 | ||
}' | ||
|
||
f'hi{ | ||
3 # hi | ||
}' | ||
|
||
Old = int | ||
isinstance(5, Old) | ||
|
||
type Newest = int | ||
isinstance(5, Newest) | ||
Newest.__value__ | ||
|
||
import dis | ||
|
||
def f(): | ||
x = [i * 2 for i in range(5)] | ||
return x | ||
|
||
dis.dis(f) | ||
|
||
'\d' | ||
r'\d' | ||
'\\d' | ||
|
||
it = [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
|
||
import itertools | ||
|
||
for a, b, c in itertools.batched(it, 3): | ||
print(a, b, c) | ||
|
||
for a, b in itertools.batched(it, 2): | ||
print(a, b) | ||
|
||
sys.version_info | ||
|
||
class C: | ||
def __init__(self): | ||
self.x = 1 | ||
def f(self): | ||
x | ||
|
||
C().f() | ||
|
||
import Counter from collections | ||
|
||
from collections import counter | ||
``` | ||
|
||
### Python debugger (pdb) | ||
|
||
``` | ||
$x = 1 | ||
import token | ||
$token = token | ||
$token | ||
y = 1 | ||
c | ||
y | ||
q | ||
``` | ||
|
||
### Bash | ||
|
||
```bash | ||
python3.11 | ||
python3.12 | ||
python3.12 -m pydoc tokenize | ||
|
||
cd pre-commit/ | ||
best-of -n 5 python3.11 t.py $(git ls-files -- '*.py') | ||
best-of -n 5 python3.12 t.py $(git ls-files -- '*.py') | ||
|
||
python3.11 -m tokenize /dev/stdin <<< 'f"hello {world}"' | ||
python3.12 -m tokenize /dev/stdin <<< 'f"hello {world}"' | ||
python3.12 -m tokenize /dev/stdin <<< 'f"{a}({world})"' | ||
|
||
python3.12 -m venv vvv | ||
sudo apt install python3.12-venv | ||
|
||
virtualenv venv -ppython3.12 | ||
./venv/bin/pip freeze --all | ||
./venv/bin/pip install setuptools | ||
./venv/bin/python3 -c 'import distutils' | ||
|
||
. venv/bin/activate | ||
pip install pycodestyle | ||
pycodestyle t4.py | ||
|
||
pip install pyupgrade | ||
cat t4.py | ||
|
||
pyupgrade t4.py | ||
cat t4.py | ||
|
||
cd pyflakes | ||
deactivate | ||
|
||
python3.12 -m unittest discover pyflakes | ||
python3.12 -m unittest discover pyflakes --duration 5 | ||
python3.12 -m unittest discover pyflakes --duration 10 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import sys | ||
import tokenize | ||
|
||
|
||
def main() -> int: | ||
for fname in sys.argv[1:]: | ||
with open(fname) as f: | ||
for _ in tokenize.generate_tokens(f.readline): | ||
pass | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
raise SystemExit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from typing import TypeVar | ||
|
||
T = TypeVar('T') | ||
|
||
|
||
def f(x: T) -> list[T]: | ||
return [x] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import TypeVar | ||
|
||
Z = TypeVar('Z', bound=int) | ||
|
||
|
||
def f[T: C, U, V](x: T) -> list[T]: | ||
return [x] | ||
|
||
|
||
async g[T](): ... | ||
|
||
class D[T]: pass | ||
|
||
class C: pass | ||
|
||
Old = int | ||
|
||
from typing import TypeAlias | ||
|
||
Newer: TypeAlias = "Foo" | ||
|
||
type Newest = int | ||
|
||
type NewestWithGeneric[T: int] = list[T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from typing import Any | ||
|
||
|
||
def f(**kwargs: dict[str, Any]): pass | ||
|
||
|
||
# not ok f(x=1, y=2) | ||
# ok f(x={}, y={}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from typing import TypedDict, Unpack | ||
|
||
|
||
class D(TypedDict): | ||
x: int | ||
y: str | ||
|
||
|
||
def f(**kwargs: Unpack[D]): pass | ||
|
||
|
||
f(x=1, y='foo') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
class C: | ||
def frob(self): | ||
print('default') | ||
|
||
def do_work(self): | ||
self.frob() | ||
|
||
|
||
class D(C): | ||
def frob(self): | ||
print('something else') | ||
|
||
|
||
D().do_work() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import override | ||
|
||
|
||
class C: | ||
def new_frob(self): | ||
print('default') | ||
|
||
def do_work(self): | ||
self.new_frob() | ||
|
||
|
||
class D(C): | ||
@override | ||
def frob(self): | ||
print('something else') | ||
|
||
|
||
D().do_work() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = '\d' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters