1
0
Fork 0
mirror of https://github.com/Brandon-Rozek/website.git synced 2025-04-07 22:55:23 +00:00

Merge branch 'master' of github.com:Brandon-Rozek/website

This commit is contained in:
Brandon Rozek 2020-04-14 08:41:18 -04:00
commit a900bbaf04
7 changed files with 296 additions and 0 deletions

View file

@ -0,0 +1,40 @@
---
title: "Download Changes"
date: 2020-04-12T15:28:31-04:00
draft: false
tags: []
---
When testing daily ISO images, it is useful to only download the parts of the ISO that has changed since the previous days. That way we can preserve time and bandwidth.
## Rsync method
This approach requires server-side support, and a lot of flags specified.
```bash
rsync --times \
--compress --partial \
--progress --stats \
--human-readable \
--human-readable \
rsync://cdimage.ubuntu.com/cdimage/kubuntu/daily-live/20200412/focal-desktop-amd64.iso \
kubuntu-focal-desktop-amd64.iso
```
| Flag | Description |
| ------------------ | ------------------------------------------------------------ |
| `--times` | Transfer modification times along with the files. |
| `--compress` | Compress the file data during transit. |
| `--partial` | Keep partial downloads if interrupted. |
| `--progress` | Print information showing the progress of the /transfer. |
| `--stats` | Print a set of statistics on the file transfer. |
| `--human-readable` | Output numbers in a more human readable format, can use up to 3 times. |
## Zsync method
This approach does not involve adding a bunch of flags, but it does require the provider to have a `.zsync` file on their server and for the user to have the `zync` package installed. This package typically isn't installed by default on most systems.
```bash
zsync http://cdimage.ubuntu.com/kubuntu/daily-live/20200412/focal-desktop-amd64.iso.zsync
```

98
content/blog/gpgkeygen.md Normal file
View file

@ -0,0 +1,98 @@
---
title: "GPG Keygen"
date: 2020-04-11T19:35:05-04:00
draft: false
tags: ["gpg"]
---
GPG keys have a variety of different uses from sending encrypted emails to verifying git commits. Here I'll show how easy it is to create a public/private key-pair. Assuming you have the `gpg` client installed.
Type the following command
```bash
gpg --full-gen-key
```
This will then show
```
gpg (GnuPG) 2.2.12; Copyright (C) 2018 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
```
I selected the default option.
```
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096
Requested keysize is 4096 bits
```
I went for the highest available option.
```
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 1y
```
It's highly recommended that you set an expiration date. I usually set it for around 1-3 years.
```
Key expires at Mon 11 Apr 2021 06:42:01 PM EDT
Is this correct? (y/N) y
```
Quick sanity check.
```
GnuPG needs to construct a user ID to identify your key.
Real name: Brandon Rozek
Email address:
Comment: Git
```
All the fields are optional. Fill them in as you wish.
```
You selected this USER-ID:
"Brandon Rozek (Git)"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
```
More sanity checks.
```
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
```
Do as it says, start going crazy.
```
gpg: key IFMWDHXYSKTICHSE marked as ultimately trusted
public and secret key created and signed.
pub rsa4096 2020-04-11 [SC] [expires: 2021-04-11]
FDMGHVYEIWPDKVT83ICUZOEKSLFIVYQALKZMNTYR
uid Brandon Rozek (Git)
sub rsa4096 2020-04-11 [E] [expires: 2021-04-11]
```
Congratulations, you now have a GPG key set.

View file

@ -0,0 +1,31 @@
---
title: "Iteratively Read CSV"
date: 2020-04-11T21:34:33-04:00
draft: false
tags: ["python"]
---
If you want to analyze a CSV dataset that is larger than the space available in RAM, then you can iteratively process each observation and store/calculate only what you need. There is a way to do this in standard Python as well as the popular library Pandas.
## Standard Library
```python
import csv
with open('/path/to/data.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimeter=',')
for row in reader:
for column in row:
do_something()
```
## Pandas
Pandas is slightly different in where you specify a `chunksize` which is the number of rows per chunk and you get a pandas dataframe with that many rows
```python
import pandas as pd
chunksize = 100
for chunk in pd.read_csv('/path/to/data.csv', chunksize=chunksize):
do_something(chunk)
```

View file

@ -0,0 +1,31 @@
---
title: "Pip Editable"
date: 2020-04-11T20:38:33-04:00
draft: false
tags: ["python"]
---
I've found it to be incredibly helpful to emulate having a library installed on my system rather than depending on my local directory path to pick up my file edits. To do this in a python project, we need to add the `--editable` flag to a pip install.
First uninstall whatever version of your `library` you have.
```bash
pip uninstall library
```
Then in your folder with the `setup.py` run the following command
```bash
pip install --editable .
```
This will then create a symlink from your site-packages directory to the directory in which your code lives.
Once you're ready to install it formally,
```bash
pip uninstall library
pip install .
```
Distribute it,
```bash
pip wheel .
```

42
content/blog/pyfutures.md Normal file
View file

@ -0,0 +1,42 @@
---
title: "Quick Python: Concurrent Futures"
date: 2020-04-11T20:40:28-04:00
draft: false
tags: ["python", "concurrency"]
---
Another way to perform concurrency in python is to use the `concurrent.futures` module.
```python
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
def add(x, y):
return x + y
with ThreadPoolExecutor(max_workers=4) as executor:
future = executor.submit(add, 1, 2)
result = future.result(timeout=30) # unit: seconds
```
If `max_workers=None` then it will default to the number of processors on the machine multiplied by 5.
If `timeout=None` then there is no time limit applied.
You can also apply a function to a list or iterables
```python
def double(x):
return 2 * x
with ThreadPoolExecutor() as executor:
future = executor.map(function_handle, [1, 2, 3])
result = future.result()
```
Instead of threads, it is also possible to spawn processes to side-step the global interpreter lock. The documentation warns that only picklable objects can be executed and returned though.
```python
def add(x, y):
return x + y
with ProcessPoolExecutor() as executor:
future = executor.submit(add, 1, 2)
result = future.result()
```

View file

@ -4,6 +4,7 @@ date: 2020-02-21T22:42:55-05:00
draft: false
tags: [ "python" ]
---
**Deprecated in favor of [pip install editable](https://brandonrozek.com/blog/pipeditable)**
I've found it to be incredibly helpful to emulate having a library installed on my system rather than depending on my local directory path to pick up my file edits. To do this in a python project where you've defined a `setup.py`, you can specify the command `develop`.

View file

@ -0,0 +1,53 @@
---
title: "Signing Commits"
date: 2020-04-11T19:59:41-04:00
draft: false
tags: ["git", "gpg"]
---
Git and their various hosting platforms support commit signing as an additional step of verification. There seems to be an active debate on whether it should be used regularly, though I'll describe it on here in case you want to set it up.
You'll need to have a [GPG key already created](https://brandonrozek.com/blog/gpgkeygen).
First locate the key you want to sign with
```bash
gpg --list-secret-keys --keyid-format SHORT
```
This will output something like
```
/home/user/.gnupg/pubring.kbx
------------------------------
sec rsa4096/8294756F 2020-04-11 [SC] [expires: 2021-04-11]
KDIAUBEUX837DIU79YHDKAPOEMNCD7123FDAPOI
uid [ultimate] Brandon Rozek (Git)
ssb rsa4096/9582109R 2020-04-11 [E] [expires: 2021-04-11]
```
Copy the string starting with "KDI..". This will be your *fingerprint*.
Now tell git the key you want to sign with
```bash
git config --global user.signingkey $FINGERPRINT
```
To sign a commit, add a `-S` flag
```bash
git commit -S -m "Initial Commit"
```
To always sign your commits
```bash
git config --global commit.gpgsign true
```
Remember to add your public key to Github, Gitlab, etc. You can get it by
```bash
gpg --armor --export $FINGERPRINT
```