Skip to content

Instantly share code, notes, and snippets.

View nexus166's full-sized avatar
🌪️
🐧

nexus166

🌪️
🐧
  • Earth
View GitHub Profile
@nexus166
nexus166 / generate_directory_index_caddystyle.py
Created January 22, 2021 02:29 — forked from glowinthedark/generate_directory_index_caddystyle.py
Generate directory index (recurse subfolders with `-r` or `--recursive`). Use `-h` or `--help` for all options
#!/usr/bin/env python3
# ---
# Copyright 2020 glowinthedark
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
#!/bin/bash -x
sleep 15
_uqmi="/sbin/uqmi"
ifdown WWAN || true
_cleanup() {
/usr/bin/killall "${_uqmi}" 2>/dev/null || true
for i in $(/bin/ps www | /usr/bin/awk '/uqmi/ && /cdc-wdm0/ && !/awk/ {print $1}'); do
#!/usr/bin/env bash
set -xeuo pipefail
DISK="${1}"
_DISKNAME="$(basename "${DISK}")"
openssl rand 4096 >"${_DISKNAME}.key"
yes YES | cryptsetup luksFormat -d "${_DISKNAME}.key" "${DISK}" || true

install packages

apt install unattended-upgrades apt-config-auto-update

configure

cat <<'EOF' | tee /etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Origins-Pattern {
 "origin=Debian,codename=${distro_codename},label=Debian";
cfg = rs.conf()
cfg.members[0]["host"] = "[insert_correct_hostname_or_ip]:27017"
rs.reconfig(cfg)
@nexus166
nexus166 / dict2json.sh
Last active March 11, 2022 04:21
convert bash arrays to json
#!/usr/bin/env bash
dict2json() {
local _data=""
trap 'if [[ -n "${_data}" ]]; then printf "{%s}" "${_data%?}" | jq -arc .; fi' RETURN
case "${#@}" in
0)
return
;;
1)
#!/usr/bin/env bash
declare -A CHART=(
["a"]="alpha" ["b"]="bravo" ["c"]="charlie"
["d"]="delta" ["e"]="echo" ["f"]="foxtrot"
["g"]="golf" ["h"]="hotel" ["i"]="india"
["j"]="juliet" ["k"]="kilo" ["l"]="lima"
["m"]="mike" ["n"]="november" ["o"]="oscar"
["p"]="papa" ["q"]="quebec" ["r"]="romeo"
["s"]="sierra" ["t"]="tango" ["u"]="uniform"
@nexus166
nexus166 / chunk_split.go
Created June 17, 2020 08:13
split and merge []byte in go
package main
import (
"fmt"
)
func main() {
s := "He turned in the research paper on Friday; otherwise, he would have not passed the class."
fmt.Printf("%s\nlenght:%d\n", s, len(s))
func rotateString(s string, n int, encdec bool) (string, error) {
l := len(s)
if l < 1 {
return "", fmt.Errorf("empty input")
}
if n < 1 || n > 6 {
return "", fmt.Errorf("invalid shift n %d", n)
}
var out string
switch encdec {
package main
import (
"bytes"
"fmt"
"os"
"strings"
"strconv"
)