Skip to content

Instantly share code, notes, and snippets.

View zanbaldwin's full-sized avatar
🦀

Zan Baldwin zanbaldwin

🦀
View GitHub Profile
@zanbaldwin
zanbaldwin / README.md
Last active April 22, 2024 13:18
SystemD: Automatic Software Update
  • Install the system-update.service and system-update.timer service files to a directory that SystemD loads service definitions from.
    • The most likely directory on most distros is /etc/systemd/system/ (create this directory if it does not exist).
  • sudo systemctl daemon-reload to tell SystemD to refresh its configuration cache.
  • sudo systemctl enable --now software-update

If SystemD does not know about the software-update service you created, refer to your distros documention about which directories are checked for configuration. Perhaps try /usr/lib/systemd/system/ (not recommended initially)?

@zanbaldwin
zanbaldwin / README.md
Last active January 4, 2024 12:17
Onefetch Git Information on `cd`

Show Git Information when cding into a Git repository

  1. Install onefetch by either:
    • Compiling it from scratch using the Rust compiler, Cargo: with the command cargo install onefetch
    • Downloading a pre-built binary from Onefetch's GitHub releases page (recommended) and placing it in your $PATH (such as /usr/local/bin/onefetch).
  2. Add the snippet listed in onefetch_on_cd.sh to whatever file that gets run whenever you start a new Bash session. This differs per distro but common files include:
    • ~/.bashrc
    • ~/.bash_profile
    • sometimes ~/.bash_aliases?
@zanbaldwin
zanbaldwin / example.rs
Created December 28, 2023 13:10
Why can't I understand async :(
pub fn function_from_external_crate<F, I>(get_more_info: F) -> Vec<Action>
where
F: FnMut(&str) -> I,
I: IntoIterator<Item = String>,
{
todo!()
}
async fn function_in_my_crate(conn: &Pool<Postgres>) { // <-- Currently inside an async function so
// can't create a runtime within a runtime?
@zanbaldwin
zanbaldwin / Makefile
Last active June 8, 2023 11:02
Skeleton Makefile I reuse for Symfony projects.
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.ONESHELL:
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
ifeq ($(origin .RECIPEPREFIX), undefined)
$(error This Make does not support .RECIPEPREFIX; Please use GNU Make 4.0 or later)
endif
# The editor config for IDEs automatically converts tabs (default Make config) to spaces. Use a printable character instead of whitespace.
@zanbaldwin
zanbaldwin / fizzbuzz.rs
Created February 16, 2022 12:35
I did some cool Rust problems and need to store them somewhere.
const MAX: u32 = 1_000_000;
fn main() {
fizzbuzz();
}
struct Definition<'a> {
divisor: u16,
text: &'a str,
}
@zanbaldwin
zanbaldwin / phpenv.sh
Last active February 13, 2022 13:02
Quick and dirty script to pull a specific version of the PHP Docker image, much less hassle than having multiple PHP versions installed locally. You won't be able to install any extensions though because you won't be root (remove the --user flag if you're okay with creating files in your working tree belonging to root).
#!/bin/sh
if [ $# -eq 0 ]; then
echo 2>&1 "You must specify the PHP version as the first argument."
exit 1
fi
###################################################################################
### ENVIRONMENT HELPER ###
### --------------------------------------------------------------------------- ###
@zanbaldwin
zanbaldwin / DoctrineArgumentResolver.php
Last active February 11, 2022 16:48
This will be useful at some point.
<?php declare(strict_types=1);
namespace App\Request\ArgumentResolver;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@zanbaldwin
zanbaldwin / UnicodeCharacter.php
Last active February 16, 2022 13:03
I got bored and played with the UTF-8 standard.
<?php declare(strict_types=1);
class UnicodeCharacter
{
private string $binary;
/**********************************\
| CONSTRUCTORS AND FACTORY METHODS |
\**********************************/
@zanbaldwin
zanbaldwin / Makefile
Last active February 8, 2022 02:11
Drop this in "/etc/nginx/conf.d", or use nginx-proxy-manager Docker image instead.
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.ONESHELL:
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
ifeq ($(origin .RECIPEPREFIX), undefined)
$(error This Make does not support .RECIPEPREFIX; Please use GNU Make 4.0 or later)
endif
.RECIPEPREFIX = >
@zanbaldwin
zanbaldwin / OpenApiLoader.php
Last active January 28, 2022 18:15
(Extremely) Simple OpenAPI Specification Route Loader for Symfony
<?php declare(strict_types=1);
namespace App\Routing\Loader;
use League\JsonReference\Dereferencer;
use League\JsonReference\Loader\ArrayLoader;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Config\Loader\FileLoader;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Route;