Skip to content

Instantly share code, notes, and snippets.

View JayDoubleu's full-sized avatar
🎯
Focusing

Jay W JayDoubleu

🎯
Focusing
View GitHub Profile
@JayDoubleu
JayDoubleu / ado_create_pat_token.sh
Created January 25, 2024 14:28
Bash script to create Azure DevOps PAT token programmatically. Note, creation of PATs under service principals is NOT supported
#!/bin/bash
set -x
patName="nameOfThePatToken"
adoOrgName="yourOrgName"
apiVersion="7.1-preview.1"
apiUri="https://vssps.dev.azure.com/$adoOrgName/_apis/tokens/pats?api-version=$apiVersion"
validTo=$(date -d '+90 days' +'%Y-%m-%dT%H:%M:%S.%3NZ')
@JayDoubleu
JayDoubleu / kainositworkexperiencescheme.pptx
Last active October 25, 2023 12:20
Sample public gist
This is sample public gist
function Invoke-DatabricksAdminCreation {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, HelpMessage = 'Databricks instance URL')]
[string]$databricksUrl,
[Parameter(Mandatory = $true, HelpMessage = 'Databricks JWT token')]
[string]$bearerToken,
[Parameter(Mandatory = $true, HelpMessage = 'Object ID for the user')]
curl --location 'https://{openaiName}.openai.azure.com/openai/chunks?api-version=2023-03-31-preview' \
--header 'api-key: {openai api key}' \
--header 'Content-Type: application/json' \
--data '{
"values": [
{
"recordId": "0",
"data": {
"document_id": "aHR0cHM6Ly9zdGtuc294Zm9yZGRhdGFzYm94ZXVzMDEuYmxvYi5jb3JlLndpbmRvd3MubmV0L2RhdGEwMS9CZW5lZml0c19VSyUyMCgxKS5wZGY1",
"text": "\nYour employee benefits summary \n\nYour employee \nbenefits summary\n\n\n\nYour employee benefits summary \n\n\n\nYour employee benefits summary Your employee benefits summary \n\nYour benefits\nAs well as your salary and continued support of your professional \ndevelopment, we aim to go further and reward you with some truly \nexceptional core benefits. Here’s a summary of some of these - \nmake sure you’re not missing out on anything!\n\n\n\nYour employee benefits summary \n\nValues \nOur values drive us. Our values are not abstract, intangible beliefs: \nfor Kainos, our values are what we expect fr
$transcriptsDirectory = "C:\transcripts"
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$currentUserName = $currentUser.Name
$transcriptUser = $currentUserName.replace('\', '_')
if (!(Test-Path $transcriptsDirectory)) { New-Item -Path $transcriptsDirectory -ItemType Directory }
if ($currentUserName.Contains("SYSTEM")) { icacls "C:\AzureData" /grant Everyone:F /T }
$date = Get-Date
$transcriptFileName = "customData" + '_' + $transcriptUser + '_' + $date.ToString("yyyy-MM-dd_HH-mm-ss") + ".log"
name: CI
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Create tmate session
run: |
set -m
@JayDoubleu
JayDoubleu / tmate_ado.yaml
Created July 25, 2023 14:32
A task to use tmate.io for troubleshooting
trigger: none
pool:
vmImage: ubuntu-latest
steps:
- task: Bash@3
displayName: Life is too short for troubleshooting
inputs:
targetType: 'inline'
@JayDoubleu
JayDoubleu / tmate_ado.yaml
Created July 25, 2023 14:23
An ADO task to establish tmate session for troubleshooting
steps:
- task: Bash@3
displayName: Life's too short for troubleshooting
inputs:
targetType: 'inline'
script: |
set -m
sudo apt-get update && sudo apt-get -y install tmate
export TERM=xterm
python3 -c 'import pty; pty.spawn("/bin/tmate")'
@JayDoubleu
JayDoubleu / listStorageKeys.ps1
Created July 24, 2023 18:27
List storage keys by authenticating via managed identity
$url = 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/'
$accessToken = Invoke-RestMethod -Uri $url -Headers @{Metadata = 'true'} -Method Get -UseBasicParsing | Select-Object -ExpandProperty access_token
Write-Host "Access token: $accessToken"
$storageAccountResourceId = '/subscriptions/1c0c1a70-a036-40b3-a022-77db654391c4/resourceGroups/rg-kns-testing-prd-a-uks-01/providers/Microsoft.Storage/storageAccounts/stgknstestingprdauks01'
$url = 'https://management.azure.com/'+ $storageAccountResourceId + '/listKeys?api-version=2022-09-01&$expand=kerb'
$headers = @{
'Accept' = 'application/json'
'Authorization' = 'Bearer ' + $accessToken
}
@JayDoubleu
JayDoubleu / apt_lock.sh
Created July 24, 2023 12:16
apt-get lock function
apt_wait() {
# Check if dpkg or apt-get lock is held by another process
locks=(/var/lib/dpkg/lock /var/lib/apt/lists/lock)
for lock in "${locks[@]}"; do
echo "Waiting for lock on $lock..."
while fuser "$lock" >/dev/null 2>&1; do
sleep 1
echo -n "."
done
echo