❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

🎯 PostgreSQL Zero to Hero with Parottasalna – 2 Day Bootcamp (FREE!) πŸš€

2 March 2025 at 07:09

Databases power the backbone of modern applications, and PostgreSQL is one of the most powerful open-source relational databases trusted by top companies worldwide. Whether you’re a beginner or a developer looking to sharpen your database skills, this FREE bootcamp will take you from Zero to Hero in PostgreSQL!

What You’ll Learn?

βœ… PostgreSQL fundamentals & installation

βœ… Postgres Architecture
βœ… Writing optimized queries
βœ… Indexing & performance tuning
βœ… Transactions & locking mechanisms
βœ… Advanced joins, CTEs & subqueries
βœ… Real-world best practices & hands-on exercises

This intensive hands on bootcamp is designed for developers, DBAs, and tech enthusiasts who want to master PostgreSQL from scratch and apply it in real-world scenarios.

Who Should Attend?

πŸ”Ή Beginners eager to learn databases
πŸ”Ή Developers & Engineers working with PostgreSQL
πŸ”Ή Anyone looking to optimize their SQL skills

πŸ“… Date: March 22, 23 -> (Moved to April 5, 6)
⏰ Time: Will be finalized later.
πŸ“ Location: Online
πŸ’° Cost: 100% FREE πŸŽ‰

πŸ”— RSVP Here

Prerequisite

  1. Checkout this playlist of our previous postgres session https://www.youtube.com/playlist?list=PLiutOxBS1Miy3PPwxuvlGRpmNo724mAlt

πŸŽ‰ This bootcamp is completely FREE – Learn without any cost! πŸŽ‰

πŸ’‘ Spots are limited – RSVP now to reserve your seat!

Learning Notes #70 – RUFF An extremely fast Python linter and code formatter, written in Rust.

9 February 2025 at 11:00

In the field of Python development, maintaining clean, readable, and efficient code is needed.

The Ruff Python package is a faster linter and code formatter designed to boost code quality and developer productivity. Written in Rust, Ruff stands out for its blazing speed and comprehensive feature set.

This blog will delve into Ruff’s features, usage, and how it compares to other popular Python linters and formatters like flake8, pylint, and black.

What is Ruff?

Ruff is an extremely fast Python linter and code formatter that provides linting, code formatting, and static code analysis in a single package. It supports a wide range of rules out of the box, covering various Python standards and style guides.

Key Features of Ruff

  1. Lightning-fast Performance: Written in Rust, Ruff is significantly faster than traditional Python linters.
  2. All-in-One Tool: Combines linting, formatting, and static analysis.
  3. Extensive Rule Support: Covers rules from flake8, isort, pyflakes, pylint, and more.
  4. Customizable: Allows configuration of rules to fit specific project needs.
  5. Seamless Integration: Works well with CI/CD pipelines and popular code editors.

Installing Ruff


# Using pip
pip install ruff

# Using Homebrew (macOS/Linux)
brew install ruff

# Using UV
uv add ruff

Basic Usage

1. Linting a python file

# Lint a single file
ruff check app.py

# Lint an entire directory
ruff check src/

2. Auto Fixing Issues

ruff check src/ --fix

3. Formatting Code

While Ruff primarily focuses on linting, it also handles some formatting tasks

ruff format src/

Configuration

Ruff can be configured using a pyproject.toml file

[tool.ruff]
line-length = 88
exclude = ["migrations"]
select = ["E", "F", "W"]  # Enable specific rule categories
ignore = ["E501"]          # Ignore specific rules

Examples

import sys
import os

print("Hello World !")


def add(a, b):
    result = a + b
    return a

x= 1
y =2
print(x+y)

def append_to_list(value, my_list=[]):
    my_list.append(value)
    return my_list

