Skip to content

Instantly share code, notes, and snippets.

View webern's full-sized avatar

Matthew James Briggs webern

View GitHub Profile
@webern
webern / file-permissions.txt
Last active November 17, 2020 01:00
File Permissions
https://www.drupal.org/node/2690335
Most files should be 644 or -rw-r--r--
All directories should be 755 or drwxr-xr-x
Files that are intended to be run at the command line should have the executable bit set meaning 755 or -rwxr-xr-x
Public Key: chmod 644
Private Key: chmod 600
@webern
webern / main.rs
Last active July 20, 2020 01:29
Rust struct where user decides who owns the data.
#![forbid(missing_debug_implementations, missing_copy_implementations)]
#![deny(rust_2018_idioms)]
#![deny(clippy::pedantic)]
#![allow(dead_code)]
use std::borrow::Cow;
struct YouDecide<'a> {
s: Cow<'a, str>
}
@webern
webern / main.rs
Created July 20, 2020 02:20
Generalizing a Struct that holds a Cow
#![forbid(missing_debug_implementations, missing_copy_implementations)]
#![deny(rust_2018_idioms)]
#![deny(clippy::pedantic)]
#![allow(dead_code)]
use std::borrow::Cow;
use std::fmt::Debug;
/// A custom type. Clone is required by `Cow`. `Debug` is required by our example so that we can
/// easily print our results. `Copy` is added for completeness since `MyType` has no allocations.
@webern
webern / heredoc.sh
Created August 14, 2020 00:18
I can never remember how to do heredocs
#!/usr/bin/env bash
# heredoc with shell expansion
cat << EOF
The current working directory is: $PWD
You are logged in as: $(whoami)
EOF
# heredoc with shell expansion into a variable
myvar=$(cat << EOF
@webern
webern / git.sh
Last active October 25, 2020 23:47
#!/usr/bin/env bash
# create an annotated tag, the -a indicates that the tag will have a message
git tag –a v1.0.0 –m "This is the 1.0 release."
# same as above, but opens your text editor for the message
git tag –a v1.0.0
2021-04-16T19:49:58.2829250Z ##[section]Starting: Request a runner to run this job
2021-04-16T19:49:58.3336405Z Found online and idle self-hosted runner in current repository that matches the required labels: 'self-hosted , linux , x64'
2021-04-16T19:49:58.4060068Z ##[section]Finishing: Request a runner to run this job
2021-04-16T19:50:03.4876898Z Current runner version: '2.277.1'
2021-04-16T19:50:03.4879705Z Runner name: 'i-03f6a562b9e9aec3e'
2021-04-16T19:50:03.4880215Z Runner group name: 'Default'
2021-04-16T19:50:03.4881048Z Machine name: 'ip-172-31-6-197'
2021-04-16T19:50:03.4883428Z ##[group]GITHUB_TOKEN Permissions
2021-04-16T19:50:03.4884366Z Actions: read
2021-04-16T19:50:03.4884791Z Checks: read
@webern
webern / init_logger.rs
Last active May 21, 2021 23:07
Initializing Rust env_logger with the settings that I like
// colored = "2"
// chrono = "0"
// env_logger = "0"
// log = "0"
use colored::*;
use std::io::Write;
fn init_logger(default_level: LevelFilter) {
// extract the value of RUST_LOG if it exists
@webern
webern / docker-commands.md
Last active March 8, 2023 21:35
Nuke Docker from Orbit

You can double-check the docker data directory with this, but I considered too dangerous to include in the rm -rf command.

docker info | grep 'Docker Root Dir' | grep -oE '/.*'

Nuke Docker from Orbit

@webern
webern / custom-serde.rs
Created October 26, 2021 21:54 — forked from MightyPork/custom-serde.rs
example of custom serialize and deserialize in serde
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer, de::Visitor, de::MapAccess, Deserialize, Deserializer};
use std::fmt;
#[derive(Debug)]
struct Custom(String, u32);
impl Serialize for Custom {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where

Copy from another host

SOURCE_HOST=somehost
SOURCE_HOST_USERNAME=mjb
SOURCE_FILEPATH=/some/path
DESTINATION_FILEPATH=/local/path
scp $SOURCE_HOST_USERNAME@$SOURCE_HOST:$SOURCE_FILEPATH $LOCAL_FILEPATH