<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>TechSwitch blog</title><link>https://techswitch.in/blogs/</link><description>Notes on DevSecOps, cloud and Python from TechSwitch.</description><language>en</language><atom:link href="https://techswitch.in/blogs/rss.xml" rel="self" type="application/rss+xml"/><item><title><![CDATA[Claude CCAR-F Certification: High Probability Questions, Cheat Sheet and Anti-Patterns]]></title><link>https://techswitch.in/blogs/claude-ccar-f-certification-sample-questions/</link><guid isPermaLink="true">https://techswitch.in/blogs/claude-ccar-f-certification-sample-questions/</guid><description><![CDATA[16 sample questions with answers, a one-page cheat sheet and the anti-patterns behind most wrong options. These may hit your CCAR-F exam: I cleared it on my second attempt.]]></description><pubDate>Sat, 31 Oct 2026 00:00:00 GMT</pubDate><category><![CDATA[Claude]]></category><category><![CDATA[Anthropic]]></category><category><![CDATA[Certification]]></category><category><![CDATA[AI Agents]]></category><content:encoded><![CDATA[<p>I cleared the Claude CCAR-F certification on my second attempt. These are sample questions I practised with, and questions like these may hit your exam. Each one has the answer and a short reason. Try each question first, then open the answer.</p>
<p>The questions are grouped in three areas: a multi-agent research system, Claude Code in a CI/CD pipeline, and structured data extraction with tool use. After them come a cheat sheet to revise from and the anti-patterns that most wrong options are built on.</p>
<ul class="jump" aria-label="On this page">
<li><a href="#multi-agent">Sample questions</a></li>
<li><a href="#cheat-sheet">Cheat sheet</a></li>
<li><a href="#anti-patterns">Anti-patterns</a></li>
<li><a href="#tips">What helped me pass</a></li>
</ul>

<h2 id="multi-agent">Multi-agent research system</h2>
<p>Most of these questions use the same scenario: a coordinator agent with four subagents (web search, document analysis, synthesis and a report generator).</p>

<div class="quiz">
<h3 id="q1">1. Too many tools per agent</h3>
<p>You've configured the system so that all four subagents have access to the complete set of 18 tools. During testing, agents frequently call tools outside their specialization: the synthesis agent attempts web searches, and the report generator tries to analyze documents. What is the primary cause of this poor tool selection behavior?</p>
<ol type="A">
<li>Choosing from 18 tools instead of 4-5 relevant ones increases decision complexity beyond reliable selection thresholds.</li>
<li>The agents' role descriptions in their system prompts conflict with having access to tools outside that role.</li>
<li>The tool definitions consume too much context window space, leaving insufficient room for task content.</li>
<li>The coordinator cannot track which capabilities each subagent has, leading to misrouted tasks.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>A.</strong> The more tools an agent can choose from, the less reliably it picks the right one. Give each subagent only the few tools its role needs.</p>
</details>
</div>

<div class="quiz">
<h3 id="q2">2. Delegation that never happens</h3>
<p>The coordinator agent has AgentDefinitions configured for all four specialized subagents, each with appropriate descriptions, prompts, and tool restrictions. During testing, you notice the coordinator correctly reasons about when to delegate (it generates messages like "I'll ask the web search agent to find sources on this topic") but no subagent execution ever occurs. The coordinator then proceeds as if the delegation happened and continues with incomplete information. Logs show no errors. What is the most likely cause?</p>
<ol type="A">
<li>The coordinator's max_tokens setting is too low, causing the Task tool invocation to be truncated before the subagent type parameter can be specified.</li>
<li>The coordinator's allowedTools configuration doesn't include "Task", so while it can reason about delegation, it cannot invoke the tool required to spawn subagents.</li>
<li>Subagent context isolation means task descriptions from the coordinator don't automatically reach subagents; you need to configure explicit context forwarding in ClaudeAgentOptions.</li>
<li>The AgentDefinitions are configured correctly, but the coordinator's system prompt doesn't explicitly list the available subagent types, preventing the model from knowing they can be invoked.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>B.</strong> Subagents are spawned through the Task tool. If <code>Task</code> is not in the coordinator's <code>allowedTools</code>, it can only talk about delegating. Nothing fails, so the logs stay clean.</p>
</details>
</div>

<div class="quiz">
<h3 id="q3">3. Giving the synthesis subagent its input</h3>
<p>After the web search and document analysis subagents complete their tasks, the coordinator needs to spawn the synthesis subagent to synthesize the findings. What is the correct approach for providing the synthesis subagent with the information it needs?</p>
<ol type="A">
<li>Provide the subagent with tool definitions that allow it to request outputs from other subagents via callbacks.</li>
<li>Include the complete findings from both subagents directly in the synthesis subagent's prompt.</li>
<li>Pass reference identifiers and configure the subagent with read access to a shared memory store where other subagents deposited their results.</li>
<li>Spawn the subagent with only a brief task description, relying on automatic context inheritance from the coordinator.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>B.</strong> A subagent starts with a fresh context and inherits nothing from the coordinator. Everything it needs goes into its prompt.</p>
</details>
</div>

<div class="quiz">
<h3 id="q4">4. How subagents share results</h3>
<p>The web search agent has gathered several relevant sources for a research topic. The document analysis agent now needs to examine these sources. How does information typically flow between these two specialized subagents?</p>
<ol type="A">
<li>The agents communicate through an event-driven message queue, with the document analysis agent subscribing to web search completion events.</li>
<li>The web search agent directly invokes the document analysis agent, passing the discovered sources as parameters.</li>
<li>The coordinator agent receives the web search agent's output and includes relevant findings in the prompt when invoking the document analysis agent.</li>
<li>Both agents access a shared memory store where the web search agent writes findings and the document analysis agent reads them.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>C.</strong> Subagents do not talk to each other. Results go back to the coordinator, which passes what is relevant to the next subagent.</p>
</details>
</div>

<div class="quiz">
<h3 id="q5">5. Lost source attribution</h3>
<p>In production, final reports frequently contain claims without proper source attribution. Investigation shows that while the web search and document analysis agents correctly attach citations to their outputs, the synthesis agent loses track of which sources support which conclusions when combining findings. What's the most effective architectural change?</p>
<ol type="A">
<li>Add a verification step where the report generator uses semantic similarity matching against original sources to reconstruct which claims came from which documents.</li>
<li>Have the coordinator inject source identifier prefixes into text before each handoff, then parse these prefixes at report generation to reconstruct citations.</li>
<li>Maintain complete transcripts of all subagent interactions and add a citation-resolution agent to analyze logs and determine attributions before report generation.</li>
<li>Require all subagents to output structured claim-source mappings that the synthesis agent must preserve and merge when combining findings from multiple sources.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>D.</strong> Keep attribution as structured data through every handoff. The other options try to rebuild it after it is lost.</p>
</details>
</div>

<div class="quiz">
<h3 id="q6">6. Simple queries run the whole pipeline</h3>
<p>In production, you observe that simple fact-checking queries (e.g., "What year was the Paris Climate Agreement signed?") traverse all four subagents sequentially, consuming 40+ seconds and significant tokens per query. Complex comparative research benefits from the full pipeline. Your query distribution is diverse and evolving as users discover new applications. What's the most effective approach to optimize for varying query complexity?</p>
<ol type="A">
<li>Have the coordinator analyze each query and dynamically decide which subagents to invoke based on its assessment of query requirements.</li>
<li>Train a query complexity classifier on labeled historical data to predict optimal subagent combinations, retraining periodically as query patterns evolve.</li>
<li>Create a fast-path for factual questions that bypasses subagents entirely, routing all other queries through the complete pipeline to ensure research thoroughness.</li>
<li>Implement pattern-based routing that categorizes queries by structure (single-fact vs. comparative vs. analytical) and maps each category to a predefined combination.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>A.</strong> The query mix keeps changing, so fixed routes and trained classifiers fall behind. Let the coordinator decide per query which subagents it needs.</p>
</details>
</div>

