Skip to content

Instantly share code, notes, and snippets.

@AFirooz
Last active May 30, 2025 16:29
Show Gist options
  • Save AFirooz/17f21f7e869ed5e5123bbe742d6e3713 to your computer and use it in GitHub Desktop.
Save AFirooz/17f21f7e869ed5e5123bbe742d6e3713 to your computer and use it in GitHub Desktop.
Misc Learn
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import multiprocessing as mp
import time
from tqdm import tqdm
""" See Obsidian for more details.
A more complicated example:
https://github.com/mCodingLLC/VideosSampleCode/blob/master/videos/104_multiprocessing_pool/multiprocessing_pool.py
"""
def process_task(func_args):
data, other = func_args
other = other if other else 0
# Replace this with the actual computation for each loop iteration
t = 25-data if data < 25 else data - 25
time.sleep(0.25*t)
# print(f"Processed {data=}")
return data*other
if __name__ == "__main__":
print("Number of cpu : ", mp.cpu_count())
# List of inputs for the loop
inputs = list(range(50))
other = list(range(0, 100, 2))
func_args = [(x, y) for x, y in zip(inputs, other)]
results = []
start = time.time()
# Create a pool of workers (defaults to all available cores)
with mp.Pool(processes=30) as pool:
# Map the function to the inputs, distributing tasks across CPUs
# results = pool.map(process_task, func_args)
# results = pool.map_async(process_task, func_args).get()
# results = list(pool.imap(process_task, func_args)) # Convert iterator to list. Much slower than map
# results = list(pool.imap_unordered(process_task, func_args))
# tqdm need to be passed an iterable, not a generator
# Source: https://stackoverflow.com/a/41921948/12315585
with tqdm(total=len(inputs)) as pbar:
for result in pool.imap_unordered(process_task, func_args):
pbar.update()
pbar.refresh()
# Do something with the result
results.append(result)
print('\ntime taken: ', time.time() - start, '\n')
if isinstance(results, list):
print(results)
else:
for r in results:
print(r)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Code Quality & Organization

  • Clean Code: Write readable, maintainable code with meaningful names and clear structure

  • SOLID Principles: five fundamental principles of object-oriented programming and design that help reduce coupling, increase cohesion, and create more maintainable, flexible, and scalable software:

    1. S - Single Responsibility Principle (SRP)

      A class should have only one job or responsibility. Example: Instead of a User class that handles both user data and email sending, separate them into User and EmailService classes.

    2. O - Open/Closed Principle (OCP)

      Software entities should be open for extension but closed for modification. You should be able to add new functionality without changing existing code.

      How? Use interfaces and inheritance to add new payment methods without modifying existing payment processing code.

    3. L - Liskov Substitution Principle (LSP)

      Objects of a superclass should be replaceable with objects of a subclass without breaking the application.

      Example: If you have a Bird class, a Penguin subclass shouldn't break the application if it can't implement a fly() method that all birds are expected to have.

    4. I - Interface Segregation Principle (ISP)

      Clients should not be forced to depend on interfaces they don't use. Create specific, focused interfaces rather than large, monolithic ones.

      Example: Instead of one large Worker interface with methods like work(), eat(), and sleep(), create separate interfaces like Workable, Eatable, and Sleepable.

    5. D - Dependency Inversion Principle (DIP)

      High-level modules should not depend on low-level modules. Both should depend on abstractions (interfaces), not concrete implementations.

      Example: A PaymentProcessor should depend on a PaymentGateway interface, not directly on specific implementations like StripePayment or PayPalPayment.

  • DRY (Don't Repeat Yourself): Avoid code duplication

  • Code Reviews: Peer review process to catch bugs and improve code quality

Development Practices

  • Version Control: Use Git with meaningful commit messages and branching strategies
  • Test-Driven Development (TDD): Write tests before implementing features
  • Unit Testing: Comprehensive test coverage with automated testing
  • Documentation: Clear API docs, README files, and inline comments

Architecture & Design

  • Microservices Architecture: Break applications into small, independent services
  • Design Patterns: Use proven solutions for common problems
  • Separation of Concerns: Keep different functionalities isolated
  • API Design: RESTful APIs with consistent naming conventions

DevOps & Deployment

  • CI/CD Pipelines: Automated build, test, and deployment processes
  • Infrastructure as Code: Manage infrastructure through code
  • Containerization: Use Docker for consistent environments
  • Monitoring & Logging: Track application performance and errors

Project Management

  • Agile Methodologies: Iterative development with regular feedback
  • Code Standards: Consistent formatting and style guidelines
  • Security Best Practices: Input validation, authentication, encryption
  • Performance Optimization: Profiling and optimizing bottlenecks Agile Methodologies are iterative approaches to software development that emphasize flexibility, collaboration, and customer satisfaction. Here's a deep dive:

Core Agile Values (Agile Manifesto)

  • Individuals and interactions over processes and tools
  • Working software over comprehensive documentation
  • Customer collaboration over contract negotiation
  • Responding to change over following a plan

Popular Agile Frameworks

Scrum

  • Sprints: 1-4 week development cycles
  • Roles: Product Owner, Scrum Master, Development Team
  • Ceremonies: Sprint Planning, Daily Standups, Sprint Review, Retrospective
  • Artifacts: Product Backlog, Sprint Backlog, Increment

Kanban

  • Visual workflow management using boards
  • Continuous delivery without fixed iterations
  • Work-in-progress (WIP) limits
  • Focus on flow optimization

Extreme Programming (XP)

  • Pair programming and code reviews
  • Test-driven development (TDD)
  • Continuous integration
  • Simple design and refactoring

Key Agile Practices

Sprint Planning & Estimation

  • Story points for effort estimation
  • Planning poker for team consensus
  • Definition of Done criteria

Daily Communication

  • Stand-up meetings (What did you do? What will you do? Any blockers?)
  • Transparent progress tracking
  • Quick issue resolution

Continuous Improvement

  • Sprint retrospectives to identify improvements
  • Adapt processes based on team feedback
  • Metrics tracking (velocity, burndown charts)

Customer Involvement

  • Regular demos and feedback sessions
  • User stories written from customer perspective
  • Iterative requirement refinement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment