This commit is contained in:
slonkazoid 2024-08-30 15:22:09 +03:00
parent b36893239f
commit 8055505792
Signed by: slonk
SSH key fingerprint: SHA256:tbZfJX4IOvZ0LGWOWu5Ijo8jfMPi78TU7x1VoEeCIjM
13 changed files with 177 additions and 42 deletions

View file

@ -1,15 +1,16 @@
# snippets
slonked up scripts and stuff to do stuff
slonked up scripts and little snippets to do stuff
everything in this repository is licensed under CC0-1.0 unless specified
otherwise, use it for whatever purposes you want
# quick navigation
| C | Bash | JS |
| ---------------------- | ----------------------------------------------------- | ----------------------- |
| [unlink.c](c/unlink.c) | [arshit](shell/bash/arshit) | [svged.js](js/svged.js) |
| [cecho.c](c/cecho.c) | [sshfs_mount_file.sh](shell/bash/sshfs_mount_file.sh) | |
| | [repo_build.sh](shell/bash/repo_build.sh) | |
| | [grabber.sh](shell/bash/grabber.sh) | |
| C | Bash | JS |
| -------------------- | ----------------------------------------------- | ----------------------- |
| [cecho.c](c/cecho.c) | [arshit](bash/arshit) | [svged.js](js/svged.js) |
| | [sshfs_mount_file.sh](bash/sshfs_mount_file.sh) | |
| | [repo_build.sh](bash/repo_build.sh) | |
| | [grabber.sh](bash/grabber.sh) | |
| | [frequented.sh](bash/frequented.sh) | |
| | [start.sh](bash/start.sh) | |

1
bash/avt/README.md Normal file
View file

@ -0,0 +1 @@
# Moved to [slonkazoid/avt](https://gitlab.com/alifurkany/avt)

79
bash/frequented.sh Executable file
View file

