Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
keithrbennett / cec-proposed-constitution.md
Last active May 10, 2025 09:31
New constitution proposal for Chiang Mai Expats Club

Constitution of the Chiang Mai Expats Club

PREAMBLE

Pursuant to Article VIII of the existing Constitution of the Chiang Mai Expats Club (CEC), dated 24 May 2025, we the Members of the CEC, hereby adopt this amended Constitution to replace and supersede the existing Constitution, adopted on 28 January 2022.

I. NAME & PURPOSE of the CLUB

A. The club is called the "Chiang Mai Expats Club," or "CEC." Its purpose shall be to serve and help expats expand friendships and improve their quality of life by exchanging advice and information. CEC operates with the theme of "Expats Helping Expats" to reside safely and legally in Thailand and to adapt to and understand the local customs and traditions.

@keithrbennett
keithrbennett / ai-rules-to-cursor
Last active May 1, 2025 09:30
Converts plain text Cursor AI rules separated by "\n====\n" to Cursor's settings.json expected format.
#!/usr/bin/env python
# Transforms Cursor rules written in text and plain text delimited by '\n====\n'
# into the JSON expected in the project root's .cursor/settings.json.
#
# This is a filter script that reads its input from stdin and writes it to stdout.
#
# For example, it could be run like this, from the project root:
#
# ai-rules-to-json < my-rules.txt > .cursor/settings.json
@keithrbennett
keithrbennett / internet_monitor.py
Last active March 30, 2025 12:45
Python script to monitor and output Internet connection state to console and log file.
#!/usr/bin/env python -u
# This script monitors the internet connection status and logs the changes to a file.
# It uses ping or http to check the connection and the platform module to determine the appropriate ping command for the operating system.
# The script writes both human-readable output to stdout and machine-readable JSON logs to the specified log file.
# Each log entry includes:
# - timestamp: ISO format timestamp
# - state: Current connection state ("On" or "Off")
# - duration: Duration in the previous state
# - event: Only present when monitoring stops (value: "monitor_stopped")
@keithrbennett
keithrbennett / compare_request_methods.rb
Last active September 20, 2024 16:40
Illustrates getting responses from multiple HTTPS resources in Ruby using conventional, thread, and fiber approaches.
#!/usr/bin/env ruby
# frozen_string_literal: true
# IMPORTANT: You may need to increase the number of available file handles available to this process.
# The number should be greater than the maximum number of requests you want to make, because each process
# opens at least 3 file handles (stdin, stdout, stderr), and other files may be opened during the program's
# run (e.g. for the logger).
# ulimit -n 300 && scripts/compare_request_methods.rb
require 'async/http/internet' # gem install async-http if necessary
ERROR in ./app/javascript/stylesheets/application.scss (./node_modules/css-loader/dist/cjs.js??ref--6-1!./node_modules/postcss-loader/src??ref--6-2!./node_modules/sass-loader/dist/cjs.js??ref--6-3!./app/javascript/stylesheets/application.scss)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
ParserError: Syntax Error at line: 1, column 29
at /Users/kbennett/code/bbs-website/app/javascript/stylesheets/application.scss:5:44227
at Parser.error (/Users/kbennett/code/bbs-website/node_modules/postcss-values-parser/lib/parser.js:127:11)
at Parser.operator (/Users/kbennett/code/bbs-website/node_modules/postcss-values-parser/lib/parser.js:162:20)
at Parser.parseTokens (/Users/kbennett/code/bbs-website/node_modules/postcss-values-parser/lib/parser.js:245:14)
at Parser.loop (/Users/kbennett/code/bbs-website/node_modules/postcss-values-parser/lib/parser.js:132:12)
at Parser.parse (/Users/kbennett/code/bbs-website/node_modules/postcss-values-parser/lib/parser.js:51:17)
at
@keithrbennett
keithrbennett / chg-screenshot-filenames
Created February 18, 2024 13:49
Renames Mac screenshot files using a more command line friendly format.
#!/usr/bin/env python3
# This script reads the filespecs in the current directory, collects names of files
# in the default screenshot file name format, converts the names to lower case
# with spaces converted to hyphens, and removes the "at" to produce a command line friendly filespec;
# for example, "Screenshot 2024-02-18 at 21.06.31.pdf" becomes "screenshot-2024-02-18--21.06.31.pdf".
#
# It ignores but preserves the extensions, so if you have changed the screenshot file type with, e.g.:
# defaults write com.apple.screencapture type pdf && killall SystemUIServer
# then it will rename those PDF files too.
@keithrbennett
keithrbennett / 2023-12-09-chiang-mai-ai-meeting-notes.md
Last active December 10, 2023 05:45
2023-12-09 Chiang Mai AI Meeting Notes
def modules_including_module(target_module)
ObjectSpace.each_object(Module).select do |object|
# All Class'es are modules, but we are not interested in them, so we exclude them.
!object.is_a?(Class) \
&& \
object.ancestors.include?(target_module) \
&& \
!object.equal?(target_module)
end
end
# Any module (not class) that includes SemanticLogger::Loggable must also implement an
# `included` method that gets the including class to also include SemanticLogger::Loggable.
# This is because the module's instance method `logger`, when it becomes part of the including
# class, will look for `self.class.logger` when called, and `self` will evaluate to the instance
# of the class and not the module. Having the class include `Loggable` will cause a class method
# `logger` to be created so that this will work.
#
# This method returns the modules that have included Loggable but do not have an `included`
# method implementation. This is an imperfect test since we are not testing the content of that
# implementation, but I don't know a better way.
@keithrbennett
keithrbennett / module-method-doesnt-override-class-instance-method.rb
Last active September 18, 2022 07:54
Shows that a module instance method will not overwrite a class instance method of the same name if `include` is used, but *will* if `prepend` is used.
#!/usr/bin/env ruby
module M
def foo
puts 'I am a module instance method.'
end
end
# Class whose foo instance method is defined *after* the include.
class C1