Skip to content

Instantly share code, notes, and snippets.

View alanhamlett's full-sized avatar

Alan Hamlett alanhamlett

View GitHub Profile
AI_CODING_APP_HEARTBEAT_REWRITE_MAX_DISTANCE = Decimal(USER_DEFAULT_TIMEOUT * 60)
AI_MODEL_DISPLAY_NAMES = {
"amp": "Amp",
"claude": "Claude",
"cline": "Cline",
"codex": "Codex",
"cody": "Cody",
"continue": "Continue",
"copilot": "Copilot",
@alanhamlett
alanhamlett / claude.txt
Last active February 8, 2026 13:22
Claude Opus 4.6 Real World Not There Yet
Original Plan Prompt: implement backchannel-logout in the wakatime/sso/views.py file
Claude Code v2.1.37
▐▛███▜▌ Opus 4.6 · API Usage Billing
▝▜█████▛▘ ~/git/wakatime
▘▘ ▝▝ Opus 4.6 is here · Most capable for ambitious work
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Plan to implement │
│ │
@alanhamlett
alanhamlett / post-parser.ts
Created June 4, 2025 12:47
wonderful.dev markdown parser
import type { TimelineTemplate } from '@acme/db/schema';
import { makeExternalUrl, truncate, validateTLD } from './helpers';
export const MENTION_REGEX = /@[a-zA-Z][\w\d][\w\d][\w\d-]+/g;
const REPO_REGEX = /\b[a-zA-Z][\w.-]*\/[\w.-]+/g;
const REPO_ISSUE_REGEX = /\b[a-zA-Z]+[\w.-]*\/[\w.-]+#\d+/g;
export const HASHTAG_REGEX = /#[\w][\w+-]*/g;
const URL_REGEX = /(?:^|\s)(https?:\/\/)?[a-zA-Z][-a-zA-Z0-9@:%._+~#=]{0,253}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#()?&//=]*)/g;
const URL_REGEX_IN_MARKDOWN = /\]\(((https?:\/\/)?[a-zA-Z][-a-zA-Z0-9@:%._+~#=]{0,253}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#()?&//=]*))\)/g;
"""
wakatime.geocoding_utils
~~~~~~~~~~~~~~~~~~~~~~~~
Utils to get location from ip address.
"""
import traceback
import flag # https://pypi.org/project/emoji-country-flag
@alanhamlett
alanhamlett / image_utils.py
Last active September 24, 2022 08:07
Utility functions to resize, make square, and optimize (pngquant) images using Python
from io import BytesIO
from subprocess import PIPE, Popen
from typing import Optional
from PIL import Image, ImageFile, UnidentifiedImageError
from PIL.Image import DecompressionBombError
SUPPORTED_IMAGE_FORMATS = ["PNG", "JPEG", "JPEG2000"]
@alanhamlett
alanhamlett / logger.py
Created September 6, 2022 00:21
WakaQ example worker error log handler
from logging import getLogger, ERROR, Formatter, Filter
from logging.handlers import WatchedFileHandler
from wakatime import app
from wakatime.background import wakaq
TASK_LOG_FORMAT = '[%(asctime)s] %(hostname)s %(levelname)s in %(task)s args=%(task_args)s kwargs=%(task_kwargs)s retry=%(task_retry)s: %(message)s'
class TaskFilter(Filter):
@alanhamlett
alanhamlett / processHeartbeatsIntoDurations.js
Last active April 21, 2025 15:49
Turn an array of heartbeats into durations by combining heartbeats that are within Keystroke Timeout minutes from each other.
/*
BSD 3-Clause License
Copyright (c) 2023 Alan Hamlett.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
@alanhamlett
alanhamlett / wakatime-admin-__init__.py
Created November 30, 2018 00:11
Flask-Admin Example (replace dash with forward slash in file names)
# -*- coding: utf-8 -*-
"""
wakatime.admin
~~~~~~~~~~~~~~
Flask-Admin.
"""
from .views import admin
@alanhamlett
alanhamlett / oauth_example_decorator.py
Created July 12, 2018 02:22
OAuth permission decorator code snippet from WakaTime blog post
""" Example for Blog Post:
https://wakatime.com/blog/34-part-3-flask-api-decorators-and-helpers
"""
def oauth(required_scopes=[]):
def wrapper(func):
@wraps(func)
def inner(*args, **kwargs):
# don't check oauth tokens if user already logged in with session cookie
@alanhamlett
alanhamlett / oauth-provider.py
Created January 18, 2017 02:48
WakaTime OAuth Provider Implementation using Flask
# -*- coding: utf-8 -*-
"""
wakatime.oauth.provider
~~~~~~~~~~~~~~~~~~~~~~~
OAuth 2.0 Provider.
"""
from datetime import datetime, timedelta