<div class="quiz">
<h3 id="q7">7. Conflicting findings and uncertainty</h3>
<p>Production reviews reveal inconsistent handling of uncertainty in final reports. Sometimes conflicting subagent findings are synthesized into a single confident statement (losing nuance), while other times reports over-hedge with excessive qualifications (becoming unhelpful). When the web search agent returns "industry analysts estimate $50B market size (methodology varies)" and the document analysis agent returns "peer-reviewed study estimates $35B (±$7B, 95% CI)," the coordinator either picks one arbitrarily or produces vague statements like "the market may be $35B-$50B depending on factors." What systematic approach best addresses this?</p>
<ol type="A">
<li>Implement a confidence calibration layer that normalizes subagent uncertainty expressions to standardized probability scores (0.0-1.0), then weight-average findings by their calibrated confidence.</li>
<li>Instruct the synthesis agent to structure reports with explicit sections distinguishing well-established findings from contested ones, preserving original source characterizations and methodological context.</li>
<li>Configure subagents to only report findings meeting a high-confidence threshold, filtering uncertain information before it reaches the coordinator.</li>
<li>Add a verification subagent that cross-references findings across sources, only passing claims to synthesis that are corroborated by at least two independent sources.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>B.</strong> Show the conflict with each source's method, so the reader can judge. Averaging or filtering removes exactly the context the reader needs.</p>
</details>
</div>

<div class="quiz">
<h3 id="q8">8. Every output turned into bullet points</h3>
<p>A user expands the research system beyond its original web-search agent by adding specialized data sources. A financial API agent returns structured JSON containing revenue, margins, and growth rates. A news-monitoring agent returns prose summaries of recent developments. A patent-analysis agent returns structured lists of technology areas. The synthesis agent combines these results into executive briefings. Currently, it converts everything into bullet points, causing financial comparisons to lose tabular clarity and news summaries to lose their narrative flow. What change would most improve briefing quality?</p>
<ol type="A">
<li>Standardize all subagent outputs as prose summaries with inline citations.</li>
<li>Standardize all subagent outputs as JSON containing fields for claim, evidence, source, and confidence.</li>
<li>Update the synthesis agent to render each content type appropriately: financial data as tables, news as prose, and technology areas as structured lists.</li>
<li>Add a format-conversion layer that transforms every subagent result into a common intermediate representation before synthesis.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>C.</strong> The problem is in synthesis, so fix it there. Each content type keeps the format that suits it. Forcing one format on all of them is the problem you started with.</p>
</details>
</div>

<h2 id="claude-code-ci">Claude Code in CI/CD</h2>

<div class="quiz">
<h3 id="q9">9. Capping turns and cost per run</h3>
<p>You are integrating Claude Code into your CI/CD pipeline. The system runs automated code reviews, generates test cases, and provides feedback on pull requests. You need to design prompts that provide actionable feedback and minimize false positives. During initial testing of the automated review pipeline, you notice that reviews on large pull requests containing more than 50 changed files sometimes take over 20 minutes and cost $8-$12 per run because of extensive agentic loops. Claude reads files, runs analysis tools, and iterates many times. Your team needs each invocation to abort once it reaches both a fixed iteration count and a fixed dollar amount, enforced by Claude Code itself rather than by the surrounding job runner. Which configuration change directly enforces both per-invocation caps?</p>
<ol type="A">
<li>Switch the <code>--model</code> flag to a smaller, less expensive model so each iteration uses fewer tokens and has a lower per-call cost.</li>
<li>Set <code>timeout-minutes: 5</code> on the GitHub Actions job step and monitor per-run costs through the Anthropic Console usage dashboard.</li>
<li>Add <code>--max-turns 10 --max-budget-usd 2.00</code> to the <code>claude -p</code> invocation to cap iterations and spending.</li>
<li>Set <code>--permission-mode dontAsk</code> to automatically deny tool-permission requests not included in the explicitly allowed set.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>C.</strong> <code>--max-turns</code> caps iterations and <code>--max-budget-usd</code> caps spend, and Claude Code enforces both. A job timeout is the runner's limit, and a cheaper model caps neither.</p>
</details>
</div>

<div class="quiz">
<h3 id="q10">10. Review that ignores the rest of the repo</h3>
<p>You are setting up a non-interactive automated code review pipeline using Claude Code. You want Claude to analyze a pulled Git diff (<code>git diff</code>) against the main branch and apply a custom set of code review instructions. However, you notice that when you run the pipeline, Claude only looks at the raw diff text itself and completely stops using its file-reading or code navigation tools. As a result, it fails to inspect the broader codebase repository context, which is critical because the diff modifies a core function called by many other external modules. Which change to the CLI invocation will cause Claude to read related files in the repository while still successfully applying your custom review instructions?</p>
<ol type="A">
<li>Replace <code>--system-prompt</code> with <code>--append-system-prompt</code> so your review instructions are added to Claude Code's default prompt instead of overwriting the built-in guidance for using file-reading and code navigation tools.</li>
<li>Keep <code>--system-prompt</code> and add <code>--allowedTools "Read, Glob, Grep"</code> so that the non-interactive mode permits file system tools that it otherwise disables.</li>
<li>Stop piping the diff via stdin and instead embed the diff contents inside the prompt string, so Claude Code treats the invocation as an agentic session rather than a stream-processing one.</li>
<li>Remove <code>--system-prompt</code> entirely and place the review instructions in a CLAUDE.md file at the repo root, since <code>--system-prompt</code> is incompatible with tool use under <code>-p</code>.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>A.</strong> <code>--system-prompt</code> replaces Claude Code's whole default prompt, including its guidance on using tools. <code>--append-system-prompt</code> keeps that guidance and adds your instructions.</p>
</details>
</div>

<h2 id="extraction">Structured extraction and tool use</h2>
<p>These questions use a system that extracts information from unstructured documents, validates it against JSON schemas and passes it to downstream systems.</p>

<div class="quiz">
<h3 id="q11">11. Unparseable JSON</h3>
<p>Your extraction pipeline occasionally receives responses that cannot be parsed as valid JSON, causing downstream processing failures. The current implementation prompts Claude to return JSON in the response text and then parses it. What is the most reliable approach to ensure Claude returns valid, schema-compliant structured data?</p>
<ol type="A">
<li>Add explicit formatting instructions to the prompt with JSON examples, emphasizing that Claude must return only valid JSON with no surrounding text.</li>
<li>Use regular expressions to locate and extract JSON from the response text, handling cases where Claude includes explanatory text around the JSON block.</li>
<li>Define a tool with a JSON schema specifying the expected structure, using tool use to constrain Claude's output to schema-compliant JSON.</li>
<li>Implement a retry loop that catches JSON parsing errors and re-prompts Claude with the error details, asking it to correct the malformed output.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>C.</strong> A tool's input schema makes Claude return structured arguments that match the schema. Prompt instructions, regex and retries treat the symptom.</p>
</details>
</div>

<div class="quiz">
<h3 id="q12">12. Forcing the first tool call</h3>
<p>Your pipeline uses a tool called <code>extract_metadata</code> with a JSON schema for paper details. You've also defined <code>lookup_citations</code> and <code>verify_doi</code> tools for enrichment. During testing, you notice that when users include requests like "extract the metadata and tell me how cited it is," Claude sometimes calls <code>lookup_citations</code> first, which fails because it needs the DOI that <code>extract_metadata</code> would provide. What's the most effective way to ensure structured metadata extraction happens first?</p>
<ol type="A">
<li>Set tool choice to <code>{"type": "tool", "name": "extract_metadata"}</code> and process the enrichment requests in subsequent turns after receiving the extracted metadata.</li>
<li>Set tool choice to <code>"any"</code> so Claude must use a tool, combined with system prompt instructions prioritizing <code>extract_metadata</code>.</li>
<li>Set tool choice to <code>{"type": "tool", "name": "extract_metadata"}</code> for every API call in the pipeline, ensuring Claude always extracts metadata before any enrichment can occur.</li>
<li>Set tool choice to <code>"auto"</code> and reorder the tool definitions so <code>extract_metadata</code> appears first in the tools array, since Claude prioritizes earlier-listed tools.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>A.</strong> Force <code>extract_metadata</code> on the first call only, then let later turns use the enrichment tools. Forcing it on every call (C) means the enrichment tools never run. <code>"any"</code> doesn't say which tool, and tool order sets no priority.</p>
</details>
</div>

