Skip to content

Instantly share code, notes, and snippets.

View dsoprea's full-sized avatar
💭
Head in yesterday. Hands in today. Heart in tomorrow.

Dustin Oprea dsoprea

💭
Head in yesterday. Hands in today. Heart in tomorrow.
View GitHub Profile
@dsoprea
dsoprea / assert_yaml_uniqueness.py
Last active January 13, 2024 09:32
Assert Uniqueness In YAML dictionaries using PyYAML
import yaml
def load_and_assert_uniqueness(x):
# We'd like to detect duplicates. Since PyYAML both loads things depth-first
# *and* doesn't give us the parent when processing a child node, we'll index
# of all of the object IDs as we're constructing them, and then see which
# are disappeared from the final hierarchy. Since all we can do is pass a
# class, we need to inline the class in order to load into an index within
# our scope.
@dsoprea
dsoprea / sentry_generate_release_commit_arguments.py
Last active August 15, 2023 22:21
Generate a list of commit arguments from a submodules superproject for a Sentry release
#!/usr/bin/env python3
# MIT LICENSE
#
# Copyright 2023 Dustin Oprea
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the “Software”), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
import os
import json
import requests
_PUBLIC_SECRET = os.environ['KLAVIYO_PUBLIC_SECRET']
_API_ROOT = 'https://a.klaviyo.com/api'
_VALID_EXTRA_ATTRIBUTES = [
@dsoprea
dsoprea / yaml_apply_context.py
Created April 1, 2022 06:51
Replace tokens into YAML during load
import string
import yaml
def load_yaml(f, context=None):
if context is None:
context = {}
def string_constructor(loader, node):
@dsoprea
dsoprea / mssql_encryption_backup_restore_encrypt_test.sql
Last active May 28, 2020 15:13
SQL Server: Backup and Restore Credentials, and Test Encryption
-- To run this script more than once, make sure to delete c:\temp\test.dmk,
-- c:\temp\test.smk, c:\temp\test.crt, and c:\temp\test.crt.key .
DECLARE @ExpectedSignature VARBINARY(8000);
DECLARE @ActualSignature VARBINARY(8000);
DECLARE @Encrypted VARBINARY(8000);
DECLARE @Decrypted VARBINARY(8000);
DECLARE @TestString VARCHAR(100) = 'protected string';
@dsoprea
dsoprea / ssl_nonblocking_client.c
Created January 24, 2019 05:30
Non-Blocking SSL Client
//============================================================================
// Name : SSLClient.cpp
// Compiling : g++ -c -o SSLClient.o SSLClient.cpp
// g++ -o SSLClient SSLClient.o -lssl -lcrypto
//============================================================================
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
@dsoprea
dsoprea / ssl_server_nonblock.c
Created January 24, 2019 04:38 — forked from darrenjs/ssl_server_nonblock.c
OpenSSL example using memory BIO with non-blocking socket IO
/*
This file had now been added to the git repo
https://github.com/darrenjs/openssl_examples
... which also includes a non blocking client example.
-------------------------------------------------------------------------------
ssl_server_nonblock.c -- Copyright 2017 Darren Smith -- MIT license
@dsoprea
dsoprea / ldap_lookup_with_python.py
Last active June 23, 2018 18:51
LDAP Lookups Against Active Directory with Python
import logging
import ldap
import collections
# Install:
#
# apt: libsasl2-dev
# pip: python-ldap
#
@dsoprea
dsoprea / strip_extended.py
Created May 22, 2018 01:08
Tool to recursively strip all extended characters from all non-hidden files
#!/usr/bin/env python3
import sys
import os
import argparse
import shutil
_DESCRIPTION = "Strip extended characters from all non-hidden files in a path."
def _get_args():
@dsoprea
dsoprea / git_squash_last.sh
Created May 4, 2018 01:59
Script to squash the last Git commit
#!/bin/bash -e
HEAD_COMMIT_MESSAGE=$(git log --format=%B -1 HEAD)
# For safety. Our use-case is usually to always just squash into a commit
# that's associated with an active change. We really don't want lose our head
# and accidentally squash something that wasn't intended to be squashed.
if [[ "${HEAD_COMMIT_MESSAGE}" != SQUASH* ]]; then
echo "SQUASH: Commit to be squashed should have 'SQUASH' as its commit-message."
exit 1