def append_to_list(value, my_list=[]):
    my_list.append(value)
    return my_list

  1. Identifying Unused Imports
  2. Auto-fixing Imports
  3. Sorting Imports
  4. Detecting Unused Variables
  5. Enforcing Code Style (PEP 8 Violations)
  6. Detecting Mutable Default Arguments
  7. Fixing Line Length Issues

Integrating Ruff with Pre-commit

To ensure code quality before every commit, integrate Ruff with pre-commit

Step 1: Install Pre-Commit

pip install pre-commit

Step 2: Create a .pre-commit-config.yaml file

repos:
  - repo: https://github.com/charliermarsh/ruff-pre-commit
    rev: v0.1.0  # Use the latest version
    hooks:
      - id: ruff

Step 3: Install the Pre-commit Hook

pre-commit install

Step 4: Test the Hook

pre-commit run --all-files

This setup ensures that Ruff automatically checks your code for linting issues before every commit, maintaining consistent code quality.

When to Use Ruff

  • Large Codebases: Ideal for projects with thousands of files due to its speed.
  • CI/CD Pipelines: Reduces linting time, accelerating build processes.
  • Code Reviews: Ensures consistent coding standards across teams.
  • Open Source Projects: Simplifies code quality management.
  • Pre-commit Hooks: Ensures code quality before committing changes.

Integrating Ruff with CI/CD

name: Lint Code

on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.10'
    - name: Install Ruff
      run: pip install ruff
    - name: Lint Code
      run: ruff check .

Ruff is a game-changer in the Python development ecosystem. Its unmatched speed, comprehensive rule set, and ease of use make it a powerful tool for developers aiming to maintain high code quality.

Whether you’re working on small scripts or large-scale applications, Ruff can streamline your linting and formatting processes, ensuring clean, efficient, and consistent code.

Learning Notes #67 – Build and Push to a Registry (Docker Hub) with GH-Actions

28 January 2025 at 02:30

GitHub Actions is a powerful tool for automating workflows directly in your repository.In this blog, we’ll explore how to efficiently set up GitHub Actions to handle Docker workflows with environments, secrets, and protection rules.

Why Use GitHub Actions for Docker?

My Code base is in Github and i want to tryout gh-actions to build and push images to docker hub seamlessly.

Setting Up GitHub Environments

GitHub Environments let you define settings specific to deployment stages. Here’s how to configure them:

1. Create an Environment

Go to your GitHub repository and navigate to Settings > Environments. Click New environment, name it (e.g., production), and save.

2. Add Secrets and Variables

Inside the environment settings, click Add secret to store sensitive information like DOCKER_USERNAME and DOCKER_TOKEN.

Use Variables for non-sensitive configuration, such as the Docker image name.

3. Optional: Set Protection Rules

Enforce rules like requiring manual approval before deployments. Restrict deployments to specific branches (e.g., main).

Sample Workflow for Building and Pushing Docker Images

Below is a GitHub Actions workflow for automating the build and push of a Docker image based on a minimal Flask app.

Workflow: .github/workflows/docker-build-push.yml


name: Build and Push Docker Image

on:
  push:
    branches:
      - main  # Trigger workflow on pushes to the `main` branch

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    environment: production  # Specify the environment to use

    steps:
      # Checkout the repository
      - name: Checkout code
        uses: actions/checkout@v3

      # Log in to Docker Hub using environment secrets
      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}

      # Build the Docker image using an environment variable
      - name: Build Docker image
        env:
          DOCKER_IMAGE_NAME: ${{ vars.DOCKER_IMAGE_NAME }}
        run: |
          docker build -t ${{ secrets.DOCKER_USERNAME }}/$DOCKER_IMAGE_NAME:${{ github.run_id }} .

      # Push the Docker image to Docker Hub
      - name: Push Docker image
        env:
          DOCKER_IMAGE_NAME: ${{ vars.DOCKER_IMAGE_NAME }}
        run: |
          docker push ${{ secrets.DOCKER_USERNAME }}/$DOCKER_IMAGE_NAME:${{ github.run_id }}