<div class="quiz">
<h3 id="q13">13. Batch or real-time</h3>
<p>Your extraction system processes two document types: standard monthly reports, which are archived after processing, and urgent exception reports, which must trigger business alerts within 30 minutes of receipt. Both use the same JSON schema. You want to minimize API costs while meeting the latency requirements. How should you architect the processing pipeline?</p>
<ol type="A">
<li>Submit all documents to the Message Batches API with custom_id values for tracking. When results arrive, immediately process urgent documents and trigger delayed alerts for exceptions.</li>
<li>Route standard reports to the Message Batches API for 50% cost savings, and route urgent exception reports to the real-time Messages API.</li>
<li>Queue all documents and submit hourly batches, flagging urgent documents for expedited handling when batch results return.</li>
<li>Submit all documents to the real-time Messages API to ensure consistent processing latency across document types.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>B.</strong> Batches cost half as much but can take up to 24 hours, with no latency guarantee. Batch the reports that can wait and send the urgent ones in real time.</p>
</details>
</div>

<div class="quiz">
<h3 id="q14">14. Valid JSON, empty fields</h3>
<p>After implementing tool use with strict schema definitions, JSON syntax errors are eliminated, but 5% of extractions still have valid JSON with empty arrays or null values for required fields like citations and methodology. Spot-checking reveals that source documents contain this information, but in varied formats: inline citations vs. bibliographies, methodology sections vs. details embedded in introductions. What's the most effective way to address these failures?</p>
<ol type="A">
<li>Modify your schema to make citations and methodology optional, and flag incomplete records for manual review rather than failing validation.</li>
<li>Build a regex-based post-processing layer that scans source documents for citation patterns and methodology keywords, populating empty fields when the model fails to extract.</li>
<li>Add few-shot examples demonstrating extractions from documents with varied structures, showing how to identify citations in different formats and locate methodology details across section types.</li>
<li>Implement retry logic that re-sends requests when validation detects empty required fields.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>C.</strong> The information is in the documents, so the model doesn't recognise it in unfamiliar layouts. Examples of each layout fix that. Retries repeat the same miss.</p>
</details>
</div>

<div class="quiz">
<h3 id="q15">15. Inconsistent values in one field</h3>
<p>Your extraction system parses e-commerce product descriptions to extract specifications like dimensions, weight, and materials into JSON. Despite having a well-defined schema, the model inconsistently extracts the "materials" field: sometimes returning "cotton blend", other times "Cotton/Polyester mix", and occasionally omitting the field when material information is clearly present in the source. What's the most effective way to improve extraction consistency?</p>
<ol type="A">
<li>Set temperature to 0 to eliminate randomness and ensure deterministic outputs.</li>
<li>Switch to a more capable model tier since inconsistent extraction indicates insufficient model capability.</li>
<li>Make the "materials" field required instead of optional in the schema to force the model to always extract a value.</li>
<li>Add few-shot examples showing 2-3 complete input-output pairs with standardized material description formats.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>D.</strong> The model has no standard to follow. Examples show it the format you want. Temperature 0 makes output repeatable, not standardised.</p>
</details>
</div>

<div class="quiz">
<h3 id="q16">16. A skills array with three problems</h3>
<p>Your schema includes a <code>skills: string[]</code> field. Production monitoring reveals three consistency issues: (1) compound phrases like "Python and SQL" are sometimes kept as one entry, sometimes split; (2) implied but unstated skills occasionally appear in extractions; (3) similar documents produce wildly different array lengths (5-10 vs 40+ entries). Your prompt currently says "Extract all skills mentioned." What's the most effective improvement?</p>
<ol type="A">
<li>Add few-shot examples demonstrating compound phrase handling, explicit mention criteria, and appropriate entry granularity.</li>
<li>Add constraints: "Extract 10-20 skills maximum, one skill per entry, only explicitly named skills."</li>
<li>Add post-extraction normalization that maps skills to a canonical taxonomy and deduplicates similar entries.</li>
<li>Enrich the schema to <code>skill: string, confidence: float, source_quote: string</code> to capture extraction confidence.</li>
</ol>
<details><summary>Show answer</summary>
<p><strong>A.</strong> A few examples fix all three problems at once. A hard count (B) cuts real skills from long documents, and post-processing (C) can't remove skills the model invented.</p>
</details>
</div>

<h2 id="cheat-sheet">Cheat sheet</h2>
<p>The facts I kept coming back to while revising, one line each.</p>

<div class="sheet">
<section class="sheet__group" aria-labelledby="cs-api">
<h3 id="cs-api">Messages API</h3>
<dl>
<dt>State</dt><dd>The API is stateless. Send the full conversation history, the system prompt and the tools on every request.</dd>
<dt><code>system</code></dt><dd>A separate field, not a message. It sets the role, rules and output format for the whole conversation.</dd>
<dt><code>stop_reason</code></dt><dd><code>tool_use</code>: run the tool and send back a <code>tool_result</code>. <code>end_turn</code>: done. <code>max_tokens</code>: the reply was cut off.</dd>
<dt>Long inputs</dt><dd>Details in the middle of a long context get missed. Put key facts at the start or end, and trim tool results to the fields you need.</dd>
</dl>
</section>

<section class="sheet__group" aria-labelledby="cs-tools">
<h3 id="cs-tools">Tools and structured output</h3>
<dl>
<dt>Descriptions</dt><dd>Claude picks a tool by its description. Say what it does, what it returns, its input format and when to use it instead of a similar tool.</dd>
<dt><code>tool_choice</code></dt><dd><code>auto</code>: Claude decides. <code>any</code>: some tool must be called. <code>{"type": "tool", "name": …}</code>: that tool must be called.</dd>
<dt>JSON schema</dt><dd>A tool's input schema guarantees valid, well-formed JSON. It does not guarantee the values are right.</dd>
<dt>Schema design</dt><dd>Make a field required only if every source has it. Otherwise make it nullable, or Claude will invent a value. Add <code>"other"</code> or <code>"unclear"</code> to enums.</dd>
<dt>Semantic errors</dt><dd>Totals that don't add up, or values in the wrong field: catch them with validation, then retry with the specific error.</dd>
</dl>
</section>

<section class="sheet__group" aria-labelledby="cs-agents">
<h3 id="cs-agents">Agents and the Agent SDK</h3>
<dl>
<dt>Agentic loop</dt><dd>Call Claude, run the tools it asks for, append the results, repeat while <code>stop_reason</code> is <code>tool_use</code>.</dd>
<dt>Hub and spoke</dt><dd>The coordinator splits the task, picks the subagents, passes context and collects results. Subagents never talk to each other.</dd>
<dt>Subagent context</dt><dd>A subagent starts empty. Everything it needs goes in its prompt.</dd>
<dt>Spawning</dt><dd>Subagents are started with the Agent tool (called Task in older versions). It must be in the coordinator's allowed tools. Several calls in one turn run in parallel.</dd>
<dt>Tool scope</dt><dd>Give each agent only the 4–5 tools its role needs.</dd>
<dt>Hooks</dt><dd><code>PreToolUse</code> can block or redirect a call. <code>PostToolUse</code> can rewrite a result. Use them for rules that must always hold.</dd>
<dt>Sessions</dt><dd><code>--resume</code> continues a named session, and forking branches one. After files change, tell Claude what changed, or start fresh with a summary.</dd>
</dl>
</section>

<section class="sheet__group" aria-labelledby="cs-mcp">
<h3 id="cs-mcp">MCP</h3>
<dl>
<dt>Parts</dt><dd>Tools are actions, resources are data to read (schemas, catalogues, docs), and prompts are reusable templates.</dd>
<dt>Config</dt><dd><code>.mcp.json</code> in the repo is shared with the team, with secrets as <code>${ENV_VAR}</code>. <code>~/.claude.json</code> is personal.</dd>
<dt>Errors</dt><dd>Return <code>isError: true</code> with a category, a message and whether a retry makes sense. "Operation failed" tells the agent nothing.</dd>
<dt>Build or reuse</dt><dd>Use existing servers for standard systems like GitHub or Jira. Build your own only for workflows unique to your team.</dd>
</dl>
</section>

