Skip to content

Instantly share code, notes, and snippets.

View deangrant's full-sized avatar

Dean Grant deangrant

View GitHub Profile
@deangrant
deangrant / keycloak_export_realm_and_users.sh
Created July 25, 2022 15:49
A code block to bind a temporary folder to the keycloak container and export realm and users.
# Define the volume for when the container is created, this will be used to export the realm and users
volumes:
- ./realms/:/tmp/
# Run the following command from the container shell to export the realm {{ realm }} and include users.
$ /opt/keycloak/bin/kc.sh export --dir /tmp --realm {{{ realm }} --users realm_file
@deangrant
deangrant / install_certbot_wsl.sh
Created June 23, 2022 04:05
Install Certbot on Windows Subsystem for Linux (WSL)
sudo apt update
sudo apt install python3 python3-venv libaugeas0
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
sudo /opt/certbot/bin/pip install certbot
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
@deangrant
deangrant / certbot_pfx.sh
Last active July 26, 2022 15:11
Generate a PFX cert with certbot and openssl
DOMAIN={{ domain }}
certbot -d "${DOMAIN}" --manual --preferred-challenges dns certonly
openssl pkcs12 -export -out "${DOMAIN}.pfx" -inkey "/etc/letsencrypt/live/${DOMAIN}/privkey.pem" -in "/etc/letsencrypt/live/${DOMAIN}/fullchain.pem"
@deangrant
deangrant / lookup_timezone.py
Last active June 3, 2022 13:18
Returns the time zone for a specified location based on latitude and longitude
# ~./lookup_timezone.py
# https://github.com/mattbornski/tzwhere
from tzwhere import tzwhere
def lookup_timezone(latitude, longitude):
tz = tzwhere.tzwhere(forceTZ=True)
return (tz.tzNameAt(latitude, longitude, forceTZ=True))
@deangrant
deangrant / azure_omsagent_proxyconf.sh
Last active May 27, 2022 09:18
azure: configures the osm agent to use a http proxy server.
# https://github.com/microsoft/OMS-Agent-for-Linux/blob/master/docs/OMS-Agent-for-Linux.md#configuring-the-agent-for-use-with-an-http-proxy-server
# Specify (uncomment) the HTTP proxy server, using proxy server and port, or optionally include username and password for authentication.
# proxyconf="https://{{ hostname }}:{{ port }}"
# proxyconf="https://{{ username }}:{{ password }}@{{ hostname }}:{{ port }}"
sudo echo $proxyconf >>/etc/opt/microsoft/omsagent/proxy.conf
sudo chown omsagent:omiusers /etc/opt/microsoft/omsagent/proxy.conf
sudo chmod 600 /etc/opt/microsoft/omsagent/proxy.conf
sudo /opt/microsoft/omsagent/bin/service_control restart
@deangrant
deangrant / on_change_date.js
Created May 26, 2022 07:27
Functions to change the start and end date if exceeding limit by number of days
var date_limit = {{ number_of_days }}
$("#startDate").on("change", function(e) {
var maxDate = new Date($(this).val())
var endDate = new Date($('#endDate').val())
var maxDate = maxDate.setDate(maxDate.getDate() + date_limit)
if (endDate > maxDate){
$('#endDate').val(new Date(maxDate).toJSON().slice(0,10));
}
@deangrant
deangrant / .bashrc
Last active May 26, 2022 07:00
Sample terminal session and ssh configuration to be used in combination with Pomerium and Microsoft Azure
# ~/.bashrc
# exported variable for SSH jump host
export SSH_JUMPHOST='{{ hostname }}'
# Creates a short lived SSH certificate signed by AAD.
# Requires public key file creating using the command - ssh-keygen -t rsa -b 4096
alias az_ssh_cert='az ssh cert --public-key-file ~/.ssh/id_rsa.pub --file ~/.ssh/id_rsa-aadcert.pub'
# Connects to the target host first by making a connection to the jump host and then establishing
@deangrant
deangrant / localized_time_to_epoch.py
Last active May 24, 2022 09:26
A python function to convert a localized timestamp to epoch / unix time
from dateutil import parser
from pytz import timezone
from datetime import datetime
import time
def localized_time_to_epoch(timestamp, time_zone):
strptime = "%Y-%m-%d %H:%M:%S"
timestamp = parser.parse(timestamp)
localize = timezone(timezone).localize(datetime.strptime(str(timestamp), strptime))
@deangrant
deangrant / setResourceElementMimeType.js
Created September 14, 2018 06:24
setResourceElementMimeType.js
// Retrieves the resource element as a mime attachment from the specified input parameter (resourceElement).
var content = resourceElement.getContentAsMimeAttachment();
System.debug('The resource element ' + resourceElement.name + ' has been returned with the mime type ' + content.mimeType)
content.mimeType = mime;
// Sets the mime attachement to the type specifed from the input parameter (mime).
resourceElement.setContentFromMimeAttachment(content);
System.log('The resource element ' + resourceElement.name + ' mime type type has been set to ' + mime)]]
@deangrant
deangrant / setResourceElementMimeType.js
Last active September 13, 2017 15:30
com.deangrant.library.vro/setResourceElementMimeType
// Retrieves the resource element as a mime attachment from the specified input parameter (resourceElement).
var content = resourceElement.getContentAsMimeAttachment();
System.debug('The resource element ' + resourceElement.name + ' has been returned with the mime type ' + content.mimeType)
content.mimeType = mime;
// Sets the mime attachement to the type specifed from the input parameter (mime).
resourceElement.setContentFromMimeAttachment(content);
System.log('The resource element ' + resourceElement.name + ' mime type type has been set to ' + mime)