MoreRSS

site iconShinChvenModify

A full-stack TypeScript/JavaScript web developer, and also build mobile apps.
Please copy the RSS to your reader, or quickly subscribe to:

Inoreader Feedly Follow Feedbin Local Reader

Rss preview of Blog of ShinChven

Deploy n8n with Docker Compose

2025-10-30 23:00:00

n8n is a powerful workflow automation tool that allows you to connect different services and automate tasks. While n8n offers a cloud version, self-hosting provides more control and flexibility. The recommended way to self-host n8n is by using Docker. In this guide, we will walk through how to deploy n8n using Docker Compose, which simplifies the management of multi-container Docker applications.

Quick Glance: docker-compose.yml for n8n

For those who want to get straight to it, here is a docker-compose.yml file for a basic n8n setup with a PostgreSQL database.

version: '3.8'

services:
  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
      - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - n8n_data:/home/node/.n8n
    depends_on:
      - postgres

  postgres:
    image: postgres:13
    restart: always
    environment:
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  n8n_data:
  postgres_data:

You will also need a .env file in the same directory to store your credentials:

# PostgreSQL
POSTGRES_DB=n8n
POSTGRES_USER=n8nuser
POSTGRES_PASSWORD=yoursecurepassword

# n8n Basic Auth
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=yoursecureadminpassword

# Timezone
GENERIC_TIMEZONE=Asia/Shanghai

Prerequisites

Before you start, make sure you have Docker and Docker Compose installed on your system.

Deploying n8n

  1. Create a directory for your n8n setup and navigate into it.

    mkdir n8n-deployment
    cd n8n-deployment
    
  2. Create the docker-compose.yml file and paste the content from the "Quick Glance" section above.

  3. Create the .env file and add your desired credentials.

  4. Start the services using Docker Compose. bash docker compose up -d This command will pull the necessary Docker images and start the n8n and PostgreSQL containers in the background.

Accessing n8n

Once the containers are running, you can access your n8n instance by navigating to http://localhost:5678 in your web browser. You will be prompted to set up an owner account for your n8n instance.

Updating n8n

To update your n8n instance to the latest version, follow these steps:

  1. Pull the latest n8n image:

    docker compose pull n8n
    
  2. Restart the services: bash docker compose up -d Docker Compose will recreate the n8n container with the new image while keeping your data stored in the Docker volumes.

By using Docker Compose, you can easily deploy, manage, and update your self-hosted n8n instance. This setup provides a robust and scalable environment for your workflow automations.

Count Words in LaTeX with TeXcount

2025-10-30 18:00:00

Introduction

For anyone writing academic papers, articles, or books in LaTeX, meeting word count requirements is a common task. Unlike traditional word processors, counting words in a LaTeX document can be tricky due to the presence of commands and environments. TeXcount is a powerful command-line utility specifically designed for this purpose. It intelligently parses your LaTeX document to provide an accurate word count, along with other useful statistics.

Quick Command

For a quick summary of word counts in your LaTeX file, run the following command in your terminal:

texcount -inc your_document.tex

Detailed Guide to TeXcount

Installation

TeXcount is a Perl script and is included by default in most major TeX distributions, such as TeX Live, MiKTeX, and MacTeX. You likely already have it installed. You can verify this by opening your terminal and typing:

texcount -v

If it's installed, you will see version information. If not, you should install it through your TeX distribution's package manager.

Basic Usage

The simplest way to use TeXcount is to run it on your main .tex file:

texcount your_document.tex

This will produce a detailed breakdown of words in the text, headers, and captions, as well as counts of headers, floats, and math environments.

Common Options

TeXcount offers a variety of options to customize its output.

Including External Files

If your document is split into multiple files using \input{} or \include{}, you need to tell TeXcount to include them in the count. The -inc flag does exactly that:

texcount -inc your_document.tex

This is one of the most common and useful options.

Getting a Total Sum

Often, you just want the final word count. The -total option will provide a sum of all word counts:

texcount -inc -total your_document.tex

This will give you a clean, single number for the total words.

Character and Encoding

To count characters instead of words, use the -char option. If your document uses UTF-8 encoding (which is standard for most modern documents), it's good practice to specify it with -utf8:

texcount -char -utf8 your_document.tex

Advanced Usage

TeXcount can also be instructed to ignore specific parts of your document. For example, you can add special comments in your LaTeX file to control TeXcount:

  • %TC:ignore - Start ignoring text from this point.
  • %TC:endignore - Resume counting.
  • %TC:insert N - Add N words to the count.

