Developer Blog

Tipps und Tricks für Entwickler und IT-Interessierte

Rust | Modern Alternatives of Command-Line Tools


bat

bat is a cat clone with syntax highlighting and Git integration that works on Windows, MacOS and Linux. It provides syntax highlighting for many file extensions by default.

exa

exa is a modern replacement for ls, the default command-line program in Unix/Linux for listing directory contents. exa supports icons with the --icons flag.

just

A command runner and partial replacement for make

Just create a justfile with the desired commands and your set.

When running with PowerShell, add the following at the start of your justfile:

set windows-shell := ["pwsh.exe", "-NoLogo", "-NoProfile", "-Command"]

fd

fd is a fast and user-friendly alternative to find, the built-in command-line program in Unix/Linux for walking a file hierarchy. fd provides opinionated defaults for the most common use cases. To find a specific file by name, you write fd PATTERN instead of find -iname ‘*PATTERN*’fd is also extremely fast and it comes with a ton of options like ignoring hidden directories, files and patterns from .gitignore by default.

procs

procs is a modern replacement for ps, the default command-line program in Unix/Linux for getting information about processes. It provides convenient, human-readable (and colored) output format by default.

sd

sd is an intuitive find & replace command-line tool, it is an alternative to sed, the built-in command-line program in Unix/Linux for parsing and transforming text (). sd has simpler syntax for replacing all occurrences and it uses the convenient regex syntax that you already know from JavaScript and Python. sd is also 2x-11x faster than sed.

sed is a programmable text editor, with search and replace being a common use case. In that light, sd is more like tr, but on steroids. (thanks /u/oleid for the suggestion).

dust

dust is a more intuitive version of du, the built-in command-line program in Unix/Linux for displaying disk usage statistics. By default dust sorts the directories by size.

startship

The minimal, blazing-fast, and infinitely customizable prompt for any shell.

ripgrep

ripgrep is an extremely fast alternative to grep, the built-in command-line program in Unix/Linux for searching files by pattern. ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern. By default, ripgrep respects .gitignore and automatically skips hidden files, directories and binary files.

toeki

tokei is a program that displays statistics about your code. It shows the number of files, total lines within those files and code, comments, and blanks grouped by language.

hyperfine

hyperfine is a command-line benchmarking tool. Among many features, it provides statistical analysis across multiple runs, support for arbitrary shell commands, constant feedback about the benchmark progress and current estimates and more.

ytop

ytop is an alternative to top, the built-in command-line program in Unix/Linux for displaying information about processes.

tealdeer

tealdeer is a very fast implementation of tldr, a command-line program for displaying simplified, example based and community-driven man pages.

bandwhich

bandwhich is a CLI utility for displaying current network utilization by process, connection and remote IP or hostname.

grex

grex is a command-line tool and library for generating regular expressions from user-provided test cases.

rmesg

rmesg is a dmesg implementation in Rust (and available as a library for Rust programs to consume kernel message logs.)

zoxide

zoxide is a blazing fast autojumper, intended to completely replace the cd command. It allows you to change directories without typing out the entire path name.

delta

delta is a viewer for git and diff output. It allows you to make extensive changes to the layout and styling of diffs, as well as allowing you to stay arbitrarily close to the default git/diff output.

tp-note

Tp-Note is a template tool that enhances the clipboard with a save and edit as a note file function. After creating a new note file, Tp-Note launches the user’s favorite file editor (for editing) and web browser (for viewing).

nushell

nushell is a new type of shell, written in Rust. Its goal is to create a modern shell alternative that’s still based on the Unix philosophy but adapted to the current era. It supports piping and filtering in a way similar to awk and sed with a column view so that you can combine operations like in SQL. (thanks /u/matu3ba for the suggestion).


Django | How To – Templates konfigurieren

Allgemein / Vorbereitung

Um in einem Django-Projekt mit mehreren Anwendungen die HTML-Templates zu konfigurieren sind mehrere Schritte notwendig.

Ausgangsbasis ist die nachfolgende Verzeichnisstruktur (ein Projekt mit 2 Anwendungen).

Basisprojekt einrichten

