Skip to content

Instantly share code, notes, and snippets.

@barretts
barretts / undirectedGraphNodeComponents.js
Last active March 31, 2025 23:08
turning interview questions into learning opportunities
/*
Given n, i.e. total number of nodes in an undirected graph numbered
from 1 to n and an integer e, i.e. total number of edges in the
graph. Calculate the total number of connected components in the graph.
A connected component is a set of vertices in a graph that are linked
to each other by paths.
O(E^2 log E)
mine un-sorted: 15421ms
mine un-sorted and Set nodes: 41ms
@barretts
barretts / getAppliedJobInfo.js
Created March 26, 2025 03:29
get applied job information from LinkedIn
function extractJobs(linkedInResponse) {
const jobs = [];
const jobElements = linkedInResponse?.data?.data?.searchDashClustersByAll?.elements?.[0]?.items || [];
const jobDetails = linkedInResponse?.included || [];
jobElements.forEach(({ item }) => {
const entityUrn = item?.["*entityResult"];
if (!entityUrn) return;
@barretts
barretts / muteAllDiscordChannels.js
Created March 15, 2025 21:51
mute all discord channels "Until I turn it back on"
// expand all folders before running and
// zoom out so all guild icons are visible
function extractAndProcessIds() {
const elements = document.querySelectorAll('[data-list-item-id^="guildsnav___"]');
const uniqueIdsArray = Array.from(elements)
.map(el => el.getAttribute('data-list-item-id').replace('guildsnav___', ''))
.filter(id => !isNaN(id))
.reduce((acc, id) => {
@barretts
barretts / index.ts
Last active March 6, 2025 18:31
convert diarized automatic speech recognition output to SRT subtitle file
#!/usr/bin/env ts-node
/**
* Used this Huggingface space to create a JSON formatted file
* https://huggingface.co/spaces/Xenova/whisper-speaker-diarization
*
* https://huggingface.co/onnx-community/whisper-base_timestamped
* https://huggingface.co/onnx-community/pyannote-segmentation-3.0
* https://huggingface.co/pyannote/segmentation-3.0
*/
@barretts
barretts / get_AMI_last_used_date.ps1
Created February 28, 2024 21:57
get all AMIs in a region and collect their last used date information valid from 2017 on
$amiInfo = aws ec2 describe-images --owners self --query 'Images[*].{ImageId:ImageId, CreationDate:CreationDate, Name:Name}' --output json | ConvertFrom-Json
$amiResults = @()
# $count = $amiInfo.Length;
# Write-Host "getting data for $count AMIs"
foreach ($ami in $amiInfo) {
$amiId = $ami.ImageId
$creationDate = $ami.CreationDate
@barretts
barretts / CallWhenDone.ps1
Created September 16, 2021 18:38
trigger webhook when command is finished
function CallWhenDoneFunc {
$mergedCmd = $args -join " "
Invoke-Expression $mergedCmd
# use content in payload for discord instead of text
$hookUrl = "https://hooks.slack.com/services/yoururlgoeshere"
$content = "Finished $mergedCmd"
$payload = [PSCustomObject]@{
text = $content
}
@barretts
barretts / Delete_roletouser_Duplicates.sql
Last active August 18, 2020 19:29
mysql fetch loop rows delete duplicates without primary keys
DELIMITER ;;
DROP PROCEDURE IF EXISTS Delete_roletouser_Duplicates;;
CREATE PROCEDURE Delete_roletouser_Duplicates()
BEGIN
DECLARE lmt INT DEFAULT 0;
DECLARE done INT DEFAULT 0;
DECLARE _role_id CHAR(36);
#!/usr/bin/python3
# Usage
# 0 * * * * /home/badguy90/bin/change_detection.py
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import difflib
import hashlib
@barretts
barretts / caveman-debugging-steps.md
Last active May 3, 2019 19:27
Caveman Debugging Complex Systems

Guide to Caveman Debugging Complex Systems

  • Generally state the issue you want to debug
  • Specifically identify the answer you seek from the debugging
  • List all possible points of failure in the system
  • Identify the minimum components required to debug the issue
  • Remove all possible points of failure not part of the minimum component list
  • Test the issue on this minimum setup. Does it work or not?

If the sytem does not work in the minimum setup you should begin replacing components with others that are known to work.

  • Start by switching out the component in question in this issue with one that works
@barretts
barretts / checklist.md
Last active February 20, 2019 21:36
step by step issue checklist

Yellow warnings are errors, don't ignore them.

You may at any point in the checklist need to backtrack when making code corrections and adjustments.

With all steps write down questions and notes as they arise.

Don't assume the code runs. Test it and be sure it runs.

Gather Intel

  • read the issue
  • re-read the issue making sure you understand every line, note any questions
  • create a list of the features required by this issue (fields, elements, page content)
  • if you have any outstanding questions reach out to clarify your concerns adjusting your list as necessary