Steeph's Web Site

Go To Navigation
Show/Hide Navigation

Entries tagged 'cat:Software' (Page 5)

SBWG 0.9.6

As foreseen I've made slow progress in development of SBWG, the script that generates this web site, because I want to test and improve it with the current feature set before I start to implement new features. The former is necessary. The latter is more fun. But today I've reached a point where I can say that the only thing left to do before I call it v1.0.0 is testing edge cases and things that I didn't think of testing before, as well as fixing potential bugs discovered from this testing.

So, version 0.9.6 is out, everything is working, The README file, other documentation included in the package, the example website, the included style sets and partly even the code quality has been deemed satisfactory, and I hope I'll find the time to test all sorts of weird stuff and discover and fix some bugs next month, at which point version 1.0.0 will be published and I'll finally be able to allow myself to start working on new features, some of which are awaited by both regular users of the script.

Backmatch - A Simple Dual-N-Back-Inspired Performance Task Trainer For Bash

Here is a script that I wrote as a short side project because I wanted my own n-back trainer. I'm aware that the practical memory improments of n-back training, even when using a proper audiovisual dual n-back trainer, is not as great as it's often said to be. I just wanted to try it and see whether I like the training.

Usage

Execute the script and pass it a number that resembles the difficulty level. For example bash backmatch 3 starts the script with a 3-back task. On your keyboard press the key of the letter that was displayed n letters ago (in this example 3 letters ago). When you press a key the next letter is presented immedietly. If you don't press a key for 3 seconds (the time value can be changed by changing the variable sec) the next letter is presented and you don't get a point for this letter. When you exit the script by pressing ctrl+c your keypresses get compared to what was presented and you get your score.


#!/bin/bash