<section class="sheet__group" aria-labelledby="cs-code">
<h3 id="cs-code">Claude Code</h3>
<dl>
<dt>CLAUDE.md</dt><dd><code>~/.claude/CLAUDE.md</code> is yours only. The project's <code>CLAUDE.md</code> or <code>.claude/CLAUDE.md</code> is shared through git. A <code>CLAUDE.md</code> in a subfolder applies to that folder.</dd>
<dt>Imports</dt><dd><code>@path/to/file.md</code> pulls in another file. Relative paths resolve from the importing file.</dd>
<dt>Rules</dt><dd><code>.claude/rules/*.md</code> with <code>paths:</code> globs load only for matching files, such as every test file across the repo.</dd>
<dt>Skills</dt><dd><code>.claude/skills/&lt;name&gt;/SKILL.md</code> is shared, <code>~/.claude/skills/</code> is personal. <code>context: fork</code> runs one in a subagent, and <code>allowed-tools</code> limits its tools.</dd>
<dt>Plan mode</dt><dd>For large, unclear or multi-file changes. Make small, clear fixes directly.</dd>
<dt>CI</dt><dd><code>claude -p</code> runs without prompts. Add <code>--output-format json</code>, <code>--max-turns</code>, <code>--max-budget-usd</code> and <code>--allowedTools</code>, and use <code>--append-system-prompt</code> rather than <code>--system-prompt</code>.</dd>
</dl>
</section>

<section class="sheet__group" aria-labelledby="cs-prompt">
<h3 id="cs-prompt">Prompting and pipelines</h3>
<dl>
<dt>Few-shot</dt><dd>The fix when output is inconsistent or the inputs vary: 2–4 examples that show the format and the edge cases.</dd>
<dt>Criteria</dt><dd>"Flag only issues that can cause a bug" beats "be thorough". Vague instructions give vague results.</dd>
<dt>Chaining</dt><dd>Use fixed steps when the task is predictable, and let the coordinator decide when it isn't. Review big diffs per file, then once across the files.</dd>
<dt>Retries</dt><dd>Retry with the exact error and they fix format mistakes. They can't add information the source doesn't have.</dd>
</dl>
</section>

<section class="sheet__group" aria-labelledby="cs-batch">
<h3 id="cs-batch">Message Batches API</h3>
<dl>
<dt>Trade-off</dt><dd>Half the price, but results can take up to 24 hours, with no latency guarantee.</dd>
<dt>Use it for</dt><dd>Overnight and bulk jobs. Anything a person or a deadline is waiting on goes to the regular API.</dd>
<dt><code>custom_id</code></dt><dd>Results come back in any order. Match them to requests with <code>custom_id</code>, and resubmit only the failures.</dd>
<dt>Before a big batch</dt><dd>Test the prompt on a small sample with the regular API first.</dd>
</dl>
</section>

<section class="sheet__group" aria-labelledby="cs-ops">
<h3 id="cs-ops">Escalation, errors and context</h3>
<dl>
<dt>Escalate when</dt><dd>The customer asks for a human, policy doesn't cover the case, or the agent can't make progress.</dd>
<dt>Handoff</dt><dd>Pass a structured summary (customer, issue, what was tried, what is needed) so the human doesn't start over.</dd>
<dt>Subagent errors</dt><dd>Retry transient errors locally. Otherwise send the coordinator the error type, the partial results and whether to retry.</dd>
<dt>Gaps</dt><dd>If a topic has no sources, say so in the report instead of leaving it out.</dd>
<dt>Long sessions</dt><dd>Keep key facts (IDs, amounts, dates) in a block that is never summarised. Summaries blur numbers.</dd>
</dl>
</section>
</div>

<h2 id="anti-patterns">Anti-patterns</h2>
<p>Most wrong options aren't random: they are real mistakes that sound reasonable. Learn to spot these and many questions become easy.</p>

<ol class="traps">
<li>
<h3>Teaching tool order with examples</h3>
<p class="traps__bad"><span>Trap</span>Few-shot examples or prompt rules to make sure <code>verify_identity</code> runs before <code>process_refund</code>.</p>
<p class="traps__fix"><span>Fix</span>A hook or prerequisite check in code that blocks the second call until the first has succeeded.</p>
</li>
<li>
<h3>Trusting the model's own confidence</h3>
<p class="traps__bad"><span>Trap</span>Escalating when Claude says it is unsure, or filtering findings by a confidence score it reports.</p>
<p class="traps__fix"><span>Fix</span>Objective triggers: a missing field, an amount over a limit, a policy gap, an explicit request for a human.</p>
</li>
<li>
<h3>Escalating on sentiment</h3>
<p class="traps__bad"><span>Trap</span>Routing to a human when the customer sounds angry.</p>
<p class="traps__fix"><span>Fix</span>Escalate on what the case needs. An angry customer with a simple problem can still be helped by the agent.</p>
</li>
<li>
<h3>Reading the reply to decide when to stop</h3>
<p class="traps__bad"><span>Trap</span>Ending the loop when the text says "done", or after a fixed number of turns.</p>
<p class="traps__fix"><span>Fix</span>Stop on <code>stop_reason == "end_turn"</code>. A turn cap is only a safety net.</p>
</li>
<li>
<h3>Batching everything to save money</h3>
<p class="traps__bad"><span>Trap</span>Sending urgent or interactive work to the Batches API for the discount.</p>
<p class="traps__fix"><span>Fix</span>Batch only what can wait up to a day. Send the rest to the regular API.</p>
</li>
<li>
<h3>A bigger context window for missed details</h3>
<p class="traps__bad"><span>Trap</span>Switching to a model with a larger window when details in a long document get missed.</p>
<p class="traps__fix"><span>Fix</span>Process the document in focused sections, then run one pass that combines the section results.</p>
</li>
<li>
<h3>Every tool for every agent</h3>
<p class="traps__bad"><span>Trap</span>Giving all agents all tools "for flexibility", including full web search for the synthesis agent.</p>
<p class="traps__fix"><span>Fix</span>Give each role its own few tools. For a rare need, add one narrow tool or route it back through the coordinator.</p>
</li>
<li>
<h3>Hiding failures</h3>
<p class="traps__bad"><span>Trap</span>A failed subagent returns an empty result, so the coordinator can't tell "found nothing" from "couldn't look".</p>
<p class="traps__fix"><span>Fix</span>Return an error with its type, the partial results and whether a retry makes sense.</p>
</li>
<li>
<h3>One failure stops everything</h3>
<p class="traps__bad"><span>Trap</span>A timeout in one subagent ends the whole workflow and throws away the finished work.</p>
<p class="traps__fix"><span>Fix</span>Recover locally where possible. Otherwise report to the coordinator, which can retry, reroute or continue with a noted gap.</p>
</li>
<li>
<h3>Required fields to force complete output</h3>
<p class="traps__bad"><span>Trap</span>Marking every schema field required so nothing comes back empty.</p>
<p class="traps__fix"><span>Fix</span>Make fields nullable where the source may not have the data. An honest null beats an invented value.</p>
</li>
<li>
<h3>Prompt rules as security</h3>
<p class="traps__bad"><span>Trap</span>A generic <code>fetch_url</code> tool plus "only fetch approved domains" in the prompt.</p>
<p class="traps__fix"><span>Fix</span>A narrower tool that checks an allow-list itself, so the rule holds whatever the input says.</p>
</li>
<li>
<h3>Guessing between matching records</h3>
<p class="traps__bad"><span>Trap</span>A lookup returns two customers and the agent picks the most recent one.</p>
<p class="traps__fix"><span>Fix</span>Ask for another identifier, such as an email or order number, before acting.</p>
</li>
<li>
<h3>Trusting the overall accuracy number</h3>
<p class="traps__bad"><span>Trap</span>Cutting human review because accuracy is 97% overall.</p>
<p class="traps__fix"><span>Fix</span>Check accuracy per document type and field first. A small document type can fail badly inside a good average.</p>
</li>
<li>
<h3>Resuming on stale results</h3>
<p class="traps__bad"><span>Trap</span>Resuming a session after the code changed and expecting Claude to notice.</p>
<p class="traps__fix"><span>Fix</span>Tell it which files changed, or start a new session with a summary of what was found.</p>
</li>
</ol>

<p class="rule"><strong>The rule behind them all:</strong> when something must always happen, enforce it in code (hooks, schemas, <code>stop_reason</code>, allow-lists, explicit triggers), not with a prompt, examples or the model's own judgment.</p>

<h2 id="tips">What helped me pass</h2>
<ul>
<li>Most questions describe a symptom and ask for the root cause. Ignore answers that add a layer to work around the problem.</li>
<li>If the model "doesn't know" a format or standard, the answer is usually few-shot examples. If the output must match a structure, it is tool use with a schema.</li>
<li>Subagents share nothing on their own. The coordinator passes everything, in the prompt.</li>
<li>Learn the Claude Code CLI flags: <code>-p</code>, <code>--max-turns</code>, <code>--max-budget-usd</code>, <code>--system-prompt</code> and <code>--append-system-prompt</code>, <code>--allowedTools</code>, <code>--permission-mode</code>.</li>
</ul>
<p>Good luck with your exam.</p>

<h3 id="heading-wanna-thank-me">Wanna thank me? 👇🏼</h3>
<p><a target="_blank" href="https://www.buymeacoffee.com/techswitch"><img loading="lazy" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" /></a></p>]]></content:encoded></item><item><title><![CDATA[Part 2 - Artifacts Attestation for Builds in Github Actions]]></title><link>https://techswitch.in/blogs/part-2-artifacts-attestation-for-builds-in-github-actions/</link><guid isPermaLink="true">https://techswitch.in/blogs/part-2-artifacts-attestation-for-builds-in-github-actions/</guid><description><![CDATA[Boost build's supply chain security by adding artifact attestations in Github Actions]]></description><pubDate>Fri, 03 Nov 2023 18:30:00 GMT</pubDate><category><![CDATA[github-actions]]></category><category><![CDATA[Security]]></category><category><![CDATA[Attestation]]></category><category><![CDATA[Actions]]></category><category><![CDATA[workflow]]></category><category><![CDATA[deployment]]></category><category><![CDATA[Pipelines]]></category><category><![CDATA[DevSecOps]]></category><content:encoded><![CDATA[<p>Artifact attestations help boost your build's supply chain security by showing where and how your software was created.</p>
<p>In Github Actions we can acheive this using <code>actions/attest-build-provenance</code></p>
<ol>
<li>First add permission to your workflows / re-usable workflows with <code>attestations: write</code></li>
</ol>
<pre tabindex="0"><code class="lang-yaml"><span class="hljs-attr">permissions:</span>
  <span class="hljs-attr">id-token:</span> <span class="hljs-string">write</span>
  <span class="hljs-attr">contents:</span> <span class="hljs-string">read</span>
  <span class="hljs-attr">attestations:</span> <span class="hljs-string">write</span>
</code></pre>
<h3 id="heading-optional-with-maven-builds">(optional) with Maven Builds</h3>
<p>need to specify the jar that would be generated during the maven build with exact path. in my case it is <code>target/*.jar</code> We can also add the name to attestation.</p>
<pre tabindex="0"><code class="lang-yaml">    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Build</span> <span class="hljs-string">with</span> <span class="hljs-string">Maven</span>
      <span class="hljs-attr">shell:</span> <span class="hljs-string">bash</span>
      <span class="hljs-attr">run:</span> <span class="hljs-string">mvn</span> <span class="hljs-string">--batch-mode</span> <span class="hljs-string">--update-snapshots</span> <span class="hljs-string">-DskipTests</span> <span class="hljs-string">package</span>    

    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Attest</span> <span class="hljs-string">Artifacts</span>
      <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/attest-build-provenance@v1.3.2</span>
      <span class="hljs-attr">with:</span>
        <span class="hljs-attr">subject-path:</span> <span class="hljs-string">'target/*.jar'</span>
        <span class="hljs-attr">subject-name:</span> <span class="hljs-string">${{</span> <span class="hljs-string">inputs.container-name</span> <span class="hljs-string">}}-attestation</span>
</code></pre>
<ol start="2">
<li><h1 id="heading-with-docker-builds">with Docker builds</h1>
</li>
</ol>
<p>Similarly, you can ensure that your Docker artifacts are properly attested, thereby enhancing the security and integrity of your build process. This approach helps in maintaining a robust supply chain security by providing verifiable evidence of how and where your Docker images were created.</p>
<pre tabindex="0"><code class="lang-yaml">    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Docker</span> <span class="hljs-string">build-push</span>
      <span class="hljs-attr">id:</span> <span class="hljs-string">docker-build</span>
      <span class="hljs-attr">uses:</span> <span class="hljs-string">docker/build-push-action@v6</span>
      <span class="hljs-attr">with:</span>
        <span class="hljs-attr">context:</span> <span class="hljs-string">.</span>
        <span class="hljs-attr">push:</span> <span class="hljs-literal">true</span>
        <span class="hljs-attr">tags:</span> <span class="hljs-string">|
          ${{ inputs.acr-url }}/${{ inputs.container-name }}:latest
</span>        <span class="hljs-comment"># cache-from: type=registry,ref=${{ inputs.acr-url }}/${{ env.containerName }}:buildcache</span>
        <span class="hljs-comment"># cache-to: type=registry,ref=${{ inputs.acr-url }}/${{ env.containerName }}:buildcache,mode=max</span>
        <span class="hljs-attr">cache-from:</span> <span class="hljs-string">type=gha</span>
        <span class="hljs-attr">cache-to:</span> <span class="hljs-string">type=gha,mode=max</span>   

    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Attest</span> <span class="hljs-string">Docker</span> <span class="hljs-string">build</span>
      <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/attest-build-provenance@v1.3.2</span>
      <span class="hljs-attr">id:</span> <span class="hljs-string">attest</span>
      <span class="hljs-attr">with:</span>
        <span class="hljs-attr">subject-name:</span> <span class="hljs-string">${{</span> <span class="hljs-string">inputs.acr-url</span> <span class="hljs-string">}}/${{</span> <span class="hljs-string">inputs.container-name</span> <span class="hljs-string">}}</span>
        <span class="hljs-attr">subject-digest:</span> <span class="hljs-string">${{</span> <span class="hljs-string">steps.docker-build.outputs.digest</span> <span class="hljs-string">}}</span>
        <span class="hljs-attr">push-to-registry:</span> <span class="hljs-literal">true</span>
</code></pre>
<p>And by just Generating these attestations doesn’t boost security.</p>
<ol start="3">
<li>You need to verify them for it to actually make a difference. Here is an example how this can be verified</li>
</ol>
<pre tabindex="0"><code class="lang-yaml">    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Verify</span> <span class="hljs-string">OCI</span> <span class="hljs-string">image</span>
      <span class="hljs-attr">shell:</span> <span class="hljs-string">bash</span>
      <span class="hljs-attr">env:</span>
        <span class="hljs-attr">GH_TOKEN:</span> <span class="hljs-string">${{</span> <span class="hljs-string">inputs.github-token</span> <span class="hljs-string">}}</span>
      <span class="hljs-attr">run:</span> <span class="hljs-string">|</span>
        <span class="hljs-string">gh</span> <span class="hljs-string">attestation</span> <span class="hljs-string">verify</span> <span class="hljs-string">oci://${{</span> <span class="hljs-string">inputs.acr-url</span> <span class="hljs-string">}}/${{</span> <span class="hljs-string">inputs.container-name</span> <span class="hljs-string">}}:latest</span> <span class="hljs-string">--owner</span> <span class="hljs-string">"$GITHUB_REPOSITORY_OWNER"</span>
</code></pre>
<p>You will see a detailed summary after the workflow execution is complete. it will show the status of the Docker build and push actions, indicating whether the image was successfully built and pushed to the specified container registry.</p>
<p>Additionally, it will include information about the attestation process, confirming whether the build provenance was properly attested and pushed to the registry.</p>
<p>Finally, the summary will display the results of the verification step, showing whether the OCI image was successfully verified using the provided GitHub token. This comprehensive summary helps ensure that each step of the workflow was executed correctly and provides valuable insights into the overall process.</p>
<p><img loading="lazy" src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719430534520/617391ed-b5ca-49d1-86a9-4047c5e140a2.png" alt class="image--center mx-auto" /></p>
<p>By clicking on the Attestation URL, you will see detailed information.</p>
<p><img loading="lazy" src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719430672824/d084765c-49bb-493e-8cce-76b5e6a0f298.png" alt class="image--center mx-auto" /></p>]]></content:encoded></item><item><title><![CDATA[Part 1 - Cache Docker, Python, Java(Maven), Node(npm), Go Modules in Github Actions]]></title><link>https://techswitch.in/blogs/cache-docker-python-javamaven-nodenpm-go-modules-in-github-actions/</link><guid isPermaLink="true">https://techswitch.in/blogs/cache-docker-python-javamaven-nodenpm-go-modules-in-github-actions/</guid><description><![CDATA[Improve GitHub Actions with efficient caching techniques for Docker, Python, Java, Node, and Go to speed up workflows]]></description><pubDate>Thu, 11 May 2023 18:30:00 GMT</pubDate><category><![CDATA[github-actions]]></category><category><![CDATA[ci-cd]]></category><category><![CDATA[cache]]></category><category><![CDATA[caching]]></category><category><![CDATA[caching strategies]]></category><category><![CDATA[workflow]]></category><content:encoded><![CDATA[<p>"Caching helps workflows run faster". The cache is created during the first run and is used for later runs, saving time and keeping the workflow efficient by speeding up the workflow runs.</p>
<h2 id="heading-cache-maven">Cache Maven</h2>
<p>Maven usually takes a longer time to build the dependencies because it needs to download all the required libraries and plugins from remote repositories. This process can be significantly sped up by caching the Maven repository. To achieve this, you can set the path to the local Maven repository and use the <code>key</code> and <code>restore-keys</code> arguments in your caching configuration. By doing so, the dependencies are stored locally after the first run and can be reused in subsequent runs, eliminating the need to download them again. This approach not only saves time but also reduces the load on remote repositories, making your build process more efficient and reliable.</p>
<pre tabindex="0"><code class="lang-yaml"><span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Cache</span> <span class="hljs-string">Maven</span>
  <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/cache@v4</span>
  <span class="hljs-attr">with:</span>
    <span class="hljs-attr">path:</span> <span class="hljs-string">~/.m2/repository</span>
    <span class="hljs-attr">key:</span> <span class="hljs-string">${{</span> <span class="hljs-string">runner.os</span> <span class="hljs-string">}}-m2-${{</span> <span class="hljs-string">hashFiles('**/pom.xml')</span> <span class="hljs-string">}}</span>
    <span class="hljs-attr">restore-keys:</span> <span class="hljs-string">|</span>
      <span class="hljs-string">${{</span> <span class="hljs-string">runner.os</span> <span class="hljs-string">}}-m2-</span>
