Day 56 – Raising Your Own Exceptions Sometimes it’s you who needs to throw the red flag 🚩 Use raise to enforce your own rules. def withdraw(amount): if amount <= 0: raise ValueError("Withdrawal amount must be positive!") print(f"Withdrawing ${amount}") withdraw(-50) 🧠 Output: ValueError: Withdrawal amount must be positive! 💡 Proactive exceptions prevent bigger bugs later. This is how real-world apps maintain data integrity and user safety. 👉 Where would you use a custom exception in your code? #Python #Debugging #CleanCode #DeveloperLife
Gouse Basha Shaik’s Post
More Relevant Posts
-
“When your code compiles first try… check if you’re dreaming.” Every developer knows this moment. You hit Run, the screen flickers, and suddenly, zero errors. Your brain immediately enters panic mode. "Wait… what did I forget?" Because if you’re feeling too confident, do this one thing: assume your code is pranking you. This could be: 👉 Double-check your imports (Python loves surprising you) 👉 Re-read that one function you wrote at midnight 👉 Confirm the API key isn’t hardcoded like last time 👉 Run tests again… and again 👉 Ask yourself, “What did I miss?” Real-world example? A dev wrote a function that worked perfectly. Tests passed. CI passed. He deployed it proudly. Next morning: the app crashed because he used the test database in production. (Yes… it compiled. No… it wasn’t safe.) The lesson? Clean compile ≠ clean code. Every “zero errors” moment is just the universe telling you… “Kid, the lesson isn’t over yet.” #ProgrammingHumor #TechStories #DeveloperLife #CodeCulture #WebDevelopment #AppDevelopment #Xlorit
To view or add a comment, sign in
-
-
🚀 Progress on fastapi-maker! I went from version 0.0.1 (just a placeholder on PyPI) to 0.1.1 with two functional commands: fam init → generates the base project structure (FastAPI + Alembic + .env + DB config) fam create <entity> → creates complete modules: ORM model, DTOs, repository, service, and router (already integrated into the app!) It's still in development, but it already allows you to launch CRUD APIs in seconds, with less boilerplate and more focus on logic. In addition already has integration with Alembic and its migration system! I'll soon continue improving the codebase files, help with API documentation, and much more. #FastAPI #Python #DeveloperTools #OpenSource #Backend #API #CLI #Automation
To view or add a comment, sign in
-
-
🎭 Day 279: Faking It (the Smart Way) with mock What if your function depends on an external API, but the API’s down? Or you don’t want to send real network requests while testing? That’s where mock from unittest steps in — it lets you simulate objects or functions. It’s like a stunt double for your code. 🎬 👉 Example: from unittest.mock import MagicMock get_weather = MagicMock(return_value="Sunny ☀️") print(get_weather()) # Output: Sunny ☀️ 💡 Pro tip: Use mocks when testing code that interacts with APIs, files, or databases to isolate logic and prevent real operations. 🔹 Challenge: Mock an API response to test your data parsing logic — no internet required! #Python #Mocking #Testing #DevTips
To view or add a comment, sign in
-
𝗖𝗼𝗺𝗽𝘂𝘁𝗲𝗿𝘀 𝗔𝗿𝗲𝗻'𝘁 𝗦𝗺𝗮𝗿𝘁 Most people think computers are 𝘪𝘯𝘵𝘦𝘭𝘭𝘪𝘨𝘦𝘯𝘵. As a developer, I know better. I was building a file sorter and writing tests when I noticed something odd: the tests kept failing on "tar.gz" files but worked perfectly for everything else. The problem? I was using file.suffix to get the extension. It worked great for single extensions like .pdf or .jpg, but completely failed for compound extensions like .tar.gz. Why? Because: 𝗳𝗶𝗹𝗲.𝘀𝘂𝗳𝗳𝗶𝘅 𝗿𝗲𝘁𝘂𝗿𝗻𝘀 .𝗴𝘇 (𝗼𝗻𝗹𝘆 𝘁𝗵𝗲 𝗹𝗮𝘀𝘁 𝗽𝗮𝗿𝘁) 𝗳𝗶𝗹𝗲.𝘀𝘂𝗳𝗳𝗶𝘅𝗲𝘀 𝗿𝗲𝘁𝘂𝗿𝗻𝘀 ['.𝘁𝗮𝗿', '.𝗴𝘇'] (𝗮𝗹𝗹 𝗽𝗮𝗿𝘁𝘀) The fix was simple: "".𝗷𝗼𝗶𝗻(𝗳𝗶𝗹𝗲.𝘀𝘂𝗳𝗳𝗶𝘅𝗲𝘀) 𝗕𝘂𝘁 𝗵𝗲𝗿𝗲'𝘀 𝘁𝗵𝗲 𝗿𝗲𝗮𝗹 𝗹𝗲𝘀𝘀𝗼𝗻: the computer did exactly what it was told to do. It wasn't wrong. I just failed to communicate my intent properly. Without those tests, this bug would have been invisible:files silently miscategorized, no errors thrown, just wrong behavior lurking in production. 𝗧𝗵𝗶𝘀 𝗶𝘀 𝘄𝗵𝘆 𝘁𝗲𝘀𝘁𝗶𝗻𝗴 𝗺𝗮𝘁𝘁𝗲𝗿𝘀: Not because computers make mistakes, but because we do. Computers are fast, precise, and literal. But smart? Never. They'll happily execute our misunderstandings at lightning speed. Our job is to close the gap between what we think we're asking for and what we're actually asking for. #SoftwareDevelopment #Testing #Python #CodingLessons #DeveloperLife #automation
To view or add a comment, sign in
-
Nothing hurts user experience more than "We're sorry, the service is temporarily unavailable." Especially when it's a third-party API you don't control. Instead of hoping for the best, I wrap all external API calls with this resilient Python decorator. It automatically handles retries with exponential backoff, ensuring your app remains resilient to temporary outages. 💪 Resilience: Survives network blips, API throttling, and temporary outages ⚡ Smart Backoff: Won't overwhelm the API with immediate retries 🔧 Reusable: One decorator protects all your API calls 📝 Logging: See exactly what's failing and when. Pro Tip: Combine this with circuit breakers for enterprise-grade resilience! What's the flakiest API you've ever had to integrate with? War stories welcome in the comments! 🍿 #Python #API #Microservices #Reliability #SoftwareArchitecture #BackendDevelopment #WebDevelopment #Resilience
To view or add a comment, sign in
-
-
🚀 DSA Progress – Day 94 ✅ Problem #338: Counting Bits 🧠 Difficulty: Easy | Topics: Bit Manipulation, Dynamic Programming 🔍 Approach: Implemented a Dynamic Programming approach to efficiently count the number of 1 bits in every number from 0 to n without converting numbers to binary strings. Step 1 (Initialization): Create an array result of size n + 1, initialized to zeros. Base cases: result[0] = 0 → Binary of 0 is 0, so 0 ones. result[1] = 1 → Binary of 1 is 1, so 1 one. Step 2 (Even–Odd Relation): For every number i from 2 to n: If i is even, the number of 1s = result[i // 2] (same as half of i, because last bit is 0). If i is odd, the number of 1s = result[i // 2] + 1 (same as half, plus 1 for the last bit). Step 3 (Iterative Build): Use the above relation to fill the result array for all numbers up to n. 🕒 Time Complexity: O(n) Each number is processed once. 💾 Space Complexity: O(n) We store bit counts for all numbers from 0 to n. 📁 File: https://lnkd.in/ghuw8Vea 📚 Repo: https://lnkd.in/g8Cn-EwH 💡 Learned: This problem deepened my understanding of bitwise patterns and how small observations (like even–odd relationships) can lead to elegant DP-based optimizations. It showed how dynamic programming can simplify repetitive bit-counting logic and achieve linear time solutions. ✅ Day 94 complete — counted every single bit of progress, one 1️⃣ at a time! 💡⚙️💻✨ #LeetCode #DSA #Python #DynamicProgramming #BitManipulation #CountBits #100DaysOfCode #DailyCoding #InterviewPrep #GitHubJourney
To view or add a comment, sign in
-
💡 Day 38 of 100 — Ones and Zeroes (#LeetCode 474) Today’s problem brought back the classic 0/1 Knapsack vibes but with a binary twist. It’s about choosing the largest subset of binary strings under limits for zeros (m) and ones (n). At first glance, it looks like a simple counting problem, but it quickly becomes a dynamic programming puzzle about balancing two constraints at once. 🧠 What I figured out Each string can be treated as an “item” with two costs number of 0s and number of 1s. The goal is to maximize the number of items chosen within the given limits. The trick is iterating backward in the DP array to avoid overwriting earlier results, a common knapsack technique. 💻 My thought process I initialized a 2D DP table where dp[i][j] represents the maximum subset size achievable with at most i zeros and j ones. Then, for every string, I counted its zeros and ones, and updated the DP table from the back to preserve correct state transitions. 📊 Complexity: Time — O(len(strs) × m × n) Space — O(m × n) 💬 Reflection This problem reminded me that even simple patterns like zeros and ones can hide deep optimization challenges. DP problems always test patience but when the logic clicks, it’s pure satisfaction. #100DaysOfLeetCode #Day38 #LeetCodeJourney #DSA #Coding
To view or add a comment, sign in
-
-
🔍 Day 30 | Shift Happens (and That’s Beautiful) Today’s LeetCode challenge was #848 – Shifting Letters 🌀 At first glance, it looks like a simple “shift characters” task — but under the hood, it’s a neat example of prefix-sum logic meets modular arithmetic. 💡 The Problem: For each index i, shift the first i+1 letters by shifts[i] times — wrapping around from 'z' to 'a'. 🧠 The Trick: If we start from the end of the string and move backward, we can keep a cumulative shift sum that already accounts for all later shifts. This avoids repeatedly looping over the prefix and keeps our time complexity O(n) instead of O(n²). ⚙️ Approach: Traverse from right to left Keep adding each shift to a running total (totalShift) Apply totalShift % 26 to shift the current character efficiently Update the string using a StringBuilder 💨 Why It’s Optimal: ✅ Single pass — linear time ✅ Constant extra space ✅ Clean and scalable even for large inputs (up to 10⁵ length! Sometimes the cleanest solutions come from flipping your perspective — literally shifting your direction Shishir chaurasiya and PrepInsta #LeetCode #CodingChallenge #Java #Algorithms #ProblemSolving #LearningEveryday
To view or add a comment, sign in
-
-
🗓️ Day 48 / 100 – House Robber (LeetCode #198) 💡 Today’s Challenge Today’s problem was House Robber, another classic Dynamic Programming problem that builds on logical decision-making. The goal: find the maximum amount of money you can rob without robbing two adjacent houses. This problem perfectly shows how DP helps in balancing choices and consequences — you decide whether to rob the current house (and skip the previous one) or skip it to include the next. 🔍 Key Learnings Dynamic Programming is about optimizing decisions step-by-step. The “non-adjacent” rule introduces real-world constraints into logic. Storing sub-results saves time and simplifies complex problems. 💭 Thought of the Day Life — like coding — is about smart choices. Sometimes, skipping an immediate gain (a nearby house 🏠) can lead to greater rewards later. Problem-solving isn’t always about doing more — it’s about doing smarter. 🔗 Problem Link:https://lnkd.in/gMCjampn #100DaysOfCode #Day48 #LeetCode #Python #DynamicProgramming #ProblemSolving #Algorithms #CodingChallenge #PythonProgramming #CodeEveryday #TechGrowth #LearningJourney #SmartDecisions #HouseRobber
To view or add a comment, sign in
-
-
💡 Leetcode #1716 – Calculate Money in Leetcode Bank Today’s problem is a fun simulation question that tests our logical thinking and pattern observation skills. 🧠 Problem Summary: - Hercy wants to save money for his car. - On the first Monday, he deposits $1. - Every next day of the same week, he adds $1 more than the previous day. - On every new Monday, he starts with $1 more than the previous Monday. So, the pattern looks like this: - Week 1: 1 2 3 4 5 6 7 - Week 2: 2 3 4 5 6 7 8 - Week 3: 3 4 5 6 7 8 9 ... The task is to find the total amount saved after n days. ✨ Logic Used: - Keep track of how much money is deposited at the start of each week (week_start). - For every week, sum up the deposits for up to 7 days (or remaining days). - Increment week_start after every week. 🧩 Example: - If n = 10, Week 1 → 1+2+3+4+5+6+7 = 28 Week 2 → 2+3+4 = 9 ✅ Total = 37 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) 💬 This problem reminds us that sometimes, simple observation and pattern recognition can solve what looks like a tricky problem at first glance. #LeetCode #DSA #CodingChallenge #Python #ProblemSolving #LearnDaily #100DaysOfCode
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development