For example, to exclude a paragraph from the word count:

\section{Introduction}
This paragraph will be counted.

%TC:ignore
\begin{comment}
This entire block, including the text inside, will be ignored by TeXcount.
It's useful for notes or sections you want to exclude from the final count.
\end{comment}
%TC:endignore

This paragraph will be counted again.

By mastering these simple commands and options, you can get a reliable word count for your LaTeX documents, making it easier to adhere to submission guidelines.

Effortless LaTeX: Your Guide to a Local Setup with MacTeX and VS Code on macOS

2025-10-29 20:00:00

For academics, researchers, and students, LaTeX is the gold standard for producing beautifully typeset documents, from scientific papers to dissertations. However, the traditional workflow involving clunky, outdated editors can feel cumbersome.

This guide will show you how to create a modern, streamlined, and highly efficient LaTeX environment on your Mac using the power of MacTeX and the versatility of Visual Studio Code with the LaTeX Workshop extension.

Why This Setup?

  • Modern Editor: Use the feature-rich VS Code, which you might already use for programming.
  • Live Preview: See your rendered PDF update in real-time as you type.
  • Code Completion (IntelliSense): Get smart suggestions for commands and environments.
  • Error Highlighting: Quickly spot and debug issues in your LaTeX source.
  • Integrated Terminal & Git: Manage your entire project from a single window.

Prerequisites

  1. A Mac computer.
  2. Visual Studio Code: If you don't have it, download it here.
  3. Homebrew: The easiest way to install MacTeX. If you don't have Homebrew, install it by running this command in your terminal: bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 1: Install MacTeX

MacTeX is a complete TeX distribution for macOS. It includes everything you need to start compiling LaTeX documents. The simplest way to install it is via Homebrew.

Open your terminal and run:

brew install --cask mactex

Note: MacTeX is a large installation (over 5GB), so this may take some time. It includes the TeX Live backend, GUI applications like TeXShop, and the tlmgr package manager.

Step 2: Install the LaTeX Workshop Extension for VS Code

Now, let's equip VS Code with the necessary tools.

  1. Open Visual Studio Code.
  2. Go to the Extensions view (click the icon on the sidebar or press Cmd+Shift+X).
  3. Search for LaTeX Workshop.
  4. Click Install. The publisher is James Yu.

LaTeX Workshop is incredibly powerful and will automatically detect your MacTeX installation.

Step 3: Create Your First LaTeX Document

  1. Create a new folder for your project.

  2. Open this folder in VS Code (File > Open Folder...).

  3. Create a new file named document.tex.

  4. Paste the following minimal LaTeX code into the file:

    \documentclass{article}
    
    \title{My First LaTeX Document with VS Code}
    \author{Your Name}
    \date{\today}
    
    \begin{document}
    
    \maketitle
    
    \section{Introduction}
    Hello, world! This is my first document created using MacTeX and the LaTeX Workshop extension in Visual Studio Code.
    
    It's easy to write math formulas like \( E = mc^2 \).
    
    \subsection{Features}
    Here are some things I like:
    \begin{itemize}
        \item Live preview
        \item Syntax highlighting
        \item Easy compilation
     பகிர்
    \end{itemize}
    
    \end{document}
    

Step 4: Compile and View Your Document

This is where the magic happens.

  1. Build: With the document.tex file open, click the Build LaTeX project button (a green play icon) in the top-right corner of the editor, or open the Command Palette (Cmd+Shift+P) and type LaTeX Workshop: Build LaTeX project.
  2. View: To see the PDF, click the View LaTeX PDF button (a magnifying glass icon) next to the build button, or use the Command Palette to find LaTeX Workshop: View LaTeX PDF.

The PDF will open in a new tab right inside VS Code!

Pro Tip: Auto-build on Save By default, LaTeX Workshop is configured to automatically recompile your document every time you save the .tex file. This gives you a near-instant live preview of your changes.

Troubleshooting

  • "Compiler not found": If LaTeX Workshop can't find your pdflatex compiler, make sure MacTeX is installed correctly. You can specify the path in VS Code's settings.json if needed, but this is rarely necessary with a standard Homebrew installation.
  • "Package not found" (e.g., fancyhdr.sty): MacTeX comes with thousands of packages, but if you need a rare or new one, you can install it using the TeX Live Manager (tlmgr). Open your terminal and run: bash sudo tlmgr install <packagename>

Conclusion

You now have a professional-grade LaTeX environment on your Mac. This setup combines the typesetting power of TeX with the modern conveniences of VS Code, creating a workflow that is both efficient and enjoyable. Happy typesetting!