</code></pre>
<h2 id="heading-cache-nodejs">Cache NodeJS</h2>
<p>In Unix-based Operating Systems, NodeJS npm cache files are stored under <code>~/.npm</code>. This directory contains all the cached files that npm uses to speed up subsequent installations of packages. By caching these files, you can significantly reduce the time it takes to install dependencies in future runs, as npm will reuse the cached files instead of downloading them again. This is particularly useful in continuous integration and deployment pipelines, where the same dependencies are often installed repeatedly. To cache the npm files, you can use the following configuration in your workflow:</p>
<pre tabindex="0"><code class="lang-yaml"><span class="hljs-bullet">-</span> <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/cache@v4</span>
  <span class="hljs-attr">with:</span>
    <span class="hljs-attr">path:</span> <span class="hljs-string">~/.npm</span>
    <span class="hljs-attr">key:</span> <span class="hljs-string">${{</span> <span class="hljs-string">runner.os</span> <span class="hljs-string">}}-node-${{</span> <span class="hljs-string">hashFiles('**/package-lock.json')</span> <span class="hljs-string">}}</span>
    <span class="hljs-attr">restore-keys:</span> <span class="hljs-string">|
      ${{ runner.os }}-node-
      ${{ runner.os }}-</span>
</code></pre>
<p>Alternatively, this can be used directly with the <code>setup-node</code> action.</p>
<pre tabindex="0"><code class="lang-yaml"><span class="hljs-bullet">-</span> <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/setup-node@v4</span>
  <span class="hljs-attr">with:</span>
    <span class="hljs-attr">node-version:</span> <span class="hljs-string">'20.x'</span>
    <span class="hljs-attr">cache:</span> <span class="hljs-string">'npm'</span>
    <span class="hljs-attr">cache-dependency-path:</span> <span class="hljs-string">'**/package-lock.json'</span>
