My most used bash functions

There’s problems you’d like to solve. And problems you like solving. What you put in the second category is almost uncomfortably revealing of who you are. Anything you consider trivial fits right into the first category and is a candidate for automation. Here are some of these automations I bring with me to all new laptops I work on. get a random string of variable length function randpw() { # e.g randpw 20 local pwlength="${1}" cat /dev/urandom | tr -dc 'a-zA-Z0-9!@#$%^&*()-[]{}:;\|,.<>/?' | fold -w "${pwlength:-50}" | head -n 1 } full update for ubuntu distros function fu() { sudo apt update sudo apt -y upgrade sudo apt -y dist-upgrade sudo apt -y autoremove sudo ubuntu-drivers install brew update brew upgrade } update all repos in your code directory function getallprojects() { find "${YOUR_PROJECTS_DIR}" -maxdepth 1 \ -mindepth 1 \ -type d \ -printf '%f\n' \ | grep -v .vscode } function getdefaultbranch() { git remote show origin | grep 'HEAD branch' | cut -d' ' -f5 } function refreshprojects() { local LIGHTGREEN="\e[92m" local ENDCOLOR="\e[0m" echo "---------------" for project in "$(getallprojects)"; do echo -e "Refreshing ${LIGHTGREEN}${project}${ENDCOLOR}" pushd "${project}" > /dev/null || exit git fetch --prune git checkout "$(getdefaultbranch)" git pull popd > /dev/null || exit echo "---------------" done } hack to get a urlencoded string function urlenc() { local str_to_encode="${1}" encoded_str=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''${str_to_encode}'''))") echo "${encoded_str}" # why did I need it? # verify connectivity to rabbitmq, password had special characters # rabbitmq-dump-queue -uri="amqps://mq_user:$(urlenc "${mq_password}")@my.mq.endpoint.tld:5671/" -queue=myqueue -max-messages=1 -output-dir=./ } Is it worth the time? It depends

September 15, 2024 ·  stelis

Can I get Free Email for my custom Domain, please?

At some point you bought a domain. You made something of it, or (usually) not. Now you’d like an email address on that domain. It looks much nicer than your typical xyz@gmail.com, right? Especially if you’re a business, Google Workspace or Microsoft 365 is a no-brainer. You get your custom domain email, storage, collaboration apps, SSO and other tools for something like 5-10$/person/month. But if you’re like me (i.e you like the vanity of the thing but will not allow yourself the expense unless you know you’ll actually use it or it’ll make its money back somehow) you may be looking for something without monthly subscriptions, preferably free. ...

September 14, 2024 ·  stelis

Get the env vars your app started with

The setup should be familiar. You have an app that is ready to ship, so you put it in a docker image. Any config after that is done mostly via env vars. For anything non-trivial like e.g - mounting and parsing secrets to env vars - making sure certain default values are overriden you need an init script that calculates the var’s desired value, then exports it like export MY_CONFIG_VAR=calculated_value And once done, you’d start the app with your equivalent of ...

September 14, 2024 ·  stelis

Meet your Heroes!

There’s this quote that I hate Never meet your heroes The assumption being that our heroes should be seated on pedestals and admired from afar. Meeting them will uncover their human flaws and thus they’ll lose their glory and primary function. That’s why I love Colossus’ quote from the first Deadpool movie Everyone thinks it’s a full-time job. Wake up a hero. Brush your teeth a hero. Go to work a hero. Not true. Over a lifetime, there are only four or five moments that really matter. Moments when you’re offered a choice - to make a sacrifice, conquer a flaw, save a friend, spare an enemy. In these moments, everything else falls away. ...

September 10, 2024 ·  stelis

Linguistic Details

Language is a terrific tool to get your message across. But it exactly that, a tool. Everyone uses it for their purposes. And if it succeeds we should be happy. After all, conveying a nuanced message is hard enough in itself. This is why I’ve stopped being pedantic about small errors in syntax or grammar, unless the sender has explicitly asked for comments on that. On the other hand, it’s almost magical when you notice a skilled speaker masterfully choosing the correct word to relay their message. In just as many words, they’ve communicated volumes more. But to understand and appreciate that you need to be prepared. ...

September 8, 2024 ·  stelis

Port-forward non k8s service via k8s

So, suppose my app that runs on k8s needs a postgres db to write to. I’ll set up an RDS that is reachable only within my VPC. Then a dev needs to connect to that DB from their local to troubleshoot some weird issue. What do I do? The tried-and-true solution is of course some VPN. If you have the time and resources to do it right, you’re golden. If not, a VPN is a surefire way to headaches. (new authentication pool, 2FA , maintenance, split DNS, slow connection speeds etc) ...

September 8, 2024 ·  stelis

What's the most you can make of an olivetin?

No, not that kind of olivetin, this one :-P OliveTin is a simple web UI that can be configured via yaml to run cli commands. You add a section such as actions: - title: Restart backend icon: restart shell: docker restart main-backend and in its UI you’ll find an icon with your title that, once pressed, will execute the shell command you specifed. You can even add arguments - title: Ping host shell: ping {{ host }} icon: ping arguments: - name: host title: host type: ascii_identifier default: example.com My only slight complaint is that while it sort of supports authorization it does not support authentication. If you’re deploying it to be publicly accessible, you’d need to configure your ingress to authenticate the user and only then redirect them to the app. ...

September 8, 2024 ·  stelis

Why did Ancient Greeks not have Probability Theory?

Ancient Greeks’ contribution to the foundation of sciences in undeniable. Euclidian Geometry, that accurately describes the space around us,the concept of “mathematical proof”, Aristarchus’ heliocentric theory, the foundation of medicine by Hippocrates, philosophy as expressed by Plato, Socrates and Aristotle are few examples to support this. It’s usual and familiar, whenever tracing back to the foundation of a scientific field, to find references to Ancient Greece. So it might surprise a scholar of the history of Probability Theory that its origins date back to the 16th century. And they might rightfully wonder why did Ancient Greeks not have Probability Theory? ...

September 8, 2024 ·  stelis

S3 can be persistent

I’ve always hated adding persistence in k8s workloads. There are valid reasons to avoid it, right? Adding a PV means people can store stuff there that they expect to find, regardless of where the app is deployed/redeployed (which could be in another region/zone/cluster/node etc where the original pv is not present) Thus adding another step in the deployment process that comes usually as an afterthought and may be easily overlooked and poorly documented. ...

September 7, 2024 ·  stelis

DIY internet connectivity notification

WFH is great! But every once in a while, internet goes down mid-workday and you’re not sure when it will be back up. You’re forced to leave in a hurry for some nearby cafe. How can you know it’s back up so you can return? I solved this once and while I’m not proud of how it worked, it worked! Prerequisite: A host in that network and a Slack workspace or other service you’re allowed to create a webhook for. ...