Create Remote Git Repo from Commandline

2025-08-22 05:59:02

Introduction

Creating a new Git repository is a common task for developers. While you can always do this from the web interface of GitHub or GitLab, using command-line tools can significantly speed up your workflow, especially when you're already working in the terminal. In this post, we'll explore how to use gh for GitHub and glab for GitLab to create a remote repository and push your local project to it.

Using gh to Create a GitHub Repository

The gh command is the official GitHub CLI tool. If you don't have it installed, you can follow the installation instructions on the official website.

Once installed and authenticated, you can create a new repository with the following command:

gh repo create

This command will start an interactive prompt, asking for the repository name, visibility (public, private, or internal), and whether you want to clone it or push an existing local repository.

To create a repository and push your current local folder, you can run:

gh repo create <repo-name> --public --source=. --remote=origin
git push -u origin main

Replace <repo-name> with your desired repository name. The --source=. flag tells gh to use the current directory as the source, and --remote=origin sets the remote name.

Using glab to Create a GitLab Repository

For GitLab users, glab is the official CLI tool. You can find installation instructions on its official documentation.

After installation and authentication, creating a new repository is just as simple.

To create a new repository interactively, run:

glab repo create

This will guide you through the process of naming your repository and setting its visibility.

To create a repository and push your current local project, you can use:

# Official gitlab
glab repo create <your-namespace>/<repo-name> --public
# Private host gitlab
glab repo create <your-private-host>/<your-namespace>/<repo-name> --private
# Add remote and push
git remote add origin "https://<host>/<your-username>/<repo-name>.git"
git push -u origin main

Replace <repo-name> and <your-username> accordingly. glab will create the remote repository, and then you can add it as a remote and push your code.

Conclusion

Using command-line tools like gh and glab can make your development workflow more efficient. With just a few commands, you can initialize a local repository, create a remote one, and push your code without ever leaving the terminal.

Top 6 Tools to Turn Code into Beautiful Diagrams

2025-08-19 19:06:29

Why turn code into diagrams

Good diagrams compress complex ideas into shapes, arrows, and frames the way code compresses logic. When diagrams are generated from code, they can be versioned, reviewed, and kept in sync with the system. This post compares six popular options and shows minimal working examples so you can pick the right tool for your team and workflow.

How to choose

Think about three things: where the diagram will live, how often it will change, and who must edit it. If you want diagrams embedded in docs and PRs, a text-first format like Mermaid or PlantUML works well. If you prefer diagrams sourced from real code, Diagrams (Python) or Go Diagrams integrate with your language toolchain. For quick sketches, ASCII is frictionless. For brainstorming and note-taking, Markmap turns Markdown into interactive mind maps.

Diagrams (Python)

Diagrams is a Python library that renders architecture diagrams from code. It excels at cloud/system architecture where you want provider icons, clusters, and consistent styling. Because it is Python, you can compose generators, reuse components, and test the code that produces your diagram.

# pip install diagrams
from diagrams import Diagram, Cluster
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB

with Diagram("web-service", show=False):
    with Cluster("App Tier"):
        app = [EC2("app1"), EC2("app2")]
    db = RDS("primary-db")
    lb = ELB("edge")
    lb >> app >> db

Use it when you need repeatable, code-reviewed architecture diagrams with cloud icons and when Python is already in your stack.

Go Diagrams

Go Diagrams follows a similar idea for the Go ecosystem. It lets you define nodes and edges in Go, then renders to SVG/PNG. Its strengths are type safety, simple composition, and a natural fit for Go services where developers prefer staying in one language.

package main

func main() {
    // Pseudocode-style example to convey intent
    g := NewDiagram("payments")
    api := g.Node("API")
    svc := g.Node("Service")
    db  := g.Node("DB")
    api.Connect(svc)
    svc.Connect(db)
    g.Render("payments.svg")
}

Pick it if your team writes Go and wants diagrams generated within the same toolchain, for CI-friendly outputs and code reviews.

Mermaid

Mermaid renders diagrams from a concise Markdown-like syntax, supported by many platforms (including GitHub, GitLab, and numerous docs tools). It is ideal for documentation-driven teams because diagrams live beside prose and update via simple edits.

flowchart TD
A[Client] --> B[API Gateway]
B --> C{Auth?}
C -- yes --> D[Service]
C -- no  --> E[401]
D --> F[(DB)]

Use Mermaid for architectural sketches, flows, and sequence diagrams directly in Markdown files, wikis, and PR descriptions.

