Post your handy utility scripts!

Hey, I paid for that CPU so I want to use every damn cpu core/thread it has. :stuck_out_tongue_winking_eye:

3 Likes

You were warned… :upside_down_face:

image

2 Likes

The best thing about arrays is that they occupy a contiguous part of memory, which makes makes it possible to access any element by its index. It takes the same amount of time to read item 0 and item 10000, you don’t have to iterate through all of the array to find the element at a given position. In CS jargon, this makes the array a β€œrandom access data structure”, and the time it takes to access any element is said to be O(1) (it does not depend on the position of the element nor the size of the array).

So in β€œmy method”, getting a random element from the array does not depend on the size of that array (though the probability distribution is bugged with big arrays). You just get the random index, and then access the element at that position. A single array access operation.

On the other hand, shuffling the array (with the best possible algorithm and sufficient memory) requires O(n) time, where n is the size of the array, meaning that 10 times bigger array takes 10 times longer to shuffle. Every element in the array has to be accessed at least once to shuffle it. Now, if you combine that with calling a (rather bloated) external program like sed on every element of the array… this is where you lose all that time.

6 Likes

Here is the best alias ever:

alias 🐱='cat'

It works flawlessly.

4 Likes

Isn’t that dangerous to a frog? I had to restrict my cat to the house when at the lake…

:smiley_cat:

1 Like

An Arch TU told me about this: https://wiki.archlinux.org/title/IBus#Emoji_input

It brought my system into the 21st century… :rofl:

$ πŸ¦„πŸŒˆ
zsh: command not found: πŸ¦„πŸŒˆ

:sob:

1 Like

Try 21st century B.C. :rofl:

c++ source code
#include <iostream>

#define π“‚˜ {
#define π“‚“ }
#define 𓂁 <<
#define π“‚„ >>
#define 𓇼 *
#define π“‹  +
#define π“ˆˆ =

#define π“­π“ƒŒπ“” std::cout
#define π“­π“ƒŒπ“… std::cin
#define 𓀑𓀽𓃩 int
#define π“ƒ½π“€Œπ“€“π“° char
#define π“œπ“‚€π“  template
#define π“­π“‰π“„™π“…Š class
#define π“…˜π“šπ“†« public
#define π“€ π“‰ π“Œ² const
#define π“Ήπ“Ž¬π“» return
#define π“†Œπ“†šπ“†£ auto
#define 𓄃𓃠 '\n'
#define 𓁩𓉒π“ͺ main

π“œπ“‚€π“  <π“­π“‰π“„™π“…Š 𓆦>
π“†Œπ“†šπ“†£ 𓁂𓇽𓁑(𓆦 π“€ π“‰ π“Œ² π“…‡, 𓆦 π“€ π“‰ π“Œ² π“…“) π“‚˜ π“Ήπ“Ž¬π“» π“…‡ π“‹  π“…“; π“‚“

π“œπ“‚€π“  <π“­π“‰π“„™π“…Š 𓆦>
π“­π“‰π“„™π“…Š π“‡£π“ˆŒπ“‚“
π“‚˜
π“…˜π“šπ“†«:
   π“œπ“‚€π“  <π“­π“‰π“„™π“…Š 𓋍>
   π“†Œπ“†šπ“†£ π“ƒšπ“ŒŒπ“‹Ήπ“…€(𓋍&& π“‹—, 𓆦 π“€ π“‰ π“Œ² π“…‡, 𓆦 π“€ π“‰ π“Œ² π“…“)
   π“‚˜
      π“Ήπ“Ž¬π“» π“‹—(π“…‡, π“…“);
   π“‚“
π“‚“;

𓀑𓀽𓃩 𓁩𓉒π“ͺ()
π“‚˜
   π“‡£π“ˆŒπ“‚“<𓀑𓀽𓃩> π“……π“€Žπ“ƒ¦;
   𓀑𓀽𓃩 𓃕 π“ˆˆ π“……π“€Žπ“ƒ¦.π“ƒšπ“ŒŒπ“‹Ήπ“…€(𓁂𓇽𓁑<𓀑𓀽𓃩>, 1, 2);

   π“­π“ƒŒπ“” 𓂁 𓃕 𓂁 𓄃𓃠;
