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
Diary

[Mac] Port 5000 Unavailable in Monterey

1 Mins read

Developing with port 5000 but getting an error?

Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5000 -> 0.0.0.0:0: listen tcp 0.0.0.0:5000: bind: address already in use

lsof -i:5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ControlCe 85856 user10 26u IPv4 0x4ff853972c8bedd 0t0 TCP *:commplex-main (LISTEN)
ControlCe 85856 user10 27u IPv6 0x4ff85430b21e97d 0t0 TCP *:commplex-main (LISTEN)

What’s this thing?

Turns out Monterey added an AirPlay feature that’s hijacking the port.

System Preference > Sharing > AirPlay Receiver > Uncheck it

That’ll free it up, but thinking ahead, other people will hit the same issue. Better to just change the dev side to use a different port.

Read more
Diary

[Mac] Terminal and Operation not permitted – Configure for Developer Use

1 Mins read

macOS Monterey
Version 12.4

■1. Change “SIP” to disabled
(Disable System Integrity Protection: SIP)

Shut down Mac once
At startup, press “command + R”, release when the mark appears
Recovery mode starts
From the menu bar at the top, select “Open Terminal”

# Command: Check if "csrutil status" returns "enabled"
csrutil status

# Command: Run "csrutil disable" (changes take effect only after reboot!)
csrutil disable

# Command: Reboot Mac with "reboot"
reboot

■2. Set Terminal to full file access
After normal startup
Go to “System Preferences”

“Security & Privacy”

“Privacy” tab, then “Full Disk Access” on the right

Check the “Terminal” checkbox On

■3. Delete “.DS_Store” and prevent creation

# Delete all .DS_Store files
sudo find / -name ".DS_Store" -delete
# Restart Finder
Killall Finder

# Prevent .DS_Store files from being created at all
defaults write com.apple.desktopservices DSDontWriteNetworkStores True
# Restart Finder
Killall Finder

■4. If not needed, disable iCloud sync

Read more