</code></pre>
<h2 id="heading-cache-python">Cache Python</h2>
<p>Python dependencies can be cached to speed up workflow runs significantly. For <code>pipenv</code>, the dependencies are typically stored under <code>~/.local/share/virtualenvs</code>. This directory contains the virtual environments created by <code>pipenv</code>, which include all the necessary packages and dependencies for your Python projects. By caching this directory, you can avoid the time-consuming process of reinstalling these dependencies during each workflow run.</p>
<p><strong>for PIPENV</strong></p>
<pre tabindex="0"><code class="lang-yaml"><span class="hljs-bullet">-</span> <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/cache@v4</span>
  <span class="hljs-attr">with:</span>
    <span class="hljs-attr">path:</span> <span class="hljs-string">~/.local/share/virtualenvs</span>
    <span class="hljs-attr">key:</span> <span class="hljs-string">${{</span> <span class="hljs-string">runner.os</span> <span class="hljs-string">}}-python-${{</span> <span class="hljs-string">steps.setup-python.outputs.python-version</span> <span class="hljs-string">}}-pipenv-${{</span> <span class="hljs-string">hashFiles('Pipfile.lock')</span> <span class="hljs-string">}}</span>
</code></pre>
<p><strong>for PIP</strong>  </p>
<pre tabindex="0"><code class="lang-yaml"><span class="hljs-bullet">-</span> <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/cache@v4</span>
  <span class="hljs-attr">with:</span>
    <span class="hljs-attr">path:</span> <span class="hljs-string">~/.cache/pip</span>
    <span class="hljs-attr">key:</span> <span class="hljs-string">${{</span> <span class="hljs-string">runner.os</span> <span class="hljs-string">}}-pip-${{</span> <span class="hljs-string">hashFiles('**/requirements.txt')</span> <span class="hljs-string">}}</span>
    <span class="hljs-attr">restore-keys:</span> <span class="hljs-string">|</span>
      <span class="hljs-string">${{</span> <span class="hljs-string">runner.os</span> <span class="hljs-string">}}-pip-</span>
</code></pre>
<h2 id="heading-cache-docker">Cache Docker</h2>
<p>Significantly speed up your Docker builds by leveraging GitHub's infrastructure to store and retrieve cache layers. Docker provides multiple caching options, including Registry Cache, Inline Cache, and GitHub Cache. Each method has its own advantages, but I recommend using GitHub Cache with the <code>type=gha</code> as it is integrated seamlessly with GitHub Actions, making it easier to set up and manage within your CI/CD workflows.</p>
<pre tabindex="0"><code class="lang-yaml">    <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Build</span> <span class="hljs-string">and</span> <span class="hljs-string">push</span>
      <span class="hljs-attr">uses:</span> <span class="hljs-string">docker/build-push-action@v6</span>
      <span class="hljs-attr">with:</span>
        <span class="hljs-comment"># context: docker-springboot</span>
        <span class="hljs-attr">context:</span> <span class="hljs-string">.</span>
        <span class="hljs-attr">push:</span> <span class="hljs-literal">true</span>
        <span class="hljs-attr">tags:</span> <span class="hljs-string">|
          ${{ inputs.acr}}/${{ github.event.repository.name }}:latest
</span>        <span class="hljs-comment"># cache-from: type=registry,ref=${{ inputs.acr-url }}/${{ env.containerName }}:buildcache</span>
        <span class="hljs-comment"># cache-to: type=registry,ref=${{ inputs.acr-url }}/${{ env.containerName }}:buildcache,mode=max</span>
        <span class="hljs-attr">cache-from:</span> <span class="hljs-string">type=gha</span>
        <span class="hljs-attr">cache-to:</span> <span class="hljs-string">type=gha,mode=max</span>
</code></pre>
<h2 id="heading-cache-go">Cache Go</h2>
<p>Like other builds, Go builds can benefit significantly from caching. By storing and reusing dependencies and build artifacts, we can drastically reduce build times and improve efficiency. GitHub Actions provides a convenient way to cache Go modules and build outputs, ensuring that subsequent builds are faster and more reliable.</p>
<pre tabindex="0"><code class="lang-yaml"><span class="hljs-bullet">-</span> <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/cache@v4</span>
  <span class="hljs-attr">with:</span>
    <span class="hljs-attr">path:</span> <span class="hljs-string">|
      ~/.cache/go-build
      ~/go/pkg/mod
</span>    <span class="hljs-attr">key:</span> <span class="hljs-string">${{</span> <span class="hljs-string">runner.os</span> <span class="hljs-string">}}-go-${{</span> <span class="hljs-string">hashFiles('**/go.sum')</span> <span class="hljs-string">}}</span>
    <span class="hljs-attr">restore-keys:</span> <span class="hljs-string">|</span>
      <span class="hljs-string">${{</span> <span class="hljs-string">runner.os</span> <span class="hljs-string">}}-go-</span>