PlantUML

PlantUML is a mature, text-based system supporting many diagram types: sequence, component, class, state, and more. It provides powerful styling, includes, and skinparams for large documentation codebases.

@startuml
actor User
participant "Web App" as Web
database DB
User -> Web: POST /login
Web -> DB: query credentials
DB --> Web: result
Web --> User: 200 OK
@enduml

Choose PlantUML when you need breadth of diagram types, fine-grained styling, and modular includes across a large doc set.

ASCII diagrams

ASCII diagrams are plain text drawings you can create in any editor and keep in code blocks. They render everywhere, diff cleanly, and require no toolchain. They are perfect for quick design notes, README snippets, and terminal-first workflows.

+---------+      +----------+      +--------+
| Client  | ---> |  Proxy   | ---> |  API  |
+---------+      +----------+      +--------+
                      |                 |
                      v                 v
                   Cache            Database

Reach for ASCII when you value speed, universality, and zero dependencies over polish.

Markmap

Markmap converts Markdown lists into interactive mind maps. It is excellent for brainstorming, note-taking, and structuring research. Because the source is Markdown, it works well with existing docs and knowledge bases.

# Project Kickoff
- Scope
  - MVP
  - Out of scope
- Architecture
  - Services
  - Data flow
- Risks
  - Scaling
  - Compliance

Use Markmap to ideate and present hierarchies during early phases, then evolve those notes into formal docs.

When to use which

If you want code-native, icon-rich architecture diagrams that stay in sync with cloud resources, prefer Diagrams (Python) or Go Diagrams depending on your language. If you need frictionless diagrams in docs and PRs with broad platform support, pick Mermaid. If you require advanced diagram types, skinning, and modularization, choose PlantUML. For fast, dependency-free sketches, use ASCII. For early-stage thinking and presentations built from notes, adopt Markmap.

Workflow tips

Keep diagram sources in the same repo as the system they describe so changes travel with code. Add a CI step to render and validate diagrams to prevent drift. Create reusable templates for common topologies and enforce naming and styling conventions. For mixed environments, standardize on a text-first format like Mermaid or PlantUML for documentation and complement it with language-native generators (Diagrams or Go Diagrams) for architecture that benefits from code reuse.

Closing thoughts

Treat diagrams as living artifacts rather than static images. When they are generated from code or text, they become reviewable, testable, and easy to evolve. Pick one primary format for your team and add others only when they clearly reduce friction or improve clarity.

Setting up a Global Hotkey to Summon iTerm2

2025-08-09 23:07:37

Need quick access to your terminal? iTerm2 offers a seamless way to summon it with a system‑wide hotkey—just like a drop‑down terminal. Here's how to set it up.

Method 1: Create a Dedicated Hotkey Window

  1. Open iTerm2 → Preferences → Keys.
  2. Click Create a Dedicated Hotkey Window. This generates a special profile (often named Hotkey Window) and opens configuration options for it.
  3. In the configuration panel, you can set:
  • Whether the hotkey window stays open when losing focus (pin window).
  • If it should automatically reopen when iTerm2 is activated.
  • Whether it's a floating window, and whether to animate show/hide transitions.
  1. Customize the profile’s appearance or behavior under Profiles → Hotkey Window, such as window size, transparency, or full‑screen layout.

This creates a dedicated, always-accessible, overlay-style terminal window—ideal for quick access.


Method 2: Use an Existing Profile as a Hotkey Window

  1. Go to Preferences → Profiles, and select the profile you want to make hotkey-enabled.
  2. Navigate to the Keys tab within that profile.
  3. Enable “A hotkey opens a dedicated window with this profile”.
  4. Click Configure Hotkey Window to assign the hotkey and tweak window properties.

Now, pressing your chosen hotkey will toggle this profile in a dedicated window—without creating a new one.


Summary of Both Methods

Method Steps Pros
Dedicated Hotkey Window Preferences → Keys → Create Dedicated Hotkey Window → Configure options Fast setup, always-available overlay
Existing Profile Preferences → Profiles → (Profile) → Keys → Enable hotkey window → Configure hotkey Reuses your customized profile and settings

Final Thoughts

Both approaches work well—choose whichever fits your workflow:

  • Want a quick, uniform terminal open with a global hotkey? Go with the Dedicated Hotkey Window.
  • Prefer customizing your own profile (colors, shell, layout)? Use the existing profile method.

With your hotkey set, your terminal is gone—until you need it again.

References

Official iTerm2 Documentation - Dedicated Hotkey Windows