Skip to content

Instantly share code, notes, and snippets.

View uplime's full-sized avatar
👻
Spooky

Nick Chambers uplime

👻
Spooky
View GitHub Profile
@uplime
uplime / quine.sh
Created June 12, 2026 17:31
Display a program's source as its output.
quine ()
{
type quine | {
read;
IFS= read -rd '' func;
printf %s "$func"
};
printf quine
}
quine
@uplime
uplime / cidr
Created June 12, 2026 17:30
A forgiving CIDR calculator.
#!/usr/bin/env bash
bin() {
local str num=$1
while (( num > 0 )); do
str=$(( num % 2 ))$str
(( num /= 2 ))
done
@uplime
uplime / sheconds
Created June 12, 2026 17:29
Convert seconds to a human-readable timestamp.
#!/usr/bin/env bash
# The variables are checked dynamically
# shellcheck disable=SC2034
seconds() {
local day hour minute second span time
(( day = $1 / 60 / 60 / 24 ))
(( hour = $1 / 60 / 60 % 24 ))
(( minute = $1 / 60 % 60 ))
(( second = $1 % 60 ))
@uplime
uplime / tickertape
Created June 12, 2026 17:28
Display a tickertape for a line of text across the terminal.
#!/usr/bin/env bash
cols=$(tput cols) line=""
while (( ${#line} < cols + ${#1} )); do
if (( ${#line} < ${#1} )); then
line=${1:$((${#1}-${#line}-1)):1}$line
else
line=" $line"
fi
@uplime
uplime / vigenere
Created June 12, 2026 17:28
A vigenere encoder and decoder.
#!/usr/bin/env bash
numeric() {
printf %d "$(( $(printf %d \'"${1,}") - $(printf %d \'a) ))"
}
vigenere_enc() {
local key=$1 plain=$2 idx {plain,key}_pos incr offset
for (( idx = 0; idx < ${#plain}; idx += 1 )); do
@uplime
uplime / bucket
Created June 12, 2026 17:25
Simple terminal games written in shell scripts.
#!/usr/bin/env bash
clear() {
printf "\x1b\x5b\x48\x1b\x5b\x32\x4a"
}
red() {
local red=$'\x1b\x5b\x33\x31\x6d'
local rst=$'\x1b\x28\x42\x1b\x5b\x6d'
printf %s%s%s "$red" "$1" "$rst"
@uplime
uplime / b64-encode.sh
Created June 12, 2026 17:24
A base64 encoder written in Bash.
#!/usr/bin/env bash
b64_encode() {
local idx=0 numerics table_idxs table_idx encoded
local table=( {A..Z} {a..z} {0..9} + / )
for (( ; idx < ${#1}; idx+=3 )); do
read -ra numerics < <(
printf '%d %d %d\n' "'${1:idx:1}" "'${1:idx+1:1}" "'${1:idx+2:1}"
)
@uplime
uplime / decip.c
Created June 12, 2026 17:22
Turn an IP into a numeric decimal.
#include <stdint.h>
#include <stdio.h>
uint32_t numeric_ip4(const char *ip) {
uint32_t octets = 0;
uint8_t octet = 0;
for(; *ip; ip += 1) {
if(*ip == '.') {
octets = (octets << 8) | octet;
@uplime
uplime / reverse.c
Created June 12, 2026 17:21
Display lines of input with every word reversed.
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
for(argc -= 1, argv += 1; *argv; argc -= 1, argv += 1) {
char *idx = *argv;
char *begin = NULL;
char *end = NULL;
@uplime
uplime / cosmic.c
Created June 12, 2026 17:18
A simple and effective glob star matcher.
int match(const char *needle, const char *haystack) {
while(*haystack || *needle) {
if(*needle == '*') {
if(*(needle + 1) == '\0') {
return 1;
} else if(*(needle + 1) == '*') {
needle += 1;
} else if(*(needle + 1) == *haystack) {
needle += 1;
} else if(*haystack == '\0') {