Skip to content

Instantly share code, notes, and snippets.

@jtbr
jtbr / is_writable.py
Created February 26, 2026 00:06
Find whether you can write to a path without actually doing so (in python)
import os
from pathlib import Path
def is_writable(path: Path) -> tuple[bool,str]:
"""Determines if path is writeable without actually writing to it.
Return True if the process can write to path, and False otherwise, along with a useful error message."""
if path.exists():
if not os.access(path, os.W_OK):
return False, f"Cannot write to {path}: permission denied"
else:
@jtbr
jtbr / cors-proxy.js
Created February 18, 2026 16:07
Simple CORS proxy
'use strict';
const { log } = require('console');
// CORS proxy intended for local use to call 3rd-party APIs;
// redirects requests to the target URL to avoid CORS issues with strict origin.
//
// To run: `node cors-proxy.js`
// Then request http://localhost:8888/?q=https://example.com/api to proxy a request to example.com/api
//
// "localhost" and "8888" can be configured with environment variables HOST and PORT.
// The target URL can also be passed with encodeURIComponent(url) as the q parameter.
@jtbr
jtbr / claude-code-statusline-guide.md
Last active March 5, 2026 00:33 — forked from patyearone/claude-code-statusline-guide.md
Claude Code Status Line: Usage Limits, Pacing Targets, and Context Window - Complete guide with all the gotchas

Claude Code Status Line: Usage Limits, Pacing Targets, and Context Window

A complete guide to building a Claude Code status line that shows your 5-hour and weekly usage limits with color-coded progress bars, pacing markers, reset times, and context window usage.

What you get:

yearone-3 main* │ Opus 4.6 │ 07:00 PM │ ctx ▓▓░░░░░░░░ 20% │ 5hr (11pm) ▓▓▓│░░░░░░ 37% │ wk (thu, 10am) ▓▓░│░░░░░░ 26%
@jtbr
jtbr / exe_dir.h
Created June 1, 2018 11:22
Find the path to (directory containing) the currently running executable (cross-platform C++ function)
#ifndef __EXE_DIR_H__
#define __EXE_DIR_H__
#include <string>
#include <boost/predef/os.h>
#if (BOOST_OS_WINDOWS)
# include <stdlib.h>
#elif (BOOST_OS_SOLARIS)
# include <stdlib.h>
@jtbr
jtbr / endianness.h
Last active October 14, 2025 08:31
cross-platform / cross-compiler standalone endianness conversion
/**
* @file endianness.h
* @brief Convert Endianness of shorts, longs, long longs, regardless of architecture/OS
*
* Defines (without pulling in platform-specific network include headers):
* bswap16, bswap32, bswap64, ntoh16, hton16, ntoh32 hton32, ntoh64, hton64
*
* Should support linux / macos / solaris / windows.
* Supports GCC (on any platform, including embedded), MSVC2015, and clang,
* and should support intel, solaris, and ibm compilers as well.