Skip to content

Instantly share code, notes, and snippets.

@mcalavera81
mcalavera81 / gist:17da485efabdb97bf5e5380faa9561f7
Created August 6, 2026 09:33
Ask for a story, not a category
Bad version. Asking for a category
What does this repository do? Who is it for, and what are its main use cases?
Good version. Asking for a story
---
name: clarity-of-intent
description: "Refactor or generate code so data models reveal intent through explicit domain types, precise names, small carriers, invariants, and immutability. Trigger on explicit requests for a clarity of intent refactor, data model refactor, or domain type review. Do NOT trigger on general architecture reviews, failure handling reviews, sustainability audits, or code quality reviews — use the architecture-review, failure-handling, or sustainability skills for those."
---
# Clarity of Intent Generator
Generate or refactor code following the **Clarity of Intent** principles from *The Art of Code*, Chapter 4.
The data model should reveal the purpose of the code. A reader should understand what a value means, what unit it uses, whether it can change, and which rules make it valid — without opening its definition, inspecting its construction logic, or searching the codebase.
case class Event(name: String, start: Int, end: Int)
def validateName(name: String): Option[String] =
if (name.size > 0) Some(name) else None
def validateEnd(end: Int): Option[Int] =
if (end < 3000) Some(end) else None
def validateStart(start: Int, end: Int): Option[Int] =
if (start <= end) Some(start) else None
val raw: List<Char> = "aabcccccaaa".map { it }
println(raw.toList().fold(listOf<Char>()) { acc, value ->
if (acc.isEmpty()) listOf(value)
else {//a2, b
if (acc.last() == value) acc
else acc + value
}
})
helm ls #list releases
helm test #run tests
#installs a release from a remote repo or local folder, in <namespace> and with extra configuration values values.yaml
#helm install <release> <chart_name|local folder> -n <namespace> -f <file_location>
helm install elasticsearch elastic/elasticsearch -n elasticsearch-poc -f ./values.yaml
helm install nginx nginx # the first nginx is the name of the release, the second one is the name of the folder
helm delete <release> #delete a release.
helm delete elasticsearch
#renders charts templates locally
helm template <release> <chart> [flags]
POST /tmdb/_close
POST /tmdb/_open
PUT /tmdb/_settings
{
"analysis": {
"filter": {
"my_shingle": {
"type": "shingle",
"min_shingle_size": 2,
ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); #B MapType mapType =
mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);
MapType yamlConfigType = mapper .getTypeFactory() .constructMapType( HashMap.class, mapper.getTypeFactory().constructType(String.class), mapType);
Path configFilePath;
Map<String, Map<String, Object>> config = mapper.readValue(configFilePath.toFile(), yamlConfigType);
AuthStrategy authStrategy = null;
Map<String, Object> authConfig = config.get("auth")
if (authConfig.get("strategy").equals(USERNAME_PASSWORD_STRATEGY)) {
authStrategy = new UsernamePasswordAuthStrategy( (String) authConfig.get("username"), (String) authConfig.get("password"));
@mcalavera81
mcalavera81 / request-deduplication
Created August 12, 2021 09:39
request deduplication
function UpdateChatRoom(req: UpdateChatRoomRequest): ChatRoom {
if (req.requestId === undefined) { // #A
return ChatRoom.update(...);
}
const hash = crypto.createHash('sha256').update(JSON.stringify(req)).digest('hex');
const cachedResponse = cache.get(req.requestId);
if (!cachedResult) { // #B
const response = ChatRoom.update(...);
cache.set(req.requestId, { response, hash }); // #C
return response;
@mcalavera81
mcalavera81 / retries-exp-back-off
Last active August 11, 2021 22:54
exponential back-off algorithm
async function getChatRoomWithRetries(id: string, maxDelayMs = 32, maxRetries = 10): Promise<ChatRoom> {
return new Promise<ChatRoom>(async (resolve, reject) => {
let retryCount = 0;
let delayMs = 1000;
while (true) {
try {
return resolve(GetChatRoom({ id }));
} catch (e) {
if (retryCount++ > maxRetries) return reject(e);
await new Promise((resolve) => {