To Actions on live: https://github.com/syedjaferk/gh_action_docker_build_push_fastapi_app/actions

Idea Implementation #1 – Automating Daily Quiz Delivery to Telegram with GitHub Actions

25 December 2024 at 17:53

Telegram Group: https://t.me/parottasalna

Github Repo: https://github.com/syedjaferk/daily_quiz_sender

In this blog, I’ll walk you through the journey of transitioning from a PythonAnywhere server to GitHub Actions for automating the delivery of daily quizzes to a Telegram group https://t.me/parottasalna . This implementation highlights the benefits of GitHub Actions to run a cronjob.

Problem Statement

I wanted to send a daily quiz to a Telegram group to keep members engaged and learning. Initially, I hosted the solution on a PythonAnywhere server.

Some of the limitations are,

  1. Only one cron job is allowed for a free account.
  2. For every x days, i need to visit the dashboard and reactive my account to make it work.

Recently, started learning the Github Actions . So thought of leveraging the schedule mechanism in it for my usecase.

Key Features of My Solution

  • Automated Scheduling: GitHub Actions triggers the script daily at a specified time.
  • Secure Secrets Management: Sensitive information like Telegram bot tokens and chat IDs are stored securely using GitHub Secrets.
  • Serverless Architecture: No server maintenance; everything runs on GitHub’s infrastructure.

Implementation Overview

I am not explaining the code here. Please checkout the repo https://github.com/syedjaferk/daily_quiz_sender

The core components of the implementation include

  1. A Python script (populate_questions.py) to create questions and store each question in the respective directory.
  2. A Python script (runner.py) which takes telegram_bot_url, chat_id and category as input to read the correct question from the category directory and send the message.
  3. A GitHub Actions workflow to automate execution.

Workflow Yaml File


name: Docker Quiz Sender

on:
  schedule:
    - cron: "30 4 * * *"

  workflow_dispatch:

jobs:
  run-python:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

      - name: Run script with secrets0
        run: python runner.py --telegram_url ${{ secrets.TELEGRAM_BOT_URL }} --chat_id ${{ secrets.CHAT_ID }} --category docker

Benefits of the New Implementation

  1. Cost-Effectiveness: No server costs thanks to GitHub’s free tier for public repositories.
  2. Reliability: GitHub Actions ensures the script runs on schedule without manual intervention.
  3. Security: GitHub Secrets securely manages sensitive credentials.
  4. Centralization: All code, configuration, and automation reside in a single repository.

Lessons Learned

  • Environment Variables: Using environment variables for secrets keeps the code clean and secure.
  • Error Handling: Adding error-handling mechanisms in the script helps debug issues effectively.
  • Time Zones: GitHub Actions uses UTC; be mindful when scheduling tasks for specific time zones.

Future Enhancements

  1. Dynamic Quizzes: Automate quiz generation from a database (sqlite3) or external API.
  2. Logging: Store logs as GitHub Actions artifacts for better debugging and tracking.
  3. Failure Notifications: Notify via Telegram or email if the workflow fails.
  4. Extend for other categories

You can check out the project here. Feel free to fork it and adapt it to your needs!

Learning Notes #2 – Automate Email Notifications in GitHub Actions

20 December 2024 at 07:07

Today, i was checking youtube videos on github actions. I came across a video on sending a mail via a Github Action https://www.youtube.com/watch?v=SkD7KQ3KzZs&t=108s. This blog is just an implementation of the video.

What am i going to do ?

I need to send a mail using my gmail id via Github

What prior information you need ?

  1. Gmail SMTP Server address – smtp.gmail.com
  2. Gmail SMTP port – 465
  3. Email username – your mail id.
  4. Email password – App Password from Google. https://support.google.com/accounts/answer/185833?hl=en.

YAML File


name: "Send Mail"

on:
  workflow_dispatch:

jobs:
  mail:
    runs-on: ubuntu-latest
    steps:
      - name: Print Name
        run: echo "Sending Mail"
    
      - name: Send Mail
        if: ${{ always() }}
        uses: dawidd6/action-send-mail@v3
        with:
          server_address: smtp.gmail.com
          server_port: 465

          username: ${{ secrets.EMAIL_USERNAME }}
          password: ${{ secrets.EMAIL_PASSWORD }}

          subject: ${{ github.job }} job of ${{ github.repository }} has  ${{ github.status }}
          body: "Test Message in Github"
          to:  syedjafer1997@gmail.com
          from: Syed Jafer K



My Github Run: https://github.com/syedjaferk/gh_actions_templates/actions/runs/12426929593

Learning Notes #01 – Github Actions

19 December 2024 at 16:31

GitHub Actions is a CI/CD tool that automates workflows directly from your GitHub repository. I am writing this notes for my future self.

Github: https://github.com/syedjaferk/gh_action_docker_build_push_fastapi_app

0. Github Actions

Github Actions is a managed CI/CD pipeline offering. It provides free runners for running the code.

1. Workflow, Jobs, Steps

A workflow is a collection of jobs defined in a .yml file inside .github/workflows. Each workflow consists of jobs, and jobs have steps.


name: My First Workflow
on: push
jobs:
  example-job:
    runs-on: ubuntu-latest
    steps:
      - name: Print a message
        run: echo "Hello, GitHub Actions!"

2. Availability and Pricing

GitHub Actions is free for public repositories and has free usage limits for private repositories, depending on the plan. Paid plans increase these limits. For detailed pricing, visit the GitHub Actions pricing page.

3. First workflow with basic echo commands

Start with a workflow triggered by any push event. Here’s a simple example,


name: Echo Workflow
on: push
jobs:
  echo-job:
    runs-on: ubuntu-latest
    steps:
      - name: Say Hello
        run: echo "Hello from my first workflow!"

4. Multiline Shell Commands

You can use the | symbol to write multiline shell commands.


name: Push Event Workflow
on:
  push:
    branches:
      - main
jobs:
  push-job:
    runs-on: ubuntu-latest
    steps:
      - name: On Push
        run: echo "Code pushed to main branch!"

5. A new workflow with push events

Workflows can be triggered by specific events like push. This example triggers only on push to the main branch.


name: Push Event Workflow
on:
  push:
    branches:
      - main
jobs:
  push-job:
    runs-on: ubuntu-latest
    steps:
      - name: On Push
        run: echo "Code pushed to main branch!"

6. Using actions in workflow (Marketplace and Open Source)

GitHub Actions Marketplace offers reusable actions. For example, using the actions/checkout action.


steps:
  - name: Checkout Code
    uses: actions/checkout@v3

7. Checkout in code

Checking out your code is essential to access the repository content. Use actions/checkout


steps:
  - name: Checkout Code
    uses: actions/checkout@v3

8. Adding workflow job steps

Each job can have multiple steps.


jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Step 1 - Checkout Code
        uses: actions/checkout@v3
      - name: Step 2 - Run a Script
        run: echo "Script running in step 2."

9. Jobs in Parallel and Sequential

To run jobs in parallel, define them without dependencies. For sequential jobs, use needs.

Parallel Jobs:

jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Job 1"

  job2:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Job 2"

Sequential Jobs:


jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Job 1"

  job2:
    runs-on: ubuntu-latest
    needs: job1
    steps:
      - run: echo "Job 2 after Job 1"

10. Using Multiple Triggers

A workflow can be triggered by multiple events.


on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

11. Expressions and Context Objects

Expressions are used to access variables and contexts like github or env.


steps:
  - name: Use an Expression
    run: echo "Triggered by ${{ github.event_name }}"

Setting Up Pre-Commit Hooks in GitHub: Ensuring Code Quality and Consistency

By: angu10
11 July 2023 at 21:55

