Skip to content

Instantly share code, notes, and snippets.

@TiloGit
TiloGit / get_tds_cert.py
Last active August 6, 2019 22:40 — forked from lnattrass/get_tds_cert.py
A terrible way to connect to MS SQL Server and dump the certificate as a PEM
### run like:: python3 get_tds_cert.py mySQLserver 1433
import sys
import pprint
import struct
import socket
import ssl
from time import sleep
# Standard "HELLO" message for TDS
prelogin_msg = bytearray([ 0x12, 0x01, 0x00, 0x2f, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x06, 0x01, 0x00, 0x20,
@TiloGit
TiloGit / prom-k8s-request-limits.md
Created October 8, 2021 22:16 — forked from max-rocket-internet/prom-k8s-request-limits.md
How to display Kubernetes request and limit in Grafana / Prometheus properly

CPU: percentage of limit

A lot of people land when trying to find out how to calculate CPU usage metric correctly in prometheus, myself included! So I'll post what I eventually ended up using as I think it's still a little difficult trying to tie together all the snippets of info here and elsewhere.

This is specific to k8s and containers that have CPU limits set.

To show CPU usage as a percentage of the limit given to the container, this is the Prometheus query we used to create nice graphs in Grafana:

sum(rate(container_cpu_usage_seconds_total{name!~".*prometheus.*", image!="", container_name!="POD"}[5m])) by (pod_name, container_name) /
@TiloGit
TiloGit / main_AWS.py
Last active November 16, 2021 06:50
Duolingo via Phyton
def item_already_equipped(lingo, item):
if item == 'streak_freeze':
return lingo.__dict__['user_data'].__dict__['tracking_properties']['num_item_streak_freeze'] > 0
if item == 'rupee_wager':
return lingo.__dict__['user_data'].__dict__['tracking_properties']['has_item_rupee_wager']
def main(a, b):
import duolingo, os
username = os.environ['usernames']
@TiloGit
TiloGit / dump-win-access-log.ps1
Created March 3, 2022 00:51
Simple export of win access log failures as csv
$result = Get-EventLog -LogName Security -InstanceId 4625 |
ForEach-Object {
[PSCustomObject]@{
Time = $_.TimeGenerated
Machine = $_.ReplacementStrings[6]
User = $_.ReplacementStrings[5]
Access = $_.ReplacementStrings[10]
SourceAddr = $_.ReplacementStrings[19]
}
}
@TiloGit
TiloGit / log4j2-azure-log-mon.xml
Last active March 23, 2022 19:34
log4j2 for azure log monitoring file ingestion
<RollingFile name="VFLOGMON"
filePattern="${sys:log.dir}/VFLOGMON/MyFlow-LogMon-%d{yyyy-MM-dd}-%i.log"
immediateFlush="true">
<PatternLayout alwaysWriteExceptions="false"
pattern="%d %-5p [%t] %C{2} (%F:%L) - %enc{%m}{CRLF} %replace{%throwable}{[\r|\n]}{|}%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true"/>
<SizeBasedTriggeringPolicy size="22 MB"/>
</Policies>
@TiloGit
TiloGit / fix-bitrate.ps1
Created March 31, 2022 22:23
set MS Teams Media bit rate (Kbs)
#PS use shell.azure.com
Connect-MicrosoftTeams -UseDeviceAuthentication
##use browser to login
##check value
Get-CsTeamsMeetingPolicy | select Identity, WhoCanRegister, MediaBitRateKb , RecordingStorageMode
##set to new value
Set-CsTeamsMeetingPolicy -Identity Global -MediaBitRateKb 50001
###output:
PS /home/tilo> Get-CsTeamsMeetingPolicy | select Identity, WhoCanRegister, MediaBitRateKb , RecordingStorageMode
@TiloGit
TiloGit / get-fn-addon-viajs.js
Created May 5, 2022 22:16
FileNet GCD Addon list (quick hack)
importClass(java.lang.System);
function OnCustomProcess (CEObject)
{
var objStor = CEObject.getObjectStore();
objStor.refresh();
var myDomain = objStor.get_Domain();
myDomain.refresh();
var AddOnListIterator = myDomain.get_AddOns().iterator();
var output = "";
@TiloGit
TiloGit / check-res.sh
Created June 17, 2022 21:20
Check HTTP reponse time via curl
#!/bin/bash
##from https://ops.tips/gists/measuring-http-response-times-curl/
##mod by allow self sign cert (-k)
# Set the `errexit` option to make sure that
# if one command fails, all the script execution
# will also fail (see `man bash` for more
# information on the options that you can set).
set -o errexit
@TiloGit
TiloGit / icn-curl-example.sh
Last active July 6, 2022 18:49
ICN (navigator) curl example with CP4BA IAM and ZEN (CPD)
iamURL="cp-console.apps.ocp6.tsodev.com"
cpdURL="cpd-alf1.apps.ocp6.tsodev.com"
userid="cp4baadmin"
userpw="mypass123"
##now in chain
iamToken=$(curl -b icncookie.txt -c icncookie.txt -k -s -X POST -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" -d "grant_type=password&username=$userid&password=$userpw&scope=openid" https://$iamURL/idprovider/v1/auth/identitytoken | jq '.access_token' | xargs)
echo $iamToken
@TiloGit
TiloGit / GenPDFfiles.ps1
Created October 3, 2022 20:19
Generate PDF files from text in powershell
#################createPrinter
# choose a name for your new printer
$printerName = 'PrintPDFUnattended'
# choose a default path where the PDF is saved
$PDFFilePath = "C:\PrinterTemp\PDFResultFile.pdf"
New-Item $PDFFilePath -type file -Force
# add printerPort
Add-PrinterPort -Name $PDFFilePath
# add printer
Add-Printer -DriverName "Microsoft Print to PDF" -Name $printerName -PortName $PDFFilePath