This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| POST /tmdb/_close | |
| POST /tmdb/_open | |
| PUT /tmdb/_settings | |
| { | |
| "analysis": { | |
| "filter": { | |
| "my_shingle": { | |
| "type": "shingle", | |
| "min_shingle_size": 2, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| query = { | |
| 'query': { | |
| 'bool': { | |
| 'should': [ | |
| {'match_phrase': { | |
| 'title_exact_match': { | |
| 'query': SENTINEL_BEGIN + ' ' + usersSearch + ' ' + SENTINEL_END, | |
| 'boost': 1000, | |
| } | |
| }}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) => { |
NewerOlder