Skip to content

Instantly share code, notes, and snippets.

@dberstein
dberstein / download.php
Created November 29, 2024 12:56 — forked from nicklasos/download.php
Curl PHP multiple files downloading
<?php
function multiple_download(array $urls, $save_path = '/tmp')
{
$multi_handle = curl_multi_init();
$file_pointers = [];
$curl_handles = [];
// Add curl multi handles, one per file we don't already have
foreach ($urls as $key => $url) {
@dberstein
dberstein / duration.py
Last active May 8, 2023 04:02
Python time duration as in golang
import re
import time
from datetime import datetime, timedelta
class DurationUnits:
Nanosecond = 1
Microsecond = 1000 * Nanosecond
Millisecond = 1000 * Microsecond
Second = 1000 * Millisecond
@dberstein
dberstein / main.go
Last active April 30, 2023 04:35
Golang os/arch, arch/os
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"strings"
)
@dberstein
dberstein / intellij.sh
Last active December 23, 2022 09:02
CLI background launcher of IntelliJ using aliases for toolbox scripts
#!/bin/sh
# Locate tool whose basename matches ours in toolbox's scripts directory
# ie. ln -s [$HOME/.local/bin/]intellij.sh [$HOME/.local/bin/]clion
# ensure "$HOME/.local/bin" in PATH is *before* toolbox's path ($HOME/.local/share/JetBrains/Toolbox/scripts),
# that way invoking "clion" invokes intellij.sh and it invokes toolbox's in CLI's background.
declare TOOL="$( find "$HOME/.local/share/JetBrains/Toolbox/scripts" -mindepth 1 -maxdepth 1 -type f \
-name "$(basename $0)" -executable -exec readlink -f {} \; )"
# No tool found is an error ...
#!/bin/sh
DEFAULT_CHART="${1:-grafana/loki-stack}"
REPO_NAME="${2:-grafana}"
REPO_URL="${3:-https://grafana.github.io/helm-charts}"
helm repo add "${REPO_NAME}" "${REPO_URL}"
helm search repo "${REPO_NAME}"
read -p "Chart? [${DEFAULT_CHART}]: " CHART
[ -z "${CHART}" ] && CHART="${DEFAULT_CHART}"
@dberstein
dberstein / git-dotfiles
Last active February 7, 2021 13:12
simple git alias for dotfiles management
# git-dotfiles: simple git alias for dotfiles management
# 1. configure dotfiles checkout location ...
git config --global --replace-all dotfiles.dir "$HOME/.dotfiles"
# 2. init dotfiles ...
git init --bare "$(git config --global dotfiles.dir)"
# 3. create git dotfiles alias ...
git config --global --replace-all alias.dotfiles '!git --git-dir="$(git config --global dotfiles.dir)" --work-tree="$HOME"'
# 4. (OPTIONAL)
echo \* >> $HOME/.gitignore
@dberstein
dberstein / 1p-gauge.sh
Last active January 16, 2021 14:00
One Punch Gauge
#!/bin/sh
echo 'One Punch Gauge, choose:'
cat <<EOS
🁣 🁣 0 00 πŸ‚‘ πŸ‚… πŸ€± πŸ€± πŸ“ 🁟
πŸͺ 🁀 10 90 πŸ‚ 🁾 πŸ€Έ πŸ€² 🁌 🁞
🁱 πŸ₯ 20 80 πŸ‚ 🁷 πŸ€Ώ πŸ€³ πŸ… 🁝
🁸 🁦 30 70 πŸ‚Ž 🁰 πŸ† πŸ€΄ πŸ€Ύ 🁜
🁿 🁧 40 60 πŸ‚ 🁩 🁍 πŸ€΅ πŸ€· πŸ›
#!/usr/bin/env sh
##########################################
# args - shell arguments parsing library #
##########################################
# Usage:
# - function "args_parse" with the parameters to parse, response will be a temp filename used to store the
# parsed data (see "Arguments parsing" and "Cleanup").
# Example: ARGS=$(args_parse "$@")
#
@dberstein
dberstein / bump.sh
Last active October 24, 2018 07:26
Shell semver component bump (1 line function)
# SemVer bump small shell/python function: bumps component $1 ("major", "minor" or "patch") from version in $2 (or STDIN).
# Version components to the right of the bump rollback to 0, ie. 1.2.3:1.2.4 or 1.2.3:1.3.0 or 1.2.3:2.0.0.
function bump() {
echo ${2:-$(</dev/stdin)} | python -c 'from sys import argv,stdin,stdout;n={"major":0,"minor":1,"patch":2}.get(argv[-1]);v=list(map(int,stdin.read().strip().split(".")));v[n]=v[n]+1;v[n+1:]=[0]*len(v[n+1:]);stdout.write(".".join(map(str,v))+"\n")' $1
}
## Examples
# # Version as parameter
# $ bump minor 1.0.1
# 1.1.0
@dberstein
dberstein / README.md
Last active May 1, 2023 04:15
ca-bundler.py - Certificate extractor for CA bundle creation

Certificate extractor for CA bundle creation

Outputs lines between (inclusive) -----BEGIN something----- and -----END something----- in reverse order. Useful for creation of CA certificates bundles.

Note that start/stop lines must begin with at least one dash and be followed by either BEGIN or END , then a space then non-space characters and end the line with at least one dash.

Above format rule will matches usual PEM format items like:

-----BEGIN CERTIFICATE-----
....