Skip to content

Instantly share code, notes, and snippets.

@cemerson
cemerson / sublime-text-obfuscate-mangle-private-html-content-user-plugin.md
Last active September 11, 2024 10:32
Sublime Text: Obfuscate/Mangle Private HTML Content (User Plugin)

Summary

  • I needed something to clean my HTML content when using in public/AI sources
  • I initially tried Sublime Text's "macros" but they apparently can't do search/replace which is insane (imo)
  • Finally got a Sublime Text "plugin" version working - it took bit of time to hash out because all online sources (including/especially AI) were wrong and gave back/non-functioning code.
  • Sharing in case others find useful.

Important

Camel Case Command

The command in the py file * * MUST * * be exactly camel case like this or it will silently fail and never show up in the cmd palette: If the file name is my_cool_plugin.py the PY class def should be like: MyCoolPluginCommand. So:

@cemerson
cemerson / tsql-run-stored-procedure-on-multiple-ids-deletion-example.sql
Created August 19, 2024 12:37
TSQL: Run stored procedure on multiple IDs (deletion example)
BEGIN TRANSACTION
DECLARE @reviewMode int = '0';
DECLARE @password nvarchar(max) = 'password_here';
DECLARE @testStudyIDList NVARCHAR(MAX) = '2791,2793,2843,2844';
DECLARE @testStudyID NVARCHAR(4000);
DECLARE @TestStudyIDTable TABLE (ID NVARCHAR(4000));
INSERT INTO @TestStudyIDTable(ID)
SELECT Data FROM dbo.Split(@testStudyIDList, ',');
@cemerson
cemerson / csharp-get-exception-details-in-html.cs
Last active July 18, 2024 13:22
Get C# Exception Details String (HTML)
/* ---------- Usage ----------------------------------
string exceptionDetailsHtml = ExceptionHelper.GetExceptionDetailsInNicelyFormatted(ex, "HTML");
Console.WriteLine(exceptionDetailsHtml);
string exceptionDetailsText = ExceptionHelper.GetExceptionDetailsInNicelyFormatted(ex, "TEXT");
Console.WriteLine(exceptionDetailsText);
// ---------------------------------------------------- */
public static class ExceptionHelper
{
public static string GetExceptionDetailsInNicelyFormatted(Exception ex, string displayFormat = "TEXT")
@cemerson
cemerson / javascript-obfuscate-all-html-text.js
Created July 2, 2024 14:09
javascript - obfuscate all html text
function getRandomString(length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
@cemerson
cemerson / tsql-transaction-template-rollback-catcherror.sql
Last active June 24, 2024 19:52
TSQL: Template for transaction
BEGIN TRY
-- Start a transaction
BEGIN TRANSACTION;
-- Your T-SQL statements go here
-- Example:
----- YOUR SQL WORK HERE
-- If everything is successful, commit the transaction
@cemerson
cemerson / sql-empty-entire-database-ignore-constraints.sql
Created May 17, 2024 19:49
SQL: delete all data from all tables ignoring constraints
-- Step 1: Disable all foreign key constraints
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
-- Step 2: Generate delete statements for all tables
-- This part will dynamically generate the delete statements
DECLARE @sql NVARCHAR(MAX) = N'';
-- Collect all table names in the current database
SELECT @sql += 'DELETE FROM ' + QUOTENAME(s.name) + '.' + QUOTENAME(t.name) + '; '
FROM sys.tables t
@cemerson
cemerson / autohotkey-excel-extract-hyperlinks-from-selected-cells-cemerson.ahk
Last active March 18, 2024 14:23
AutoHotkey/Excel: Extract Hyperlinks from Selected Cells
@cemerson
cemerson / chatgtp-fix-export-button-hack.js
Created February 9, 2024 11:01
ChatGPT: Fix app export buttons (hack)
async function fixChatGPTExport() {
chatConf = (await invoke('get_app_conf')) || {};
actionsArea = document.querySelector('form>div>div>div');
function shouldAddButtons(actionsArea) {
// first, check if there's a "Try Again" button and no other buttons
const buttons = actionsArea.querySelectorAll('button');
const hasTryAgainButton = Array.from(buttons).some((button) => {
return !/download-/.test(button.id);
@cemerson
cemerson / ms-excel-delete-all-worksheets-but-one-2024.md
Created January 16, 2024 13:37
MS Excel - Delete All Worksheets at once but one

In Microsoft Excel, there isn't a built-in feature to delete all worksheets except one directly. However, you can use a VBA (Visual Basic for Applications) macro to achieve this. Here's a step-by-step guide:

Press Alt + F11 to open the VBA editor. In the editor, insert a new module by right-clicking on any item in the Project Explorer, selecting Insert, and then choosing Module. Copy and paste the following VBA code into the module: vba Copy code Sub DeleteAllSheetsExceptOne() Dim ws As Worksheet Dim wsToKeep As Worksheet

@cemerson
cemerson / ssl-generate-self-signed-cert-2023111x.md
Created November 16, 2023 13:34
SSL: Generate self signed cert via powershell

// Run in powershell as admin - change all ##values## as needed

$authorityCert = New-SelfSignedCertificate -Subject "CN=##MyCertFriendlyName##,OU=IT,O=##MyCompanyName## Certificate Authority,C=US" -KeyAlgorithm RSA -KeyLength 4096 -KeyUsage CertSign, CRLSign, DigitalSignature, KeyEncipherment, DataEncipherment -KeyExportPolicy Exportable -NotBefore (Get-Date) -NotAfter (Get-Date).AddYears(10)