ruby -retc -e 'puts Etc.nprocessors'
python -c "import multiprocessing; print(multiprocessing.cpu_count())"
#!/usr/bin/env bash | |
set -euo pipefail | |
claim=$1 | |
ns=$2 | |
pod_name="pvc-inspector" | |
kubectl get po "$pod_name" -n "$ns" && kubectl delete po "$pod_name" -n "$ns" | |
cat <<EOF | kubectl apply -f - |
# Reading file lines from stdin | |
cat /tmp/test.txt | python -c 'import fileinput; [print(line, end="" for line in fileinput.input()] | |
python -c 'import fileinput; [print(line, end="") for line in fileinput.input()]' < /tmp/test.txt | |
# Printing the 3 lines of the file | |
python -c "import sys; sys.stdout.write(''.join(sys.stdin.readlines()[:3]))" < /tmp/test.txt | |
# Checking if file exists | |
python -c 'from pathlib import Path; print("yes") if Path("/tmp/metrics.txt").is_file() else print("no")' |
#!/bin/bash | |
# | |
# Creates a new TypeScript project ready to use with Node.js | |
set -euo pipefail | |
if [[ ! -f $(which npm) ]] || [[ ! -f $(which yarn) ]]; then | |
echo "Please, install npm and yarn before continuing" | |
echo "See https://docs.npmjs.com/downloading-and-installing-node-js-and-npm" | |
echo "See https://yarnpkg.com/" | |
exit |
# Starting REPL | |
perl -del | |
# Search and replace in place | |
perl -p -i -e "s/test/testing/g" /tmp/testing.txt | |
# Search/replace in specific files in a directory | |
perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html` | |
# Similar to awk |
import java.util.ArrayList | |
def MAX_TO_KEEP = 10 | |
def JOB_NAME = "job_name_here" | |
def hi = hudson.model.Hudson.instance | |
def item = hi.getItemByFullName(JOB_NAME) | |
def jobs = item.getAllJobs() | |
Iterator<?> iterator = jobs.iterator() |
#!/bin/bash | |
# How to download a release file from a private GitHub repo | |
set -eou pipefail | |
TOKEN="<your_github_token>" | |
API_URL="https://api.github.com/repos/<your_repo_here>" | |
asset_id=$(curl -s -H "Authorization: token $TOKEN" -H "Accept: application/vnd.github.v3.raw" $API_URL/releases \ | |
| jq '.[0].assets[0].id') |
#!/bin/bash | |
# | |
# Set zsh as default shell when auth is done by LDAP | |
# | |
set -eou pipefail | |
getent passwd afernandez | perl -pne 's/bash/zsh/' | sudo tee -a /etc/passwd |
zipapp module allows us to create self-contained Python standalone programs that can be distributed to users who have Python already installed on their system.
Python packages not using C extensions can be bundled as well. shiv is recommended for those applications using those kind of extensions. In general, if your dependencies don't require a C compiler, you should be good to go using zipapp module.
#!/bin/bash | |
#------------------------------------------------------------------------ | |
# run-cmd-pod.sh | |
# | |
# Runs commands in K8s pods when those are not installed there | |
# but they're in the worker node. | |
# | |
# Motivation: You want to run a command in a pod without | |
# installing anything in the pod. If that command exists | |
# in the worker node running the pod, then you can use |