Skip to content

Instantly share code, notes, and snippets.

@aljex
aljex / server
Last active Feb 22, 2019 — forked from mbbx6spp/server
View server
#!/usr/bin/env bash
# HTTP web service implemented in socat + bash
# Usage: socat -T 1 -d -d tcp-l:8080,reuseaddr,fork,crlf exec:./server
# Purpose: Provide an HTTP server that displays the current server date,
# to validate the artifact structure and play with it.
# Note: socat crlf option is translating all our \n to \r\n on output.
http_version="1.0"
declare -a _http_responses=(
@aljex
aljex / mk_tmp_dir.sh
Created Mar 27, 2019
Example to create an exclusive temp/working dir in bash using the atomicity of mkdir without -p
View mk_tmp_dir.sh
#!/bin/bash
# example
# create an exclusive temp dir
# atomic mkdir op method
# allow bash-isms
# bw.aljex@gmail.com
b="${1:-/tmp/foo}"
mkdir -p "${b%/*}" || exit 1
@aljex
aljex / urlencode.sh
Created Mar 27, 2019
Url-encode in pure bash as efficient as possible
View urlencode.sh
#!/bin/bash
# urlencode in pure bash without externals
# no backticks or forking, all in-memory ops
# allow bash-isms
urlencx () {
local LANG=C i c e
for ((i=0;i<${#x};i++)); do
c=${x:$i:1}
[[ "$c" =~ [a-zA-Z0-9\.\~\_\-] ]] || printf -v c '%%%02X' "'$c"
You can’t perform that action at this time.