@ -0,0 +1,79 @@
#!/usr/bin/env bash
# Usage: ./frequented.sh [number=5]
# Lists your top `number` most frequented channels
# Single threaded, still does 1.22 milliseconds per channel
# (on a 5600X with 2289 channels and 385952 messages)
# set this to your id to not print your id in dms/group chats
SELF_ID="${SELF_ID:-276363003270791168}"
n=$((${1:-5}))
repeat() {
local n=${2?}
for ((i=0; i<n; i++)); do echo "${1?}"; done
}
# shellcheck disable=SC2207
counts=($(repeat '0' $n))
# shellcheck disable=SC2207
channels=($(repeat 'none' $n))
# insert $1 and $2 into index $3 and drop last element
insert() {
local value1=${1?}
local value2=${2?}
local idx=${3:-0}
counts=("${counts[@]:0:$idx}" "$value1" "${counts[@]:$idx:$((n - idx - 1))}")
channels=("${channels[@]:0:$idx}" "$value2" "${channels[@]:$idx:$((n - idx - 1))}")
}
total_messages=0
total_channels=0
word_count() {
local total=0
while read -r; do
total=$((total + 1))
done
echo $total
}
time for dir in c*; do
channel=${dir#c}
count=$(("$(word_count < "$dir"/messages.csv)" - 1))
total_messages=$((total_messages + count))
total_channels=$((total_channels + 1))
for ((i=0; i<n; i++)); do
if ((count > ${counts[$i]})); then
insert $count "$channel" $i
break
fi
done
done
echo "total channels: $total_channels"
echo "total messages: $total_messages"
echo "most frequented $n channels:"
for ((i=0; i<n; i++)); do
# 1 and 3 are DM and GROUP_DM respectively
# https://discord.com/developers/docs/resources/channel#channel-object-channel-types
# if you want to understand the following `jq` filter,
# start reading here: https://jqlang.github.io/jq/manual/#basic-filters
channel_text=$(jq 'if .type == 1 // .type == 3 then
.id + " (" + if (.recipients | length) > 2 then
"GC with "
else
"DM with "
end + (.recipients | map(select(. != "'"$SELF_ID"'")) | join(", ")) + ")"
else
if has("name") then
"#" + .name + " (" + .guild.name + ")"
else
.id + " (unknown guild)"
end
end' c"${channels[$i]}"/channel.json)
echo "$((i + 1)). messages: ${counts[$i]}, channel: $channel_text"
done

85
bash/start.sh Executable file
View file

@ -0,0 +1,85 @@
#!/usr/bin/env bash
# Minecraft server start.sh
# for use in slapping in tmux and forgetting
# also rolls logs
# --- CONFIGURATION
# you can source an environment file like this:
#. .env
# auto-restart
AUTO_RESTART=${AUTO_RESTART:-1} # 1 to enable
RESTART_DELAY=${RESTART_DELAY:-3} # seconds
DONT_RESTART_IF=${DONT_RESTART_IF:0} # exit code
# java options
JAVA_BIN=${JAVA_BIN:-java} # full path to the java binary
#JVM_FLAGS= # Java flags
#NO_DEFAULT_JVM_FLAGS= # 1 to disable default flags
MEMORY_MIN=${MEMORY_MIN-4G} # Xms
MEMORY_MAX=${MEMORY_MAX:-4G} # Xmx
GC=${GC:-ZGC} # ShenandoahGC or ZGC
GC_PAR_THREADS=${GC_PAR_THREADS:-6} # "parallel" (runs while workers are stopped) thread count
# recommended to set to just below total thread count
GC_CONC_THREADS=${GC_CONC_THREADS:-"$(( half=GC_PAR_THREADS / 2, half == 0 ? 1 : half ))"}
# marker thread count, defaults to half of parallel
# mc options
MC_FLAGS=${MC_FLAGS:nogui} # Minecraft flags
SERVER_JAR=${SERVER_JAR:-server.jar} # server JAR file
# ---
gcs=(
[zgc]="-XX:+UseZGC"
[shenandoahgc]="-XX:+UseShenandoahGC"
)
java_args=()
[[ "${MEMORY_MIN:+x}" == 'x' ]] && java_args+=(-Xms"${MEMORY_MIN}")
java_args+=(-Xmx"${MEMORY_MAX}")
(( ! NO_DEFAULT_JVM_FLAGS )) && java_args+=(-XX:+ParallelRefProcEnabled -XX:+DisableExplicitGC -XX:+PerfDisableSharedMem -XX:MaxGCPauseMillis=10)
if [[ "${MEMORY_MIN,,}" == "${MEMORY_MAX,,}" ]]; then
java_args+=(-XX:+AlwaysPreTouch)
[[ "${GC,,}" == 'zgc' ]] && java_args+=(-XX:-ZUncommit)
fi
if (( $(</proc/sys/vm/nr_hugepages) > 0 )); then
java_args+=(-XX:+UseLargePages)
[[ $(</sys/kernel/mm/transparent_hugepage/enabled) != 'never' ]] && java_args+=(-XX:+UseTransparentHugePages)
fi
java_args+=("${gcs[${GC,,}]}")
[[ "${GC_CONC_THREADS:+x}" == 'x' ]] && java_args+=(-XX:ConcGCThreads="${GC_CONC_THREADS}")
java_args+=(-XX:ParallelGCThreads="${GC_PAR_THREADS}")
# shellcheck disable=SC2206
java_args+=(${JVM_FLAGS})
# shellcheck disable=SC2206
java_args+=(-jar "${SERVER_JAR}" $MC_FLAGS)
{
echo "Using settings:"
echo "Java binary: ${JAVA_BIN?}"
# shellcheck disable=SC2145
echo "Options: ${java_args[@]@Q} ${}"
echo "Auto restart: $( (( AUTO_RESTART )) && echo 'enabled' || echo 'disabled' )"
} 2>&1
while true; do
"${JAVA_BIN}" "${java_args[@]}" 2>&1 | tee ./"$(date -I)".log
exitcode=$?
echo "Process exited with code "$'\033'"[3$(( exitcode == 0 ? 2 : 1 ))m${exitcode}"$'\033'"[0m" >&2
#shellcheck disable=SC2076
(( AUTO_RESTART != 1 || DONT_RESTART_IF == exitcode )) &&
exit "${exitcode}"
echo "Restarting after ${RESTART_DELAY} seconds" >&2
sleep "${RESTART_DELAY?}"
done

View file

@ -1,5 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
@ -11,5 +10,4 @@ int main(int argc, char **argv) {
}
// Compilation: cc cecho.c -o cecho
// Usage: ./cecho [STRING]...
// License: Public Domain
// Usage: ./cecho ARG...

View file

@ -1,30 +0,0 @@
#include <errno.h>
#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
if (argc < 2) {
error(1, 0, "Not enough arguments.");
}
short has_errored = 0;
for (int i = 1; i < argc; i++) {
if (unlink(argv[i]) == -1) {
has_errored = 1;
error(0, errno, "%s", argv[i]);
}
}
if (has_errored) {
exit(1);
}
return 0;
}
// Compilation: cc unlink.c -o unlink
// Usage: ./unlink FILES...
// License: Public Domain

View file

@ -11,6 +11,8 @@ const { writeFileSync, readFileSync } = require("fs");
* 4. Calculate Delta E00 between two LAB colour (Main purpose)
* @author Ahmed Moussa <moussa.ahmed95@gmail.com>
* @version 2.0
* @link https://github.com/hamada147/IsThisColourSimilar
* @license Apache-2.0
*/
class Color {
/**

View file

@ -1 +0,0 @@
# Moved to [alifurkany/avt](https://gitlab.com/alifurkany/avt)