</code></pre>
<p>Similarly, we can use the caching directly using <code>setup-go</code> action</p>
<pre tabindex="0"><code class="lang-yaml">  <span class="hljs-bullet">-</span> <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/setup-go@v5</span>
    <span class="hljs-attr">with:</span>
      <span class="hljs-attr">go-version:</span> <span class="hljs-string">'1.17'</span>
      <span class="hljs-attr">check-latest:</span> <span class="hljs-literal">true</span>
      <span class="hljs-attr">cache-dependency-path:</span> <span class="hljs-string">"**/*.sum"</span>
</code></pre>
<p>You can find more information and detailed instructions on how to use the caching feature by visiting the <a target="_blank" href="https://github.com/marketplace/actions/cache">Cache action</a> page.</p>
<p>By following the above examples, you can ensure that your builds are not only faster but also more efficient and reliable. Whether you are working with Go, Node.js, Python, or any other language, the Cache action can help you to implement effective caching in your GitHub Actions workflows.</p>]]></content:encoded></item><item><title><![CDATA[Secure Password Storage in Python: A Guide to Keyring]]></title><link>https://techswitch.in/blogs/secure-password-storage-in-python-a-guide-to-keyring/</link><guid isPermaLink="true">https://techswitch.in/blogs/secure-password-storage-in-python-a-guide-to-keyring/</guid><description><![CDATA[Python keyring makes system keyring access simple and secure.]]></description><pubDate>Mon, 10 Oct 2022 18:30:00 GMT</pubDate><category><![CDATA[keyring]]></category><category><![CDATA[Python]]></category><category><![CDATA[passwords]]></category><category><![CDATA[Security]]></category><content:encoded><![CDATA[<pre tabindex="0"><code class="lang-python"><span class="hljs-keyword">import</span> os
<span class="hljs-keyword">import</span> keyring


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">set_password</span>(<span class="hljs-params">service_name, username, password</span>):</span>
    <span class="hljs-keyword">try</span>:
        <span class="hljs-comment"># Set the password in the keyring</span>
        keyring.set_password(service_name, username, password)
        print(<span class="hljs-string">"Password set for service '{}' and username '{}'"</span>.format(service_name, username))
    <span class="hljs-keyword">except</span> keyring.errors.KeyringError <span class="hljs-keyword">as</span> e:
        <span class="hljs-comment"># Handle any errors that occur during password setting</span>
        print(<span class="hljs-string">"Error setting password: '{}'"</span>.format(str(e)))


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_password</span>(<span class="hljs-params">service_name, username</span>):</span>
    <span class="hljs-keyword">try</span>:
        <span class="hljs-comment"># Retrieve the password from the keyring</span>
        password = keyring.get_password(service_name, username)
        <span class="hljs-keyword">if</span> password:
              print(<span class="hljs-string">"Password set for service '{}' and username '{}'"</span>.format(service_name, username))
        <span class="hljs-keyword">else</span>:
            print(<span class="hljs-string">"No password found '{}' and username '{}'"</span>.format(service_name, username))
    <span class="hljs-keyword">except</span> keyring.errors.KeyringError <span class="hljs-keyword">as</span> e:
        <span class="hljs-comment"># Handle any errors that occur during password retrieval</span>
        print(<span class="hljs-string">"Error retrieving password: '{}'"</span>.format(str(e)))


<span class="hljs-comment"># Usage example</span>
service_name = <span class="hljs-string">'test_svcaccount'</span>
username = <span class="hljs-string">'test-user'</span>
pssword = os.environ[<span class="hljs-string">'SECRET_PARAM'</span>]
<span class="hljs-comment">#pssword = 'fhvjh'</span>

<span class="hljs-comment"># Set the password</span>
set_password(service_name, username, pssword)

<span class="hljs-comment"># Get the password</span>
get_password(service_name, username)
</code></pre>]]></content:encoded></item><item><title><![CDATA[Agile foundation Quiz Answers]]></title><link>https://techswitch.in/blogs/agile-foundation-quiz-answers/</link><guid isPermaLink="true">https://techswitch.in/blogs/agile-foundation-quiz-answers/</guid><description><![CDATA[Disclaimer: Please use these responses as a last resort if you tried the questions several times and still couldn't pass it. 1. In the penny game exercise…]]></description><pubDate>Sun, 13 Jun 2021 18:30:00 GMT</pubDate><category><![CDATA[agile quiz]]></category><category><![CDATA[linkedin quiz]]></category><category><![CDATA[agile foundation]]></category><category><![CDATA[agile]]></category><category><![CDATA[agile development]]></category><content:encoded><![CDATA[<p><strong>Disclaimer</strong>: Please use these responses as a last resort if you tried the questions several times and still couldn't pass it.</p>
<p><strong>1. In the penny game exercise, why do you think it takes longer for one person to flip five batches of two pennies then one batch of ten pennies?</strong></p>
<p><code>You have less collaboration on one large batch of work</code></p>
<p><strong>2. How does the Pareto principle apply to product development?</strong></p>
<p><code>Often 80% of your product's value comes from 20% of your efforts</code></p>
<p><strong>3.  Your team has been working on a software project for over a year. The software is behind schedule, so the executives have pressured the managers to try an agile approach. The manager for your team says that there are three project milestones coming up in the next six months. So the manager suggests that they simply rename the three milestones Sprint 1, Sprint 2 and Sprint 3. What's the biggest challenge with this approach?</strong></p>
<p><code>It's unlikely that your team will get any benefit from an agile mindset by following existing practices</code></p>
<p><strong>4. What does it mean when you say that Scrum separates the "what" from the "how?"</strong></p>
<p><code>The product owner decides what the team will deliver, and the team decides how they'll deliver it</code></p>
<p><strong>5. You work as a software developer on an agile team. Your manager has decided that the team must work off the existing requirements documents. What's one of the main challenges with this approach?</strong></p>
<p><code>Agile teams embrace change, requirement documents are designed to limit conversation and flexibility</code></p>
<p><strong>6. Your agile team only has one database developer. So the other developers finish their tasks and then wait for their work to be Integrated into the database. This creates a backup for the database developer. But it also means that the other developers must either wait or add to a growing pile of database work. What's one possible solution to this challenge?</strong></p>
<p><code>Have the database developer train the rest of the team so there are fewer handoffs</code></p>
<p><strong>7. What does it mean that Scrum defines itself as a "framework for empirical process control?"</strong></p>
<p><code>It means that Scrum teams are encouraged to run experiments to improve the product</code></p>
<p><strong>8. What is typically not part of the product owner's role?</strong></p>
<p><code>They create the project requirements documentation</code></p>
<p><strong>9. What's the best definition of a product iteration?</strong></p>
<p><code>It is an incremental step towards delivering your product</code></p>
<p><strong>10.The business analysts at your organization often take weeks to come up with an updated set of requirements. So the senior developer for your team encourages everyone to catch up on their training while they wait for the update. If you were an agile coach for the organization, what might you do to improve the situation?</strong></p>
<p><code>You would encourage someone from the business to sit with the team to eliminate the handoff</code></p>
<p><strong>11. In the Agile Manifesto Principles 3 and 7 recommend continuous software delivery in "weeks" as a measure of progress. What's one of the ways an agile team can follow this principle?</strong></p>
<p><code>Deliver software in two-weeks iterations or "Sprints"</code></p>
<p><strong>12. Your agile team has a senior developer that's been with the organization for over a decade. Whenever something goes wrong with the product, the director pulls this person out of the team to fix the trouble. What's likely to happen on your agile team when this person is pulled from their tasks?</strong></p>
<p><code>Agile teams work in close collaboration, so this will likely create a backup</code></p>
<p><strong>13. The director of your software product development team has started a new initiative that emphasizes organizational knowledge sharing. So they purchased licenses for a social group chat platform. They asked you to keep the platform open to answer questions that are relevant to the product. Why might this be difficult for your agile team?</strong></p>
<p><code>The platform will encourage your team to multitask</code></p>
<p><strong>14. How are organizational silos related to the penny game?</strong></p>
<p><code>Organizational silos encouraged individuals to create large batches of work</code></p>
<p><strong>15. When working with an agile team, managers will often give up long term plans for predictability. So why are agile teams more predictable?</strong></p>
<p><code>Agile teams commit to delivering product increments every two weeks</code></p>
<p><strong>16. Your agile team has set up a task board with a list of user stories under the "To Do" column. the Scrum Master says that the team can pull out the cards in any order that they like. So the developers start working on user stories that they think will be completed quickly. Is the Scrum Master right?</strong></p>
<p><code>No, the agile team should always work on the highest priority user stories first</code></p>
<p><strong>17. What is not a characteristic of a self-organized team?</strong></p>
<p><code>These teams have a director who assigns everyone their tasks</code></p>
<p><strong>18. What's one of the best ways to avoid the challenges with the cone of uncertainty?</strong></p>
<p><code>Don't make all your decisions at the beginning when you know the least about the final product</code></p>
<h3 id="heading-wanna-thank-me">Wanna thank me? 👇🏼</h3>
<p><a target="_blank" href="https://www.buymeacoffee.com/techswitch"><img loading="lazy" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" /></a></p>]]></content:encoded></item><item><title><![CDATA[Beginner's Python: Unveiling Quirky and Useful Functions You Didn't know Existed]]></title><link>https://techswitch.in/blogs/beginners-python-unveiling-quirky-and-useful-functions-you-didnt-know-existed/</link><guid isPermaLink="true">https://techswitch.in/blogs/beginners-python-unveiling-quirky-and-useful-functions-you-didnt-know-existed/</guid><description><![CDATA[To pass the value for c, d, and e you will need to explicitly pass it as “key=value” named arguments: getuser() gets the current username:]]></description><pubDate>Mon, 14 Oct 2019 18:30:00 GMT</pubDate><category><![CDATA[python tricks]]></category><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[python beginner]]></category><category><![CDATA[py]]></category><category><![CDATA[python tips]]></category><content:encoded><![CDATA[<h3 id="heading-1-function-to-make-a-noun-adjective-from-a-verb-or-an-adverb-from-a-noun-adjective">1. Function to make a noun (adjective) from a verb or an adverb from a noun (adjective)</h3>
<pre tabindex="0"><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">verbing</span>(<span class="hljs-params">s</span>):</span>
    returns iflen(s) &lt; <span class="hljs-number">3</span> elses + (<span class="hljs-string">'ing'</span>, <span class="hljs-string">'ly'</span>)[<span class="hljs-string">'ing'</span> ins]
