Skip to content

Instantly share code, notes, and snippets.

@brentmaxwell
brentmaxwell / array_size.ino
Created December 1, 2022 16:43
quick header array size macro for Arduino
#define ARRAY_SIZE(array) ((sizeof(array)) / (sizeof(array[0])))
@brentmaxwell
brentmaxwell / csv2sc.py
Created February 2, 2022 20:11
Convert csv to sc format
#!/usr/bin/python
import sys
import string
if len(sys.argv) < 2:
print "Usage: %s infile [outfile] [delimiter_char]" % sys.argv[0]
sys.exit(1)
filename_in = sys.argv[1]
@brentmaxwell
brentmaxwell / EmptyGuid.sql
Created January 20, 2022 20:42 — forked from jonsagara/EmptyGuid.sql
Generating Guid.Empty in SQL Server
--
-- 2021-11-24: suggestion from comments:
--
DECLARE @EmptyEmpty UNIQUEIDENTIFIER = CAST(0x0 AS UNIQUEIDENTIFIER)
SELECT @EmptyEmpty
--
-- Original
--
@brentmaxwell
brentmaxwell / public-key
Last active January 19, 2022 16:09
OpenPGP Public Key
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFV1z94BCACsc/WQ3v4OQK2zcTIS1751Pixtlielg8hafGUmu3RPYzB0Qrnu
109TQrfO4Sx+fi9Q4iLzzKbPJ83myaDRCxd0zng6pVbPMSX44fzzgLdQpE7esut6
ptEJtCGPqMoaLuJ5xieG8YmmERJ1lQjk6LWWat7b/wfM7E6NqDBH8YoG5Mb5kDdG
qF55p5/2L07f/7G4M28rLJLBCe4/6q/tjAUzuEVyJO/M0X3cb3bBmySOokHHhfpf
ls5ZgeJjuLAjzPImGDxLDLwBDpcEt4h8XHc65Ir17POV/gu7VSqjn4XuuOVdGed5
Abg0caqgL9u3TzIJur/SkO3fEXMDqDRZ0T0dABEBAAGJAU4EHwEKACEFAlV3IZwX
DIABw1qv3cOYCyUeXa9P0c6JaoQB3tICBwAAIQkQdV2JiVkS1voWIQRI/P0BQDzy
rVskKSR1XYmJWRLW+uo/CACfqYP1Ss2XUywH6BpgxV2HgmzLJllZVQ/QRk5j5XDJ
@brentmaxwell
brentmaxwell / search-all-tables.sql
Created January 19, 2022 16:00
Search all tables in a database
DECLARE @SearchStr nvarchar(100) = 'brent'
DECLARE @SearchSchema nvarchar(100) = 'dbo'
CREATE TABLE #Results (
TableName nvarchar(255),
ColumnName nvarchar(255),
ColumnValue nvarchar(MAX))
SET NOCOUNT ON
DECLARE @TableName nvarchar(255) = '',
@ColumnName nvarchar(255),
@brentmaxwell
brentmaxwell / Overlapping Dates
Created September 14, 2021 15:26
Overlapping Dates formula
(StartA <= EndB) and (EndA >= StartB)
Proof:
Let ConditionA Mean that DateRange A Completely After DateRange B
_ |---- DateRange A ------|
|---Date Range B -----| _
(True if StartA > EndB)
Let ConditionB Mean that DateRange A is Completely Before DateRange B
@brentmaxwell
brentmaxwell / PEMtoRSAParams
Created November 19, 2015 12:29
Convert RSA keys from PEM to RSA Parameters
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Security.Cryptography;
using System.Text;
internal class RSA {
private const string _begin = "-----BEGIN ";
@brentmaxwell
brentmaxwell / ObjectDumper.cs
Created September 23, 2015 14:11
C# Object Dumper
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
public class ObjectDumper
{
private int _level;
private readonly int _indentSize;
@brentmaxwell
brentmaxwell / myusbgadget
Last active June 1, 2020 14:39 — forked from geekman/myusbgadget
Pi Zero multiple USB gadgets minimal example
#!/bin/bash -e
modprobe libcomposite
cd /sys/kernel/config/usb_gadget/
mkdir g && cd g
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0

Better SSH Authorized Keys Management

A seemingly common problem that people encounter is how to handle all of your users authorized_keys file.

People struggle over management, ensuring that users only have specific keys in the authorized_keys file or even a method for expiring keys. A centralized key management system could help provide all of this functionality with a little scripting.

One piece of functionality overlooked in OpenSSH is the AuthorizedKeysCommand configuration keyword. This configuration allows you to specify a command that will run during login to retrieve a users public key file from a remote source and perform validation just as if the authorized_keys file was local.

Here is an example directory structure for a set of users with SSH public keys that can be shared out via a web server: