Skip to content

Instantly share code, notes, and snippets.

View davenicoll's full-sized avatar
🖖

Dave Nicoll davenicoll

🖖
View GitHub Profile
@davenicoll
davenicoll / code.sh
Created April 9, 2021 15:47 — forked from harperreed/code.sh
Use VSCode (server) in a google cloud shell. or a chromebook.
./bin/code/bin/code-server --auth none --port 8080
@davenicoll
davenicoll / random-password.sh
Last active February 4, 2021 20:53
Create a random password in bash
random_password()
{
LENGTH=32; if [[ -n "$1" ]]; then LENGTH=$1; fi
</dev/urandom tr -dc '0-9-a-z-A-Z@#()-=_+[]{},.' | head -c"$LENGTH"; echo ""
}
PASSWORD=$(random_password 20)
@davenicoll
davenicoll / get-keyvault-secrets.ps1
Last active January 29, 2021 22:12
Extract all secrets from keyvault
$IGNORE_LIST = @('not-in-use') #List of keyvaults to ignore, i.e. 'audit-tracked-secrets','nothing-to-see-here'
Write-Output "Getting subscriptions..."
$SUBSCRIPTIONS = Get-AzSubscription | Where-Object {$_.State -eq "Enabled"}
ForEach($SUBSCRIPTION in $SUBSCRIPTIONS)
{
Write-Output "✨ $($SUBSCRIPTION.Name) ($($SUBSCRIPTION.Id))"
Set-AzContext -Subscription $($SUBSCRIPTION.Id) | Out-Null
@davenicoll
davenicoll / gmail-auto-archive.js
Created January 17, 2021 13:48
Autoarchive for GMail
function gmailAutoarchive() {
var holdDays = 8;
var maxDate = new Date();
maxDate.setDate(maxDate.getDate()-holdDays);
var threads = GmailApp.getInboxThreads(0,500).filter(function(thread) {
// Return only old threads and without stars
return (thread.getLastMessageDate() < maxDate && thread.hasStarredMessages() == false);
});
@davenicoll
davenicoll / update-synology-plex.sh
Last active May 6, 2021 00:21
Automatically update plex on synology NAS
#!/bin/bash
mkdir -p /tmp/plex/ > /dev/null 2>&1
rm -rf /tmp/plex/* > /dev/null 2>&1
token=$(cat /volume1/Plex/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml | grep -oP 'PlexOnlineToken="\K[^"]+')
url=$(echo "https://plex.tv/api/downloads/5.json?channel=plexpass&X-Plex-Token=$token")
jq=$(curl -s ${url})
newversion=$(echo $jq | jq -r .nas.Synology.version)
echo New Ver: $newversion
curversion=$(synopkg version "Plex Media Server")
echo Cur Ver: $curversion
#!/bin/bash
if [[ -z "$SSH_CLIENT" ]]; then SSH_CLIENT="127.0.0.1"; fi
TEXT="A user successfully logged on to \`$USER@$HOSTNAME\` ($(hostname -I | awk '{print $1}')) from \`$(echo $SSH_CLIENT | awk '{print $1}')\`.<br/>Please review this activity."
MESSAGE=$( echo ${TEXT} | sed 's/"/\"/g' | sed "s/'/\'/g" )
JSON="{\"title\": \"Unusual user login activity\", \"themeColor\": \"\", \"text\": \"${MESSAGE}\" }"
curl --silent -H "Content-Type: application/json" -d "${JSON}" "https://outlook.office.com/webhook/..." > /dev/null
@davenicoll
davenicoll / settings.json
Last active March 2, 2022 18:30
VSCode settings
{
"telemetry.telemetryLevel": "off",
"editor.guides.bracketPairs": true,
"go.toolsManagement.autoUpdate" : true,
"explorer.compactFolders" : false,
"todo-tree.general.tags" : [
"BUG",
"HACK",
"FIXME",
"TODO",