<span class="hljs-meta">&gt;&gt;&gt; </span>verbing(<span class="hljs-string">'help'</span>)
helping
<span class="hljs-meta">&gt;&gt;&gt; </span>verbing(<span class="hljs-string">'helping'</span>)
helpingly
</code></pre>
<h3 id="heading-2-use-a-bare-asterisk-in-function-parameter-lists-to-force-the-caller-to-use-keyword-arguments-for-certain-parameters">2. use a bare “*” asterisk in function parameter lists to force the caller to use keyword arguments for certain parameters</h3>
<pre tabindex="0"><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span>(<span class="hljs-params">a, b, *, c=<span class="hljs-string">'x'</span>, d=<span class="hljs-string">'y'</span>, e=<span class="hljs-string">'z'</span></span>):</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> <span class="hljs-string">'Hello'</span>
</code></pre>
<p>To pass the value for c, d, and e you will need to explicitly pass it as “key=value” named arguments:</p>
<pre tabindex="0"><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-string">'p'</span>, <span class="hljs-string">'q'</span>, <span class="hljs-string">'v'</span>)
TypeError: f() takes <span class="hljs-number">2</span> positional arguments but <span class="hljs-number">5</span> were given
<span class="hljs-meta">&gt;&gt;&gt; </span>f(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, c=<span class="hljs-string">'p'</span>, d=<span class="hljs-string">'q'</span>,e=<span class="hljs-string">'v'</span>)
<span class="hljs-string">'Hello'</span>
</code></pre>
<h3 id="heading-3-getpass-module-provides-a-platform-independent-way-to-enter-a-password-in-a-command-line-program-without-echoing">3. getpass module provides a platform-independent way to enter a password in a command-line program without echoing</h3>
<pre tabindex="0"><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> getpass
<span class="hljs-meta">&gt;&gt;&gt; </span>password = getpass.getpass()
Password:
<span class="hljs-meta">&gt;&gt;&gt; </span>password
<span class="hljs-string">'alohomora'</span>
</code></pre>
<p><code>getuser()</code> gets the current username:</p>
<pre tabindex="0"><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>getpass.getuser()
<span class="hljs-string">'sirius_black'</span>
</code></pre>
<h3 id="heading-4-if-the-fractional-component-of-the-number-is-halfway-between-two-integers-one-of-which-is-even-and-the-other-odd-then-round-returns-the-even-this-kind-of-rounding-is-called-rounding-to-even-or-bankers-rounding">4. if the fractional component of the number is halfway between two integers, one of which is even and the other odd, then <code>round()</code> returns the even. This kind of rounding is called rounding to even (or banker’s rounding)</h3>
<pre tabindex="0"><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>round(<span class="hljs-number">0.5</span>)
<span class="hljs-number">0</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>round(<span class="hljs-number">2.4</span>)
<span class="hljs-number">2</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>round(<span class="hljs-number">2.5</span>)
<span class="hljs-number">2</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>round(<span class="hljs-number">2.6</span>)
<span class="hljs-number">3</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>round(<span class="hljs-number">3.5</span>)
<span class="hljs-number">4</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>round(<span class="hljs-number">4.5</span>)
<span class="hljs-number">4</span>
</code></pre>
<h3 id="heading-5-the-built-in-function-sysgetsizeof-returns-the-size-of-an-object-in-bytes-the-object-can-be-any-type-of-object">5. The built-in function <code>sys.getsizeof()</code> returns the size of an object in bytes. The object can be any type of object</h3>
<pre tabindex="0"><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>sys.getsizeof(<span class="hljs-number">1</span>)
<span class="hljs-number">28</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>sys.getsizeof([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>])
<span class="hljs-number">88</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>sys.getsizeof(<span class="hljs-string">''</span>)
<span class="hljs-number">49</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>sys.getsizeof(<span class="hljs-string">'P'</span>)
<span class="hljs-number">50</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>sys.getsizeof(<span class="hljs-string">'Py'</span>)
<span class="hljs-number">51</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>sys.getsizeof(<span class="hljs-string">'Python'</span>)
<span class="hljs-number">55</span>
</code></pre>]]></content:encoded></item><item><title><![CDATA[Understanding Memory Leaks in Java JVM]]></title><link>https://techswitch.in/blogs/understanding-memory-leaks-in-java-jvm/</link><guid isPermaLink="true">https://techswitch.in/blogs/understanding-memory-leaks-in-java-jvm/</guid><description><![CDATA[First of all Memory leak is not sweeping Unused objects, It is Sweeping referenced objects. Memory leak is a common memory issue that can result in an…]]></description><pubDate>Fri, 06 Sep 2019 18:30:00 GMT</pubDate><category><![CDATA[Java]]></category><category><![CDATA[Memory Leak]]></category><category><![CDATA[memory-management]]></category><category><![CDATA[jvm]]></category><content:encoded><![CDATA[<p>First of all Memory leak is not sweeping Unused objects, It is Sweeping referenced objects.</p>
<p><img loading="lazy" src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719429631709/261d105d-8f08-4660-bd51-634f609f5f32.jpeg" alt class="image--center mx-auto" /></p>
<h3 id="heading-definition">Definition:</h3>
<p><strong>Memory leak</strong> is a common memory issue that can result in an OutOfMemory error.<br />In Java, memory leaks can occur even with automatic Garbage Collection (GC).<br />GC removes objects that are no longer referenced.</p>
<p>However, if an object is not used but still referenced, GC will not remove it, potentially causing memory leaks in the JVM.</p>
<h3 id="heading-conclusion">Conclusion:</h3>
<p>Understanding memory leaks in the Java JVM is crucial for maintaining optimal application performance. Despite Java's automatic Garbage Collection, memory leaks can still occur when objects that are no longer needed remain referenced. This can lead to an OutOfMemory error, causing the application to crash or behave unpredictably. By identifying and addressing these leaks, developers can ensure more efficient memory usage and improve the stability and reliability of their Java applications.</p>]]></content:encoded></item></channel></rss>