Introduction:
Pre-commit hooks are a powerful tool that can help maintain code quality, enforce style guidelines, and prevent common mistakes in software development. In this blog post, we will explore how to set up pre-commit hooks for your entire team using GitHub. Specifically, we will discuss the process of setting up pre-commit hooks for popular tools such as Black, pre-commit-hooks, Prettier, and pylint.

Table of Contents:

1.What are Pre-Commit Hooks?
2.Benefits of Pre-Commit Hooks
3.Setting Up Pre-Commit Hooks in GitHub
a.Prerequisites
b.Configuring the pre-commit Configuration File
c.Installing and Initializing Pre-Commit
d.Adding Pre-Commit Hooks

  1. Commonly Used Pre-Commit Hooks a.Black b.pre-commit-hooks c.Prettier d.pylint
  2. Customizing Pre-Commit Hooks
  3. Running Pre-Commit Hooks
  4. Conclusion

Sure! Here are the installation steps and code snippets for each section in the table of contents:

1. What are Pre-Commit Hooks?

Pre-commit hooks are scripts or actions that are automatically executed before a commit is made to a version control system. They help enforce code quality standards and catch potential issues before they are committed.

2. Benefits of Pre-Commit Hooks

Using pre-commit hooks in your development workflow offers several benefits:

  • Ensuring code quality and consistency
  • Enforcing style guidelines and formatting standards
  • Preventing common mistakes or issues
  • Catching potential bugs or vulnerabilities early
  • Facilitating collaboration and reducing code review efforts

3. Setting Up Pre-Commit Hooks in GitHub

a. Prerequisites

  • Git installed on your system
  • A project directory set up with a Git repository

b. Configuring the pre-commit Configuration File

Create a file called .pre-commit-config.yaml in the root of your project directory. This file will contain the configuration for your Pre-Commit hooks.

c. Installing and Initializing Pre-Commit

pip install pre-commit
pre-commit init

d. Adding Pre-Commit Hooks

In the .pre-commit-config.yaml file, define the hooks you want to use. For example, to use the Black code formatter:

repos:
  - repo: https://github.com/psf/black
    rev: <version>
    hooks:
      - id: black

Replace <version> with the desired version of Black.

4. Commonly Used Pre-Commit Hooks

a. Black

Installation:

pip install black

Configuration in .pre-commit-config.yaml:

repos:
  - repo: https://github.com/psf/black
    rev: <version>
    hooks:
      - id: black

b. pre-commit-hooks

Installation:

pip install pre-commit-hooks

Configuration in .pre-commit-config.yaml:

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: <version>
    hooks:
      - id: check-json

c. Prettier

Installation:

npm install --save-dev prettier

Configuration in .pre-commit-config.yaml:

repos:
  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: <version>
    hooks:
      - id: prettier
    files: \.(json|markdown|md|yaml|yml)$

d. pylint

Installation:

pip install pylint

Configuration in .pre-commit-config.yaml:

repos:
  - repo: https://github.com/PyCQA/pylint
    rev: <version>
    hooks:
      - id: pylint
        name: pylint
        entry: pylint
        language: system
        types: [python]
        env:
          PYTHONPATH: "./"

5. Customizing Pre-Commit Hooks

You can customize pre-commit hooks by modifying the .pre-commit-config.yaml file. This includes specifying hook options, excluding files or directories, or defining additional hooks or scripts.

6. Running Pre-Commit Hooks

To run pre-commit hooks before a commit, simply make a commit using Git. The hooks will automatically be executed. To manually run the hooks without making a commit, use the command pre-commit run --all-files.

7. Conclusion

In this blog post, we have explored how to set up and use Pre-Commit hooks in GitHub. By following these steps and configuring the hooks, you can ensure code quality, enforce style guidelines, and catch potential issues early in your development workflow. Pre-Commit hooks offer numerous benefits and can greatly improve collaboration and code consistency within your team.

❌
❌