mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-22 00:06:29 -05:00
New Posts
This commit is contained in:
parent
a3ed2efc3b
commit
42fd45d2ba
4 changed files with 148 additions and 0 deletions
33
content/blog/exportpydecorator.md
Normal file
33
content/blog/exportpydecorator.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
title: "Quick Python: Export Decorator"
|
||||
date: 2020-06-14T22:15:38-04:00
|
||||
draft: false
|
||||
tags: []
|
||||
---
|
||||
|
||||
A great [StackOverflow post](https://stackoverflow.com/a/35710527) by [Aaron Hall](https://stackoverflow.com/users/541136/aaron-hall) that shows how you can create an `export` decorator in order to not have to specify all the names you want to expose via [`__all__`](https://brandonrozek.com/blog/pythonall/).
|
||||
|
||||
The Decorator:
|
||||
|
||||
```python
|
||||
import sys
|
||||
|
||||
def export(fn):
|
||||
mod = sys.modules[fn.__module__]
|
||||
if hasattr(mod, '__all__'):
|
||||
mod.__all__.append(fn.__name__)
|
||||
else:
|
||||
mod.__all__ = [fn.__name__]
|
||||
return fn
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
```python
|
||||
__all__ = []
|
||||
|
||||
@export # otherwise __all__ = ['test']
|
||||
def test():
|
||||
print("test")
|
||||
```
|
||||
|
32
content/blog/extract.md
Normal file
32
content/blog/extract.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
title: "Extract All the Things"
|
||||
date: 2020-06-14T22:23:37-04:00
|
||||
draft: false
|
||||
tags: []
|
||||
---
|
||||
|
||||
[Sandra Henry-Stocker](https://www.networkworld.com/author/Sandra-Henry_Stocker/) from Network World wrote a [great post](https://www.networkworld.com/article/3244007/extracting-from-compressed-files-on-linux.html) on how to standardize extracting files on Linux. It's a shell script that works so well, that I placed it in my [`~/.local/bin` directory](https://brandonrozek.com/blog/customexec/) in order to call upon it at any time. Here's part of it, check out the post for more.
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
if [ -f $1 ] ; then
|
||||
case $1 in
|
||||
*.tar.bz2) tar xjf $1 ;;
|
||||
*.tar.gz) tar xzf $1 ;;
|
||||
*.tar.xz) tar zxvf $1 ;;
|
||||
*.bz2) bunzip2 $1 ;;
|
||||
*.rar) rar x $1 ;;
|
||||
*.gz) gunzip $1 ;;
|
||||
*.tar) tar xf $1 ;;
|
||||
*.tbz2) tar xjf $1 ;;
|
||||
*.tgz) tar xzf $1 ;;
|
||||
*.xz) xz -d $1 ;;
|
||||
*.zip) unzip $1 ;;
|
||||
*.Z) uncompress $1;;
|
||||
*) echo "contents of '$1' cannot be extracted" ;;
|
||||
esac
|
||||
else
|
||||
echo "'$1' is not recognized as a compressed file"
|
||||
fi
|
||||
```
|
||||
|
33
content/blog/gpgagentasssh.md
Normal file
33
content/blog/gpgagentasssh.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
title: "GPG Agent as SSH Agent"
|
||||
date: 2020-06-14T22:33:01-04:00
|
||||
draft: false
|
||||
tags: []
|
||||
---
|
||||
|
||||
GPG Agent has the ability to act as a SSH Agent. This allows the use of Authentication keys on Smartcards to be used with SSH as well.
|
||||
|
||||
First we need to enable SSH support in GPG Agent,
|
||||
|
||||
```bash
|
||||
echo "enable-ssh-support" >> ~/.gnupg/gpg-agent.conf
|
||||
```
|
||||
|
||||
Then we need to specify an environmental variable for the SSH Daemon to use GPG Agent
|
||||
|
||||
```bash
|
||||
echo "export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)" >> ~/.bashrc
|
||||
```
|
||||
|
||||
If you want it to be active immediately, then source the bashrc,
|
||||
|
||||
```bash
|
||||
source ~/.bashrc
|
||||
```
|
||||
|
||||
If you have a smartcard plugged in, then you should be able to see it via the GPG agent
|
||||
|
||||
```bash
|
||||
ssh-add -l
|
||||
```
|
||||
|
50
content/blog/tokindle.md
Normal file
50
content/blog/tokindle.md
Normal file
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
title: "PDF To Kindle"
|
||||
date: 2020-06-14T21:54:21-04:00
|
||||
draft: false
|
||||
tags: []
|
||||
---
|
||||
|
||||
This post will outline a process I take in order to get content from a website onto my Kindle.
|
||||
|
||||
## Suggested Software
|
||||
|
||||
- To save a webpage as a PDF, we will use [WeasyPrint](https://weasyprint.org/).
|
||||
- To convert the PDF into a more Kindle readable format, including converting math type properly, we're going to use [k2pdfopt](https://www.willus.com/k2pdfopt/).
|
||||
- Finally we're going to use [Calibre](https://calibre-ebook.com/) to copy metadata and convert to an ebook format.
|
||||
|
||||
```bash
|
||||
sudo apt install weasyprint k2pdfopt calibre
|
||||
```
|
||||
|
||||
## Process
|
||||
|
||||
Now I'll show how we can take the [Noise Protocol specification](http://noiseprotocol.org/noise.html) and send it to the Kindle.
|
||||
|
||||
First let's download the page as a PDF
|
||||
|
||||
```bash
|
||||
weasyprint https://noiseprotocol.org/noise.html noise.pdf
|
||||
```
|
||||
|
||||
Then let's use `k2pdfopt` to convert the PDF to a more Kindle friendly format,
|
||||
|
||||
```bash
|
||||
k2pdfopt noise.pdf -ui- -x
|
||||
```
|
||||
|
||||
This will produce the file `noise_k2opt.pdf`, but sadly without the metadata. We can copy that over,
|
||||
|
||||
```bash
|
||||
ebook-meta noise.pdf --to-opf temp.opf && \
|
||||
ebook-meta noise_k2opt.pdf --from-opf temp.opf && \
|
||||
rm temp.opf
|
||||
```
|
||||
|
||||
Finally we can convert it to a Kindle friendly file format.
|
||||
|
||||
```bash
|
||||
ebook-convert noise_k2opt.pdf noise.azw3
|
||||
```
|
||||
|
||||
This will give us `noise.azw3` which we can then transfer over to the Kindle.
|
Loading…
Reference in a new issue