Skip to content

Instantly share code, notes, and snippets.

View oliverkwebb's full-sized avatar

Oliver Webb oliverkwebb

View GitHub Profile
@oliverkwebb
oliverkwebb / discordreactable.awk
Last active July 22, 2024 18:56
Hetrogram detector: Find out if a (alphabetic) line of text could be reacted to in emoji-form with discord
#!/bin/awk -f
# Under Public Domain
{
delete a; b = 0
$0 = tolower($0)
# Compacting for mmultiletter Combinational Emojis:
gsub("ab", "A") # :ab:
gsub("abc", "B") # :abc:
gsub("atm", "T") # :atm:
@oliverkwebb
oliverkwebb / chmdc.c
Last active August 9, 2024 04:11
Linux permissions visualizer
// chmdc.c, Linux permissions visualizer
// By Oliver Webb (2024), Inspired by cheat.sh/chmod/####, In Public Domain
#include <stdio.h>
#include <stdlib.h>
char *propnames[3] = {"Read ", "Write", "Exec "},
*specnames[3] = {"Setuid", "Setgid", "Sticky"};
int main(int argc, char *argv[])
{
@oliverkwebb
oliverkwebb / timeconv.c
Created July 26, 2024 05:18
Time calculation functions, recreated from algorithms in "Astronomical Formula for Your calculator"
#include <time.h>
#include <math.h>
extern int printf(const char *format, ...);
extern long timezone;
#define isleap(y) ((!(y % 4)) ? ((!(y % 100)) ? !(y % 400) : 1) : 0)
#define INT(x) ((int)(x))
#define FRACP(x) ((x)-INT(x))
// HEADER: include/astrotime.h
@oliverkwebb
oliverkwebb / luhn.c
Created August 24, 2024 07:23
A implementation of luhn's algorithm in C
// Implementation of luhn's algorithm
// See: https://cs50.harvard.edu/x/2024/psets/1/credit/
// This code is in the public domain
// TODO: Credit card type checking
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
static void invalid()
@oliverkwebb
oliverkwebb / ordindic.c
Created September 3, 2024 17:40
Convert number into ordinal indicator form i.e 1 -> 1st, 32 -> 32nd, etc
// Ordinal Indicator
#include <stdio.h>
#include <stdlib.h>
static const char *ordindic(long num)
{
int lpr = abs(num % 100);
if (lpr >= 11 && lpr <= 14) lpr = 0;
lpr %= 10;
if (lpr > 3 || !lpr) return "th";
@oliverkwebb
oliverkwebb / pngdata.c
Last active September 6, 2024 23:58
Get header information from PNG file
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <arpa/inet.h>
int main(int argc, char **argv)
{
char *colors[] = {
"Greyscale", "INVALID", "RGB", "Indexed Color",
"Greyscale w/ alpha", "INVALID", "RGBA"
@oliverkwebb
oliverkwebb / swapf.c
Created September 7, 2024 14:34
swapf: Do byteorder swaps on memory with variable integer length (i.e. structs)
#include <stdint.h>
#include <byteswap.h>
void swapf(void *mem, const char *fmt)
{
char *m = (char *)mem;
for (;;fmt++) switch (*fmt) {
case '1': case 'b':
m++;
break;
@oliverkwebb
oliverkwebb / getepoch.go
Last active September 8, 2024 18:20
Print the bounds of the epoch at various resolution and (signed) integer width
package main
import "fmt"
import "math"
import "time"
func main() {
tz, err := time.LoadLocation("UTC")
if err != nil { // Always check errors even if they should not happen.
panic(err)
@oliverkwebb
oliverkwebb / bigcal.sh
Created September 21, 2024 05:21
Print a big calander - Adaption of Jef Poskanzer 80's tool to be faster (and unfortunately less complete at the same time)
#!/bin/sh
#
# bigcal - make a 78-column version of the output of the "cal" command
#
# Pass it the same arguments you'd pass to cal, if any. If you try a
# full-year calendar, you probably won't get anything useful.
#
# Jef Poskanzer <jef@mail.acme.com>
cal "$@" | awk 'NR == 1 {printf "%s%s\n", substr(" ", length/2), $0}'
@oliverkwebb
oliverkwebb / dshot.sh
Created September 21, 2024 05:25
Simple screenshot utility for X with nsxiv previews
#!/bin/sh
DELAY="0"
MODE="D"
VIEWER="nsxiv"
SHOTPROMPT='1:Take shot\n2:Mode Change\n3:Delay+5s\n4:Delay-5s'
while true; do
SELITEM=$(printf "$SHOTPROMPT" | dmenu -h 16 -l 4 -p "Mode:$MODE Del:$DELAY")