➜ pipenv --python 3.10
➜ pipenv shell
➜ pip install django
➜ djangop-admin startproject project
➜ cd project
➜ mkdir apps
➜ mkdir apps\core
➜ django-admin startapp core apps\core
➜ mkdir apps\frontend
➜ django-admin startapp frontend apps\frontend

Dies ergibt die folgende Verzeichnisstruktur:

Hinweis: der Befehl startproject erstellt einen Ordner project, indem er einen weiteren Ordner project erstellt. Der erste Ordner dient dazu, sowohl das Django-Projekt, als auch die erstellten Anwendungen an einer gemeinsame Stelle zu speichern.

Der zweite Ordner project ist das Django-Projekt, in dem sich alle für das Projekt notwendigen Dateien befinden.

Wird in den nachfolgenden Beschreibungen vom dem Ordner project gesprochen, so ist immer der zweite gemeint (project/project)

➜ python manage.py migrate
➜ python manage.py createsuperuser --email admin@localhost --username admin
Password:
Password (again):
Superuser created successfully.

Anwendungen hinzufügen

Im nächsten Schritt werden die beiden erstellten Anwendungen (Core und Frontend) dem Django-Projekt hinzugefügt. Da sie in einem Unterverzeichnis (apps) liegen, muss ihre Konfiguration angepasst werden.

In dere Datei apps.py der jeweiligen Anwendung (apps/core/apps.py und apps/frontend/apps.py) wirr der Name angepasst:

Hinweis: Ohne diese Anpassung würde beim Start des Servers eine Fehlermeldung angezeigt

django.core.exceptions.ImproperlyConfigured: Cannot import 'frontend'. Check that 'apps.frontend.apps.FrontendConfig.name' is correct.

Im Anschluss daran werden die beiden Anwendungen dem Projekt hinzugefügt. Dies erfolgt in der Datei project/settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'apps.core',
    'apps.frontend'
]

Einfache Views erstellen

Ein Template ist die Basis eines Views.

Daher richten wir für jede Anwendung einen einfachen View ein: in apps/core/views.py und apps/frontend/views.py:

from django.shortcuts import render
from django.views import generic

class IndexView(generic.TemplateView):
    """
    IndexView:
    """
    module = 'indexView'
    template_name = 'core/index.html'

URLs für die Anwendungen hinzufügen

Im letzten Vorbereitungsschritt konfigurieren wir die URLs für unsere Anwendungen bzw die beiden eingerichteten Views:

from django.contrib import admin
from django.urls import path

import apps.core.views as core
import apps.frontend.views as frontend

urlpatterns = [
    path('admin/', admin.site.urls),
    path('frontend/', frontend.IndexView.as_view(), name='index'),
    path('core', core.IndexView.as_view(), name='index'),

]

Als Ergebnis sollten wir bei beiden URLs einen Fehler sehen.

Dies was zu erwarten, da wir die notwendigen Templates ja erst jetzt einrichten werden:

Template hinzufügen

Erstellen eines Templates für die Anwendung core: apps/core/templates/core/index.html

Der Verzeichnispfad des Templates setzt sich auch mehreren Teilen zusammen

apps/coreDas Startverzeichnis der Anwendung
templatesDer Default-Name des Verzeichnisses, in dem Django nach Templates sucht
coreDer Namespace als Unterscheidung, wenn es Templates mit gleichem Namen gibt
index.htmlDer Name des Templates

Erstellen Sie die Daten apps/core/templates/core/index.html und öffnen Sie dann den Browser:

http://localhost:8000/core

Zum Vergleich öffen wir die URL für unsere zweite Anwendung: frontend

http://localhost:8000/frontend

Im unteren Teil der Fehlermeldung findet sich aber eine hilfreiche Information:

Als erstes wir uns mitgeteilt, das ein gewünschtes Template in der nachfolgenden Reihenfolge gesucht wird. Es werden als (wir oben bereits erwähnt) mehrere Verzeichnisse durchsucht, um ein passendes Template zu finden.

Template-loader postmortem
Django tried loading these templates, in this order:

Using engine django:

Als erstes werden Verzeichnisse der Django-Installation durchsucht. Hierunter liegen z. B. die Templates für die Administration oder die Anmeldung.

