Skip to content

Instantly share code, notes, and snippets.

@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 / openpgp.txt
Created January 14, 2016 01:34
OpenKeychain Linked Identity
This Gist confirms the Linked Identity in my OpenPGP key, and links it to this GitHub account.
Token for proof:
[Verifying my OpenPGP key: openpgp4fpr:48fcfd01403cf2ad5b242924755d89895912d6fa]
@brentmaxwell
brentmaxwell / gist:4e0239b214f589cc3d80824a4bef8f34
Created May 4, 2016 12:53 — forked from davidnunez/gist:1404789
list all installed packages in android adb shell
pm list packages -f
@brentmaxwell
brentmaxwell / GenerateDataDictionary.sql
Created September 9, 2019 16:17
Generate a simple data dictionary for SQL Server; uses the Description extended property.
CREATE PROCEDURE GenerateDataDictionary
@TableName NVARCHAR(MAX)
AS
BEGIN
SELECT
c.name AS ColumnName,
CASE
WHEN c.max_length = -1 THEN dt.name + '(max)'
WHEN dt.name = 'nvarchar' THEN dt.name + '('+CAST(ISNULL(c.max_length,0)/2 AS NVARCHAR)+')'
WHEN dt.name = 'varchar' THEN dt.name + '('+CAST(ISNULL(c.max_length,0) AS nvarchar)+')'
@brentmaxwell
brentmaxwell / ChangeDoubleStraightQuotesToSmartQuotes.vba
Last active November 25, 2019 15:45
Swap smart and straight quotes in Microsoft Word
Sub ChangeDoubleStraightQuotesToSmartQuotes()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = """"
.Replacement.Text = """"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False

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:

@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
@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 / 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 / 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
--