Skip to content

2023

Removing Directories in Python

Remove Empty Directories in Python

To remove an empty directory, you can use os.rmdir() with os and Path.rmdir() with pathlib.

import os

directory_path = '/path/to/empty_directory'

try:
    os.rmdir(directory_path)
    print(f"The directory '{directory_path}' has been successfully removed.")
except OSError as e:
    print(f"Error: {directory_path} : {e.strerror}")
from pathlib import Path

directory_path = Path('/path/to/empty_directory')

try:
    directory_path.rmdir()
    print(f"The directory '{directory_path}' has been successfully removed.")
except OSError as e:
    print(f"Error: {directory_path} : {e.strerror}")

How to deploy a Streamlit Application on Hugging Face

In this guide, we'll walk through the steps to deploy a Streamlit app using the Hugging Face platform. For demonstration purposes, we'll create an app that utilizes the Python module Pix2Tex. Users will be able to upload an image and get the corresponding LaTeX formula along with a rendered version.

Prerequisites

  1. Create a virtual environment:
python3 -m venv myenv
source myenv/bin/activate
python -m venv myenv
./myenv/Scripts/activate

Flask based File Hosting (web app & api & python module & cli app)

This guide will walk you through creating a basic file hosting web application using Flask, a lightweight web framework for Python. The application will include features such as user login, file uploads, and file listing. We'll also explore adding a simple API for interacting with the application.

Prerequistes

  • python >=3.9

Setup Environment

  1. Create a requirements.txt file:
python-slugify
python-dotenv
Flask~=2.0.1

Nesting Repositories with Git Submodules: A Newbie's Guide

Introduction

Are you facing the challenge of handling multiple code pieces scattered across different repositories in your project, unsure how to seamlessly integrate them?

For developers new to the concept, managing disparate repositories within a single project can be overwhelming. Git submodules offer a guiding light, acting as a map through the maze of organizing and linking these separate codebases or libraries within your projects.

Real-Life Scenario: Aligning Frontend and Backend Strategies

Back in 2022, I found myself as the lead developer overseeing the backend team, while collaborating closely with a talented frontend developer responsible for crafting engaging user interfaces.

Our teams operated independently, each excelling in our specialized domains. However, this independence led to distinct branch strategies. The backend team adopted a unique approach, separate from the frontend's strategy.

Over time, this divergence in branch strategies caused disparities between our repositories' states. Aligning frontend changes with the evolving backend structures became a complex task. Ensuring seamless integration between our frontend branches and specific backend versions posed challenges.

Simple guide to using Docker on Windows 10 and access from WSL 2

Introduction

For a heavy linux user like me, using windows also mean find a door to work with a linux distro. There are several options to gauge from the situation. I usually need both docker and wsl2 on the computer. And i've installed this many times.

docker-logo

So, this is a very straight forward tutorial on docker and wsl2 installation and configuration on windows10 or 11.

Prerequisites

  • Windows 10 Pro, Enterprise, or Education edition.
  • WSL 2 enabled on your Windows machine.
  • Docker Desktop for Windows installed.

Step-by-Step Guide

  1. Install Docker Desktop for Windows:

  2. Enable WSL 2:

    Enable docker for wsl2

  3. Set wsl default version to 2:

    • Open PowerShell as an administrator and run the following command:
    wsl --set-default-version 2
    

Guide to Applying query on you mongodb atlas hosted database from command line

Introduction

Often when you're using a database in a dev project, you want to access it quickly to check for modifications. When you're working with mysql database, you have a client that can help you with that. But what to do when you're using mongo db ? In this tutorial, i present how to access, from command line, your databased hosted with mongo db atlas. Then i showcase basic still important query examples. It should work also for those hosted locally.

Prerequistes

  • Node js
  • a mongo db database, offline or locally served

Download and Install Mongosh

You can download and install mongosh from the MongoDB website or using package managers like npm or yarn. Make sure you have Node.js installed on your system before proceeding.

Personally, using windows, i've downloaded it (and installed the setup) from the website, put the bin file (containing mongosh.exe) into environment variables and read a bit of the docu. However, using ubuntu, i've tested both approch, installing using apt-get and using nodejs.

Let's use the Package Manage option, as it is a more straightforward approach

npx mongosh --version
yarn dlx mongosh --version

Guide to Installing MySQL and Connecting to Databases

Introduction

MySQL is a popular relational database management system used for storing and managing data. To get started, you'll need to install MySQL, set it up, and then connect to databases. Here's a comprehensive guide to help you through the process.

Installation Process

To install MySQL, follow these steps:

  • update the package lists
sudo apt-get update
  • install MySQL
sudo apt-get install mysql-server

Deploying any Web application with Nginx: Example of Flask

Introduction

You have created your flask application. How nice ! Now, you want to go a step further and deploy it. For most hosting services, you have nice interfaces to deploy your python applications with support for flask. But sometimes, you only have access via ssh to the server.

This is a very straigthforward tutorial on how to do it.

This tutorial also applies to any web server you can run on local but want to deploy

Step 1: Install Nginx and Flask

Make sure you have Nginx and Flask installed on your server. If not, install them using the appropriate package manager for your operating system.

Step 2: Configure Nginx

Create a new Nginx configuration file for your Flask app in the /etc/nginx/sites-available/ directory. For example, you could name it myapp.conf. Edit the file and add the following configuration:

Run an application forever on linux made easy: Case of a javascript project

Introduction

If you're looking to turn your application into a background process, you have come to the right tutorial, always using the fastest way.

Instead of just writing theory, we we use a real world example i've worked on.

To run a Java application as a background process and keep it running forever, you can use a process manager like systemd on Linux. Here's how you can set up a systemd service to run your Java application:

Certainly! Here are the steps named as per their actions:

Step 1: Create Service File

Create a new systemd service file for your Java application using a text editor:

sudo nano /etc/systemd/system/myapp.service

Step 2: Configure Service

Paste the following configuration into the file, replacing <jar-file-name> with the name of your JAR file:

Managing Local Modifications and Remote Changes in Git

Introduction

Git is, without discussion, a powerful version control system that enables collaborative development.

Ever found yourself in a twist trying to mix changes you made with updates from others in Git?

It's like trying to blend your cooking style with someone else's recipe without making a mess. Git's awesome for team coding, but when your tweaks clash with online updates, how do you sort it out ?

Indeed, when local modifications clash with remote changes, navigating these conflicts efficiently becomes crucial. Let's explore different strategies to handle this situation effectively.