Diary

Running Swagger Editor Locally with Docker

1 Mins read

swagger

A tool you can use for API design document management. It generates sample code as JSON, and behaves like Postman for testing.

More and more projects are using it lately.

Starting a local server (example with 3 instances, useful when you have 3 external API servers, etc.)

docker pull swaggerapi/swagger-editor
docker run -d -p 8090:8080 swaggerapi/swagger-editor
docker run -d -p 8091:8080 swaggerapi/swagger-editor
docker run -d -p 8092:8080 swaggerapi/swagger-editor

Open http://localhost:8090 etc. in your browser

Copy and paste the yaml file content from your repository into the left window of the browser alongside your source control

Test with get, post, etc.

※You’ll need some understanding of API specifications

Often used together with OpenAPI

This tool reads yaml files in API design format and automatically generates I/O source code in your specified language. However, it’s not all roses—it sometimes generates incorrect code, so you’ll often run into situations where you need to do some debugging and cleanup.

 

 

Read more
Diary

Preparing for AlmaLinux 8 GPG Key Change

1 Mins read

dnf command error

dnf update

AlmaLinux 8 - BaseOS 485 kB/s | 3.4 kB 00:00 
Importing GPG key 0xC21AD6EA: 
Userid : "AlmaLinux <packager@almalinux.org>" 
Fingerprint: E53C F5EF 91CE B0AD 1812 ECB8 51D6 647E C21A D6EA 
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-AlmaLinux 
Is this ok? [y/N]: y 
Key import succeeded 
Importing the key didn't help. Is the key wrong?

The key has been updated

AlmaLinux 8 GPG Key Change

Starting January 12, 2024, AlmaLinux 8 RPM packages and repo metadata will be signed with an updated GPG key. Follow the steps below to continue receiving updates without issues after the switch.

If you want to verify that your system already contains the new AlmaLinux 8 GPG key and trusts it, just import it.

sudo rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux
Read more
Diary

# Setting up MongoDB and Mongo Express with Docker (docker-compose)

1 Mins read

Access from browser:

http://localhost:8081

ME_CONFIG_MONGODB_ADMINUSERNAME: root 
ME_CONFIG_MONGODB_ADMINPASSWORD: password

Tried logging in with the specified ID and password in the browser but couldn’t log in? Hmm…

Turned out Basic authentication environment variables for the browser were needed.

ME_CONFIG_BASICAUTH_USERNAME: admin
ME_CONFIG_BASICAUTH_PASSWORD: password

Create a “docker-compose.yml” file (code below)

Run “docker-compose up -d” command in the terminal


version: '3.1'

services:

  mongo:
    container_name: mongo-dev
    image: mongo
    restart: always
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: password
    volumes:
      - ./configdb:/data/configdb
      - mongoDataStore:/data/db

  mongo-express:
    container_name: mongo-express
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: password
      ME_CONFIG_MONGODB_URL: mongodb://root:password@mongo:27017/
      ME_CONFIG_BASICAUTH_USERNAME: admin
      ME_CONFIG_BASICAUTH_PASSWORD: password

volumes:
  mongoDataStore:
    driver: local

Also verify connection from Mac terminal (make sure testDB and such are created beforehand via express, etc.)

mongosh "mongodb://root:password@localhost:27017/testDB?authSource=admin"

Current Mongosh Log ID: 65be609e7384r68762b10b0
Read more
Diary

Python Script to Convert All JPEG Files in a Specified Directory to PNG Format

1 Mins read
# Python script to convert all JPEG files in a specified directory to PNG format
# Python 3
# pip install Pillow
#
# Command below does not delete original files
# python jpeg-png.py
#
# Command below deletes original files
# python jpeg-png.py rm=1


from PIL import Image
import os
import sys


def convert_jpeg_to_png(directory, remove_jpeg=False):
for root, dirs, files in os.walk(directory):
for file in files:
if file.lower().endswith('.jpg') or file.lower().endswith('.jpeg'):
jpeg_path = os.path.join(root, file)
png_path = os.path.splitext(jpeg_path)[0] + '.png'


try:
image = Image.open(jpeg_path)
image.save(png_path, format='PNG')
print(f"{jpeg_path}を{png_path}に変換しました")


if remove_jpeg:
os.remove(jpeg_path)
print(f"{jpeg_path}を削除しました")
except Exception as e:
print(f"{jpeg_path}の変換に失敗しました: {e}")


# Get and specify current directory
current_directory = os.getcwd()


# Check command line arguments
remove_jpeg = False
if len(sys.argv) > 1 and sys.argv[1] == 'rm=1':
remove_jpeg = True


convert_jpeg_to_png(current_directory, remove_jpeg)
Read more
Diary

Python script to convert all PNG files in a specified directory to JPEG format

1 Mins read
Python script to convert all PNG files in a specified directory to JPEG format
# Python script to convert all PNG files in a specified directory to JPEG format
# python3
# pip install Pillow
#
# Don't delete the file below
# python png-jpeg.py
#
# Delete the file below
# python png-jpeg.py rm=1


from PIL import Image
import os
import sys


def convert_png_to_jpeg(directory, remove_png=False):
for root, dirs, files in os.walk(directory):
for file in files:
if file.lower().endswith('.png'):
png_path = os.path.join(root, file)
jpeg_path = os.path.splitext(png_path)[0] + '.jpg'


try:
image = Image.open(png_path)
rgb_im = image.convert('RGB')
rgb_im.save(jpeg_path, quality=100)
print(f"{png_path}を{jpeg_path}に変換しました")


if remove_png:
os.remove(png_path)
print(f"{png_path}を削除しました")
except Exception as e:
print(f"{png_path}の変換に失敗しました: {e}")


# Get and specify the current directory
current_directory = os.getcwd()


# Check command line arguments
remove_png = False
if len(sys.argv) > 1 and sys.argv[1] == 'rm=1':
remove_png = True


convert_png_to_jpeg(current_directory, remove_png)

 

Read more