Skip to content

Instantly share code, notes, and snippets.

View thebirk's full-sized avatar

Aleksander Birkeland thebirk

View GitHub Profile
@thebirk
thebirk / aws-exec
Created February 25, 2026 13:23
aws-exec
#!/usr/bin/env bash
# Ensure required dependencies are installed
for cmd in aws jq fzf column; do
if ! command -v "$cmd" &> /dev/null; then
echo "Error: '$cmd' is not installed or not in your PATH."
exit 1
fi
done
@thebirk
thebirk / awsp
Created February 25, 2026 13:08
Zsh function for swtiching AWS profile and validating SSO sesion
awsp () {
if [ -z "$1" ]
then
if [[ -n "$AWS_PROFILE" ]]
then
printf "Active profile: $AWS_PROFILE\n\n"
fi
local selection=$(grep "\[profile " ~/.aws/config | sed -e 's/\[profile \(.*\)\]/\1/' | fzf --height 40% --reverse --prompt="Select AWS Profile > ")
[ -z "$selection" ] && return 0
set -- "$selection"
func TabWriteSliceOfStructs[E any](w io.Writer, d []E) error {
t := reflect.TypeOf(d).Elem()
for i := 0; i < t.NumField(); i++ {
if i > 0 {
if _, err := w.Write([]byte{'\t'}); err != nil {
return err
}
}
if _, err := w.Write([]byte(t.Field(i).Name)); err != nil {
return err
@thebirk
thebirk / check_column_in_table_for_all_databases.sql
Created September 27, 2024 08:47
Check if column exists in a table across all databases - SQL Server
DECLARE @cmd nvarchar(2000)
SET @cmd = N'USE [?] IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = ''TABLE_NAME_HERE''
AND COLUMN_NAME = ''COLUMN_NAME_HERE'')
BEGIN
SELECT DB_NAME() AS ''Database'', ''TRUE'' AS ''Exists''
END
ELSE SELECT DB_NAME() AS ''Database'', ''FALSE'' AS ''Exists'''
EXEC sp_MSforeachdb @command1 = @cmd;
@thebirk
thebirk / query.sql
Created August 27, 2024 09:07
Check index usage SQL Server
/* https://stackoverflow.com/a/5146398/1088079 */
SELECT
row_number() over(order by user_seeks,user_lookups,user_scans),
[Database] = d.name,
[Schema]= s.name,
[Table]= o.name,
[Index]= x.name,
[Scans] = user_scans,
[Seeks] = user_seeks,
@thebirk
thebirk / content.js
Created February 5, 2024 23:56
OBS Websocket browser proof of concept
document.addEventListener("contextmenu", async function(e) {
const message = e.target.closest('.chat-line__message');
if (!message) {
return;
}
e.preventDefault();
const obs = new OBSWebSocket();
await obs.connect("ws://127.0.0.1:4455", "4tP1Yw7d5FxnnCjI");
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OBS Websocket</title>
<script src="https://unpkg.com/obs-websocket-js"></script>
<script type="module" async>
document.addEventListener("DOMContentLoaded", async function() {
const obs = new OBSWebSocket();
await obs.connect("ws://192.168.0.158:4455", "4tP1Yw7d5FxnnCjI");
public class DisposableStopwatch : Stopwatch, IDisposable
{
public delegate string OnStopDelegate(TimeSpan time);
private readonly OnStopDelegate _onStop;
public DisposableStopwatch(OnStopDelegate onStop)
{
_onStop = onStop;
Start();
}
package test
Id :: struct(T: typeid) {
value: int,
}
Asset :: struct {
id: Id(Asset),
name: string,
}
@thebirk
thebirk / main.odin
Created April 26, 2020 02:12
minny thing
package emulator
import "core:os"
import "core:fmt"
import "core:time"
import "core:math/rand"
when ODIN_OS == "windows" do foreign import libc "system:libcmt.lib";
when ODIN_OS == "linux" do foreign import libc "system:c";
foreign libc {