π“‚“

link to source

3 Likes

It would have been awesome if these were actual Middle Egyptian words, it’s just hieroglyphic gibberish. Still, very impressive!

I am no expert but I guess that the amount of people who are fluent both in c++ and Middle Egyptian could be counted on one hand even by a clumsy carpenter.
But then again, I may be surprised.

2 Likes

The user nobody is fluent in Middle Egyptian, the last native speaker of it died 3500 years ago. We can only guess how it sounded.

I’ve been learning it for 4-5 years now, and I know enough to be able to read hieroglyphic, but very slowly and with a help of a dictionary. I’ll never be fluent in it, unfortunately. But I find it really fun. So this combination of C++ and hieroglyphs is right up my alley :joy:

4 Likes

But - the really burning question is: Is there a :frog: hieroglyph? I know frogs were around then and there…

1 Like

Of course there is!

It’s glyph I7 in the Gardiner’s Sign List (glyph no. 7 under section I. Amphibious animals, reptiles, etc.).

There is also a tadpole, which is I8.

Frogs were very important in ancient Egyptian culture, religion, mysticism, and philosophy. They are symbols of fertility, childbirth, resurrection, and primeval times (before the creation of the universe). I could go on and on about this, but it’s quite off topic. :frog:

The Middle Egyptian word for frog was qrr, probably pronounced something like β€˜qurar’ (which is something a frog would say). Another onomatopoetic noun for an animal is mjw which means cat (probably pronounced β€˜miaw’).

5 Likes

Thank you! I learn the most interesting things here on the EnOS forum! :cat: :frog:

3 Likes

Absolutely beautiful! 𓋍&& is a work of art…

Here is a little script that generates mixed case:

#!/bin/bash
# A sImPlE sCrIpt tHAt GeNErAtEs MiXed cAse FroM ItS STdIn

max_repeat=2

function coinflip() {
  printf $(($RANDOM%2))
}

while read line; do
  uppercase_line="${line^^}"
  lowercase_line="${line,,}"
  len=${#line}
  flip=$(coinflip)
  n=0

  for ((i = 0; i < len; i++)); do
    oldflip=$flip
    flip=$(coinflip)

    if ((flip == oldflip)); then
      ((n++))
    fi

    if ((n >= max_repeat)); then
      n=0
      ((flip = !flip))
    fi

    if ((flip)); then
      printf '%s' "${uppercase_line:$i:1}"
    else
      printf '%s' "${lowercase_line:$i:1}"
    fi
  done

  printf '\n'
done < "${1:-/dev/stdin}"

Usage:

$ ./mixcase <<< 'Just pipe text into it and it will create mixed case!'
jUsT pIpE tExt inTo iT aNd It wiLL cReaTe miXeD cASe!

Useful for most online interactions.

2023-08-23: Updated the script to not use sed, but instead use built-in Bash string manipulation techniques.

8 Likes

nice …

1 Like

Gnome disable lid switch / enable lid switch:

#!/usr/bin/env bash

if [[ "$1" == "1" ]]; then
    kill -9 ` pgrep -f gnome-tweak-tool-lid-inhibitor`
    echo "Lid switch working"
fi

if [[ "$1" == "0" ]]; then
    /usr/lib/gnome-tweak-tool-lid-inhibitor&
    echo "Lid switch disabled"
fi

if [[ "$1" == "" ]]; then
    echo "Usage:"
    echo "Disable lid switch - lidsw 0"
    echo "Enable lid switch - lidsw 1"
fi

For when you are streaming a film and need to close your laptop lid :smiley: Quicker than tweaks…

How do you get the emoji’s quickly on the terminal?
I could think of opening emoji selector, searching, selecting(will copy it) and pasting it on the terminal, but is there any easier way? also helpful if not just in terminal but over the OS.
So far, I could be able to find this : https://hub.espanso.org/packages/all-emojis/#

See @jonathon post:

It’s slightly finicky to get it to work, but once you do, it’s really nice.

When installed emojione-picker.

$ yay emojione-picker-git

You can do

$ emojione-picker --help

From there you can select an emoji :slight_smile:

Just found out myself.
Screenshot_2021-07-23_11-47-44

edit typo