Move blog directory.

This commit is contained in:
jimmy committed 2024-01-27 02:54:18 +00:00
1 parent aabe7052d8
commit 7bf962afcd
7 files changed
+4 -4

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
---
title: "Bash has a builtin network client"
author: "James Pace"
date: "2024/01/12"
---
I've been playing with using Rust on microcontrollers that have
ethernet support with the microcontroller using UDP to communicate
with the rest of the world.
When testing the code I wrote on the microcontroller, I searched for how to send
udp packets from the command line (expecting to find the right incantation for
netcat, which I've used in the past but don't remember the options for.)
What I actually found was more interesting.
Apparently, bash has builtin "pseudo devices" that allow you to read and write
from a TCP or UDP port like you were reading or writing from a file.
For example, to send the string "hello" to my microcontroller at 192.168.1.109 on
port 1337, I used the command
```bash
echo "hello" > /dev/udp/192.168.1.109/1337
```
Bash supports the same thing for TCP connections as well using similar syntax.
That is a lot easier to remember than netcat, and I'll definitely use
it again.
+135
View File
@@ -0,0 +1,135 @@
---
title: "How I Deploy Static Sites With Nginx."
author: "James Pace"
date: "2024/01/14"
---
This article will describe how I built and deployed limbo.jpace121.net, including
the initial setup I had to do when setting the site up.
## Background
I decided I wanted to start self hosting certain web applications a few years ago for educational
purposes.
I live in an apartment and have internet provided through the complex, so I don't have
the ability to negotiate for a static IP from my internet provider.
What I do instead is run an Amazon Lightsail instance which runs NGINX and Wireguard.
For non-static sites, I use NGINX to proxy requests from the instance to the actual
services I run locally, which are all connected via Wireguard with the Ligthsail instance.
For static sites, proxying down into my home internet it a little silly, so I put any files
I need to host directly on the Lightsail instance and serve them from there.
I currently use Google Domains for hosting my domain and DNS.
(Though it sounds like that'll be transferred to Squarespace at some point in the near future...)
I get free HTTPS certs from LetsEncrypt.
## Step 1: Setting up DNS records.
The first step was to setup an A record on Google Domains for `limbo` pointing
to the IP of my Lightsail instance.
I do this first so the system has time to propagate the change around before we
need the domain name to resolve in the following steps.
## Step 2: Set up NGINX.
To set up nginx, I ssh'd into my Lightsail instance using my admin account.
Once I logged in, I cd'd to `/etc/nginx/sites-available` and copied one of the files that
was already there to `limbo.jpace121.net`.
I modified the file so it had the following the contents
```
server {
listen 80;
server_name limbo.jpace121.net;
location /.well-known {
alias /var/www/limbo.jpace121.net/.well-known;
}
location / {
return 301 https://limbo.jpace121.net$request_uri;
}
}
server {
listen 443;
server_name limbo.jpace121.net;
ssl_certificate /etc/letsencrypt/live/limbo.jpace121.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/limbo.jpace121.net/privkey.pem;
root /var/www/limbo.jpace121.net/;
location / {
try_files $uri /index.html;
}
location /.well-known {
alias /var/www/limbo.jpace121.net/.well-known;
}
}
```
and the commented out (using the `#` symbol) the second server block for now, since we haven't gotten
certs quite yet.
I then created a symbolic link between the new config file in `/etc/nginx/sites-enabled` which is where nginx
actually looks for server files to load (on Debian as configured by default) using the following command:
```
sudo ln -s /etc/nginx/sites-available/limbo.jpace121.net /etc/nginx/sites-enabled/limbo.jpace121.net
```
I then restarted the nginx service (using `sudo systemctl restart nginx`) so the new config would take effect.
The config file above is setup to host files from `/var/www/limbo.jpace121.net`, so we need to create that directory
(as root) and then change it's permissions so we can upload files to it as the admin user.
```
sudo mkdir /var/www/limbo.jpace121.net
sudo chown -R admin:admin /var/www.jpace121.net
```
# Step 3: Using certbot to get a cert from LetsEncrypt.
I use LetsEncrypt and certbot so I can ue https for all my self hosted sites, and so already have
it installed on my Lightsail instance.
To add my new site, I ran:
```
sudo certbot certonly --webroot -w /var/www/limbo.jpace121.net -d limbo.jpace121.net
```
Once the command finishes, we should have certs where they are being looked for in our https server configuration,
so we can open `/etc/nginx/sites-available/limbo.jpace121.net`, uncomment out the second server block, and then
restart nginx.
## Step 4: Build and Deploy the site
`limbo.jpace121.net` is written in TypeScript and uses `vite` and `yarn` for its build tool and package
manager respectively.
As configured by default, running `yarn build` from the package will use vite to create a production build
of the website, which is placed into the `dist` directory of the package.
Once we've built the package, to deploy it on the server we scp the files in dist to the `/var/www/limbo.jpace.net`
directory on the server. (I.E. `scp -r dist/. admin@vpn.jpace121.net:/var/www/limbo.jpace121.net/.`).
Once that's complete, we should be abel to load the webpage locally and see that the contents have changed.
Further updates to the site should only require completing Step 3.
To make that easier I've added the two commands required (one to build the project, and one
to deploy it) to my justfile for my web project so I can call a single command and have the
right thing happen.
## Conclusion
Once the initial set up is done, actually deploying the site is fairly easy.
A lot of times for static sites, hobbyists use something like Github Pages because it is
both easy and free.
I don't think the process is that much harder with my method, and I appreciate the extra control
I have on what gets published when.
+36
View File
@@ -0,0 +1,36 @@
---
title: "Quarto: Modifying Colors of the NavBar"
author: "James Pace"
date: "2024/01/08"
---
[Quarto](https://quarto.org/) is a static site generator that generates websites (like
this blog) from markdown files.
Quarto sites by default use the Bootstrap component library and can be themed by
overriding Bootstrap SASS variables as described
[here](https://quarto.org/docs/output-formats/html-themes.html#navigation).
One of the things I found confusing when trying to theme this blog was what SASS
variable to override to change the color of the NavBar on top of every page.
I kept trying to change the normal Boootstrap variables, but it didn't seem to
work.
For the changing the color of the NavBar, instead of the Bootstrap variables you should use the
ones described [here](https://quarto.org/docs/output-formats/html-themes.html#navigation).
More specifically, for this site, I'm using the following .scss file.
```yaml
/*-- scss:defaults --*/
$black: #000;
$neon: #39ff14;
$white: #FFFF;
$blue: #0244b8;
$link-color: $black;
$navbar-bg: $black;
$navbar-fg: $white;
$navbar-hl: $neon;
```
+39
View File
@@ -0,0 +1,39 @@
---
title: "Just: A quick review"
author: "James Pace"
date: "2024/01/10"
---
[Just](https://just.systems/man/en/) is a command runner that operates kind of like make.
Just lets you define tasks in a simple, human-readable file called a Justfile.
To run a task, simply call `just <task_name>`. Just will automatically find the
Justfile in the nearest parent directory and execute the commands defined for that
task.
For example, given the `Justfile`:
```
build:
cargo build
test:
cargo test --features log
```
the command `just test` will call `cargo test --features log` in the current terminal window.
Compared to `make`, `just`:
1. Eliminates the need for manual .PHONY target creation, saving you time and reducing
clutter in Justfiles compared to Makefiles.
2. Can be called below the directory the `Justfile` is in and still find the `Justfile`
in the parent directory.
In my recent development where I was calling wasm written in rust in a
web app, I found `just` particularly useful.
Building the app took multiple commands, one command for compiling the rust part and
a second command to bundle the JavaScript.
Combining things under a single `just` target was nice and lead to quicker
iterations.
+44
View File
@@ -0,0 +1,44 @@
---
title: "Rust: todo! macro"
author: "James Pace"
date: "2024/01/21"
---
One of the features of Rust that I've found really helpful when getting started
on a project is the `todo!` macro.
The `todo!` macro tells the compiler that you know that some section of code
isn't complete yet and that it should compile the rest of it anyway.
An example of where I've used this is when I get started on a project I like protoyping
out the signatures for the primary functions I think I'm going to need before I start
implemententing them.
For example, if I'm working on functions that do math operations on a custom type,
I'll start by thinking about what functions I need and what their signatures are
going to be, type that out, and then fill them in.
With `todo!`, that means I may type out something like:
```rust
struct Point {
pub x: f32,
pub y: f32,
pub z: f32,
}
impl Point {
pub fn add(&self, other: &Point) -> Point {
todo!()
}
pub fn subtract(&self, other: &Point) -> Point {
todo!()
}
}
```
and that compiles, as long as there are not other mistakes.
The reason that's useful is let's say I made a mistake and type `Pint`
instead of `Point` somewhere.
I can build the code, have the compiler point that out, and fix it
before needing to implement everything.
The official documentation about `todo!` can be found
[here](https://doc.rust-lang.org/std/macro.todo.html).