Archives

Pure BASH interactive CLI/TUI menu (single-/multi-select/checkboxes)

This post presents a first version of a pure bash script for creating interactive command-line menus with single-select, multi-select, and checkbox functionality.

First version. To be refactored.

Asciinema recording

Gist Link

Inspired by
Notes
  • This is a hacky first implementation for my shell tools/dotfiles (ZSH).
  • The intention is to use it for CLI wizards (my aim is NOT a full-blown curses TUI window interface).
  • I converted TPUT to ANSI-sequences to spare command executions (e.g. tput ed | xxd --plain).

Permission to copy and modify is granted under the Creative Commons Attribution 4.0 license.

[more]

Thought Experiment: Automation in Big Corporate

Thought Experiment: Automation in a Big Corporate Environment

Goal: We want to transition from owning our own fleet of cars to using a taxi service as a utility (service provider).

However, we don’t know enough about the taxi business and feel uncertain. Therefore, our first step is to hire drivers to operate our existing cars as makeshift taxis. These drivers, however, are not trained taxi drivers, they don’t know the routes, and the navigation system is a proprietary product with outdated maps. It comes from a reputable manufacturer, which is useless in practice. To keep them awake and encourage them to learn the routes, we also provide our drivers with coffee from a well-known, premium coffee chain.

[more]

PHP: just in case posix_isatty() is missing

This article provides a couple of PHP code snippets from StackOverflow that can be used to determine if a PHP script is running in an interactive terminal (TTY). These are useful workarounds for environments where the posix_isatty() function is not available.

Short function
function is_a_tty()
{
    static $result;
    if (is_null($result)) {
        $fp = fopen('php://stdin', 'r');
        $stat = fstat($fp);
        $mode = $stat['mode'] & 0170000; // S_IFMT
        $result = $mode == 0020000; // S_IFCHR
        fclose($fp);
    }
    return $result;
}
Info Class from StackOverflow by leigh
<?php

class IOMode
{
    public $stdin;
    public $stdout;
    public $stderr;

    private function getMode(&$dev, $fp)
    {
        $stat = fstat($fp);
        $mode = $stat['mode'] & 0170000; // S_IFMT

        $dev = new StdClass;

        $dev->isFifo = $mode == 0010000; // S_IFIFO
        $dev->isChr  = $mode == 0020000; // S_IFCHR …
[more]

Infojunk November 2018

This is a collection of interesting links and resources I came across in November 2018, covering topics such as security, Linux, AWS, and development.

Hacking / MITM-API-Testing
Linux
Windows
Python
KataCode
  • KataCode Playground with fully functional real browser shells for learning without barriers (using Containers?).
  • GoTTY
    How about gotty -w docker run -it --rm anapsix/nyancat:alpine?
Spectre/Meltdown
[more]

Connect to GitLab via SSH

Start an SSH Agent

If you haven’t already done so, add the following command to your shell’s RC file (such as .bashrc or .zshrc) to start the ssh-agent:

$ eval $(ssh-agent)
Add Your Generated Key

Use the ssh-add command to add your private SSH key (assuming it is the default id_rsa file) to the agent:

$ ssh-add ~/.ssh/id_rsa
List Keys

You can list the keys currently loaded by the ssh-agent using the following command:

[more]

bash: shell table output to json

This post presents a Python script that converts tabular command-line output into a more versatile JSON format. This allows for easier data manipulation using tools like jq, as an alternative to complex text-processing pipelines in bash.

You know that sometimes it would be really great to format a shell output to a more versatile format like JSON or YAML that you can process with jq instead of writing long pipes with text-processing.

[more]

AWS

This is a collection of interesting links and resources I came across in October 2018, covering a wide range of topics including browser extensions, collaborative coding, Linux, AWS, and more.

Browser Extensions
Collaborative Coding

Focusing on IDEs. Web-based solutions are mostly ignored.

Linux
[more]

Color-Laser-Printer: Xerox Workcentre 6515DNI

After my 15-year-old Konica Minolta magicolor 2530DL finally died, I was on the hunt for a new color laser printer. This post outlines my requirements and compares the top contenders, ultimately leading to my choice of the Xerox Workcentre 6515DNI.

I finally gave up my 15-year-old color laser printer, the Konica magicolor 2530DL, due to a failed firmware update. I cannot find out how to reset the firmware via a USB-Stick since most links now go to 404, and the DL model from 2003 does not have a parallel port anymore. USB and Ethernet are dead. Help is appreciated!

[more]

PulseAudio: Mono-Sink Audio

Just in case your 10,000+ employee corporation doesn’t plug in the microphone jack correctly and no one is allowed to ask questions (presentation-only).


Creating a Mono Audio Sink with PulseAudio

To force stereo audio output into a single mono channel, you can use the PulseAudio module module-remap-sink. This is often useful for presentations or when hardware is misconfigured (e.g., a microphone is plugged into an unbalanced stereo input, but only one channel is picked up).

[more]

AWS S3 Sync is Not Reliable and Slow!

This article explores reliability issues with AWS CLI’s S3 sync functionality and provides alternative solutions for better file synchronization.

While migrating from s3cmd to AWS S3 CLI, I noticed that files don’t sync properly when using AWS CLI.

I tested with different versions and they all revealed the same behavior:

  • python2.7-awscli1.9.7
  • python2.7-awscli1.15.47
  • python3.6-awscli1.15.47
Test Setup
  1. Setup AWS CLI utility and configure your credentials
  2. Create a testing S3 bucket
  3. Setup some random files
# Create 10 random files of 10MB each
for i in {1..10}; do dd if=/dev/urandom of=multi/part-$i.out bs=1MB count=10; done;
# Then copy the first 5 files over
mkdir multi-changed
cp -r multi/part-{1,2,3,4,5}.out multi-changed
# And replace the content in 5 files
for i in {6..10}; do dd if=/dev/urandom of=multi-changed/part-$i.out bs=1MB count=10; done;
Testing S3 Sync with AWS CLI
Cleanup
$ aws s3 rm s3://testbucket/multi --recursive 
Initial Sync
$ aws s3 sync multi …
[more]