if [[ ${#} -ge 1 ]] && [[ ${1} =~ ^[0-9]*$ ]]
then
  n=${1}
else
  echo "'${@}' is not a number, is it?"
  exit 1
fi

echo "Ctrl+C pressing is for quitters."
npo=$((n+1))
sec=3

end() {
  echo -en "           \n"
  if [[ ${#str} -ge ${npo} ]]							# If enough characters had been generated
  then
    for i in $(seq $n); do echo -n "-"; done					# offset by $n dashes
    echo ${str}
    echo ${you}
    got=0
    for i in $(seq ${#str})
    do
      [[ ${str:$i:1} == ${you:$((i+n)):1} ]] && got=$((got+1))
    done
    echo -e "\n${got} out of $((${#str}-npo)) correct"
  else
    echo "Not enough data to judge you."
  fi
}

trap end EXIT

while true
do
  str+=$(cat /dev/urandom | tr -dc 'A-Z' | head -c 1)				# Get a random new letter.
  echo -en "\r       \r${str: -1}"						# Print the last character in the string (the new letter).
    read -n 1 -t ${sec} key							# Get a single character input, timeout $sec seconds.
    [[ -n ${key} ]] && you+=${key^^} || you+="-"
    [[ ${key^^} == ${str: -$npo:1} ]] \
      && echo -en "\r       good" \
      || echo -en "\r        bad"						# Check if uppercase input char is the same as the nth char from the back.
done

end

exit 1
SBWG 0.8.10

So, I'm still making slow process with SBWG. I had more fun with it when I was out and implementing new features. But I find it important to finish version 1.0.0 with the currently defined set of festures and goals, which include finishing documentation, testing and code hardening, which are less fun for me.

I've always treated the third level of the version number (x.x.thisone) as a means to declare a new version done when I feel like having achived something. So today I declare version 0.8.10 as done. There really isn't much left to do to meet my milestones for v0.9.0. And from there on it will only be testing and possibly a little bit of code improvements to get to my set goals for v1.0.0.

I'm looking forward to this not only because I'll like the feeling of having achived a goal, but also it will mean that I'll be free again to introduce new features. I still have more ideas than necessary about what to do with SBWG.

But right now I'm enjoing the fact that I'm able to make myself believe that it's okay to move on as slowly as I want and let my colloquial executive dysfunction do its think without impacting my feeling of self-worth oo much.

Bash script to burn your CPU easily

When making my own CPU cooler or testing some other stuff I sometimes need to create as high of a CPU load as possible. After typing while true; do true; done for the one-too-manyth time I finally decided to create an alias for that. But that didn't feel neat enough. So I made this simple Bash script.


#!/bin/bash

if [ "$#" -ne "1" ]
then
  echo "I need one argument and one argument only: Number of threads to start."
  echo "Hint: You have $(nproc) CPU cores."
  exit 1
fi

if [[ "$1" =~ ^[0-9]+$ ]]
then
  n="$1"
else
  echo "Argument needs to be a number: Number of threads to start."
  echo "Hint: You have $(nproc) CPU cores."
  exit 1
fi

trap "pkill -P $$; exit 0" SIGHUP SIGINT SIGTERM

while [ "$n" -gt 1 ]
do
  while true; do true; done &
  n=$((n-1))
done
echo "Started $1 threads to burn your CPU."
pidof -x "$(basename -- $0)"
while true; do true; done

Download

For a simpler script, you can also just use this three-liner without any arguments to stress all CPU cores:


#!/bin/bash
yeah() { while true; do true; done& }
threads=$(nproc)
for i in $(seq 1 $threads); do yeah; done
Bash script to quickly open and close a wifi hotspot

I needed a wifi hotspot to test some phones. So I looked up how to create one quickly and learned about nmcli. It wasn't quick and easy enough for my taste. So here is how I do it from now on.

The Bash script maintains only one connection (named quick-hotspot). You can't create multiple connections or access points with it. Not intentionally, but also not accidentally because you forgot that you still have a hotspot enabled from the last time you needed one. (I know I would at some point.)

Examples:


hotspot # Creates and enables a hotspot with a random name and a random 8-digit password.
hotspot down # Disables the hotspot if it was enabled.
hotspot ⊿ⴼͳΞⵖⵡ∃ doctorwho # Creates and enables a hotspot with the SSID "⊿ⴼͳΞⵖⵡ∃" and the password "doctorwho".
hotspot . password # My use case: quick and short and I don't want to type a complicated password on the phones. SSID: ".", PW: "password"
hotspot down # Deactivates the hotspot regardless of the SSID you used.

If you activate a hotspot while one is already active, it just changes the SSID and password so that no two connections created by this script are ever active at the same time. I'm sure there already is a program that solves this better. But it was fun for me to create and I felt like sharing.

Click here to download the bash script.

Content:

#!/bin/bash

# Quickly create and activate a WiFi hotspot - optionally defining SSID and password - and deactivate it again when you don't need it anymore.

usage() {
  echo "Usage: $(basename $0) ssid passphrase"
  echo "       $(basename $0) down"
  echo "       $(basename $0)"
  exit 1
}

activate() {
  # If the connection "quick-hotspot" doesn't already exist...
  if ! nmcli connection show | grep quick-hotspot; then
    # ... then create it.
    nmcli connection add type wifi ifname '*' con-name quick-hotspot autoconnect no ssid "$ssid"
  else
    # ... else change the SSID of the existing connection.
    nmcli connection modify quick-hotspot ssid "$ssid"
  fi
  # Make the connection an access point
  nmcli connection modify quick-hotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
  # Change the password
  nmcli connection modify quick-hotspot 802-11-wireless-security.key-mgmt wpa-psk 802-11-wireless-security.psk "$pw"
  # Enable the connection
  nmcli connection up quick-hotspot
}

case $# in
  0)
    ssid=$(</dev/urandom tr -dc A-Z] | head -c8; echo "")
    echo "SSID: $ssid"
    pw=$(shuf -i 10000000-99999999 -n 1) 
    echo "PW: $pw"
    activate
    ;;
  1)
    if [ $1 == down ]; then
      nmcli connection down "quick-hotspot"
      exit 0
    else usage
    fi
    ;;
  2)
    ssid="$1"
    if ! [ ${#2} -ge 8 ]; then
      echo "$(basename $0): Password needs to be 8 characters or longer."
      exit 1
    else
      pw="$2"
      activate
    fi
    ;;
  *)
    usage
    ;;
esac

See also: My Reddit Post