django.template.loaders.app_directories.Loader: 
...\lib\site-packages\django\contrib\admin\templates\frontend\index.html (Source does not exist)

django.template.loaders.app_directories.Loader: 
...\lib\site-packages\django\contrib\auth\templates\frontend\index.html (Source does not exist)

Im Anschluss werden dann die Verzeichnisse unserer Anwendungen durchsucht.

django.template.loaders.app_directories.Loader: ...\project\apps\core\templates\frontend\index.html (Source does not exist)

django.template.loaders.app_directories.Loader: ...\project\apps\frontend\templates\frontend\index.html (Source does not exist)

Um nun ein gewünschtes Template zu finden, werden zwei Informationen benötigt:

  • der Name des Template
  • das Verzeichnis

Name des Templates

Der Name des Templates wird im View angegeben: apps/core/views.py:

class IndexView(generic.TemplateView):
    module = 'indexView'
    template_name = 'core/index.html'

Verzeichnis

Das Verzeichnis selbst wird über die Suchreihenfolge der zu verwendenden Template-Verzeichnisse ermittelt. Das erste Verzeichnis, dass das gewünschte Template beinhaltet, wird verwendet.

Ermitteln des Verzeichnisses

Im Falle unserer Anwendung frontend werden die nachfolgenden Verzeichnisse durchsucht, ob sie das Template core/index.html beinhalten:

UmgebungVerzeichnisTemplate gefunden
DJANGOlib\site-packages\django\contrib\admin\templates
DJANGOlib\site-packages\django\contrib\auth\templates
PROJEKTproject\apps\core\templatescore/index.html
PROJEKTproject\apps\frontend\templates

Template hinzufügen

Erstellen eines Templates für die Anwendung frontend: apps/frontend/templates/frontend/index.html

Weiteres Beispiel: Suchen des passenden Templates

Richten sie einen Neuen View in der Anwendung frontend ein: apps/frontend/views.py

class BaseView(generic.TemplateView):
    module = 'baseView'
    template_name = 'base.html' 

Erstellen Sie eine URL für diesen View in project/urls.py

urlpatterns = [
    path('admin/',      admin.site.urls),
    path('core',        core.IndexView.as_view(),      name='index'),
    path('frontend/',   frontend.IndexView.as_view(),  name='index'),
    path('base/',       frontend.BaseView.as_view(),   name='base'),
]

Öffnen Sie den Browser um diese URL anzuzeigen;

http://localhost:8000/base

Wie zu erwarten war, wird das Template nicht gefunden:

In keinem der bekannten Verzeichnisse gibt es ein Template base.html.

Gemeinsame Templates für alle Anwendungen

Um Templates einzurichten, die von mehreren Anwendungen verwendet werden, empfiehlt es sich, ein Verzeichnis templates auf der gleichen Ebene, wie die Anwendungen, einzurichten

In der Datei project/settings.py wird dieses Verzeichnis dem Django-Projekt hinzugefügt.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        ....

Öffnen Sie den Browser um diese URL anzuzeigen;

http://localhost:8000/base

Das zusätzliche Verzeichnis wird nun auch durchsucht:

Template-loader postmortem
Django tried loading these templates, in this order:

Using engine django:
django.template.loaders.filesystem.Loader: ...\project\templates\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: ...\.venv\lib\site-packages\django\contrib\admin\templates\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: ...\.venv\lib\site-packages\django\contrib\auth\templates\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: ...\project\apps\core\templates\base.html (Source does not exist)
django.template.loaders.app_directories.Loader: ...\project\apps\frontend\templates\base.html (Source does not exist)

Erstellen Sie nun in diesem Verzeichnis (templates) das Template base.html

Öffnen Sie den Browser um diese URL anzuzeigen;

http://localhost:8000/base

SpringBoot - Cookbook

Spring Boot | Cookbook

Introduction

Tipps and Tricks

Change App Port Number

Add line to file src/main/resources/application.properties

server.port=9010

Rest Api

Get JSON Data from a remote Rest Server

final RestTemplate restTemplate = new RestTemplate();
final String response = restTemplate.getForObject("https://httpbin.org/ip", String.class);

System.out.println(response);