Skip to content

Instantly share code, notes, and snippets.

View sandcastle's full-sized avatar
🍦

Glenn Morton sandcastle

🍦
View GitHub Profile
@sandcastle
sandcastle / Results
Created April 23, 2025 05:31
Lets you probe and test for shell capabilites.
========== bash ==========
--- plain mode (bash ) ---
HAS_PIPEFAIL = 1
HAS_ARRAY = 1
HAS_EUO = 1
HAS_EVAL = 1
HAS_ASSOC_ARRAY = 1
HAS_DBLBRACK = 1
@sandcastle
sandcastle / README.md
Last active April 5, 2025 02:34
Useful shell helper functions and tests to show usage

Bash Script Testing

This directory contains test files for the bash utility scripts used throughout the project.

Test Structure

  • test.sh: Main test runner that executes all test files (located in this directory)
  • utils.test.sh: Tests for _utils.sh utility functions
  • Additional test files should be named after the script they test with a .test.sh suffix
@sandcastle
sandcastle / vscode_cursor_agent_detect.sh
Created April 4, 2025 08:01
Detect if Cursor or VSCode agent (shell and non-interactive) and don't run interactive commands like bat
# Helper function to detect if running in VSCode or Cursor
is_agent_context() {
# Multiple detection methods for Cursor context
# 1. Check if its vscode or cursor (both have the same TERM_PROGRAM)
# 2. Check if this is being executed from a non-interactive shell (common in agents)
if [[ "$TERM_PROGRAM" == "vscode" ]] &&
[[ ! -o interactive ]]; then
return 0 # true in shell logic
else
return 1 # false in shell logic
@sandcastle
sandcastle / Guid.spec.ts
Created March 12, 2025 22:30
Typescript Guid v7 Implementation
/// <reference types="jest" />
import { Guid } from './Guid';
// Jest globals are likely configured in the project's tsconfig or type definitions
describe('Guid', () => {
describe('constructor', () => {
it('should create a valid GUID from a string', () => {
const guidStr = '123e4567-e89b-7123-8456-426614174000';
const guid = new Guid(guidStr);
expect(guid.valueOf()).toBe(guidStr);
@sandcastle
sandcastle / stringToColor.js
Created February 22, 2024 03:50
String to color converter
function stringToColor(str) {
// Predefined set of colors
const colors = ['#FF5733', '#33FF57', '#3357FF', '#F833FF', '#FF8333', '#33FFF8'];
// Simple hash function
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
@sandcastle
sandcastle / time_histogram.sql
Last active December 8, 2020 22:42
Time histogram helper function
CREATE OR REPLACE FUNCTION time_histogram(
start_time timestamp,
end_time timestamp
)
RETURNS TABLE(bucket timestamp) AS $$
DECLARE diff_hours int;
BEGIN
diff_hours = abs(extract(epoch from end_time - start_time) / 3600)
raise notice 'diff hours: ', diff_hours;
@sandcastle
sandcastle / posgres_size.sql
Created November 8, 2020 21:34
Postgres table sizes
WITH RECURSIVE pg_inherit(inhrelid, inhparent) AS
(select inhrelid, inhparent
FROM pg_inherits
UNION
SELECT child.inhrelid, parent.inhparent
FROM pg_inherit child, pg_inherits parent
WHERE child.inhparent = parent.inhrelid),
pg_inherit_short AS (SELECT * FROM pg_inherit WHERE inhparent NOT IN (SELECT inhrelid FROM pg_inherit))
SELECT table_schema
, TABLE_NAME
@sandcastle
sandcastle / IsLoopbackOrPrivate.cs
Created April 21, 2020 07:49
Check if loop back is private network or a loopback address...
static bool IsLoopbackOrPrivate([NotNull] IPAddress clientIp)
{
// RFC for private networks:
// http://www.faqs.org/rfcs/rfc1918.html
byte[] bytes = clientIp.GetAddressBytes();
switch(bytes[0])
{
case 10:
return true;
@sandcastle
sandcastle / animals.txt
Last active December 18, 2019 03:08
Animal and colour names for randomly generating anonymous names for users.
Alligator
Anteater
Armadillo
Axolotl
Badger
Bat
Beaver
Buffalo
Camel
Capybara
@sandcastle
sandcastle / name_blacklist.txt
Last active December 18, 2019 02:19
A blacklist of names and words that can be used for user registrations
airhead
allah
altar
anal
anus
aryan
ass
ass lick
asshole
asshole cleaner