Skip to content

Instantly share code, notes, and snippets.

View Orc's full-sized avatar
🚎
On fire

Orc

🚎
On fire
View GitHub Profile
@Orc
Orc / cidr.c
Created March 31, 2017 20:29
A little program that converts a cidr ip/size into a base/mask pair for tcp wrappers
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include <stdlib.h>
@Orc
Orc / mkshar.sh
Created April 10, 2017 19:19
A tiny sharfile generator that uses base64 to encode/decode (for redhat Linux; base64 is in coreutils, which is an rpm prerequisite so it's more likely to always be there)
#! /bin/sh
#
# mkshar: make a shar file
#
usage() {
echo "usage: $0 [--rc file] payload [...]" 1>&2
exit 1
}
@Orc
Orc / md5s.c
Last active April 25, 2017 18:11
Q&D md5sum clone that uses Solar Designer's md5 implementation
/* Q&D md5sum clone that uses Solar Designer's md5 implementation */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "md5.h"
@Orc
Orc / dehtml.c
Last active May 15, 2017 21:19
Q&D html stripper for mutt
#include <stdio.h>
#include <string.h>
actualspace(register c)
{
return (c=='\r') || (c=='\n') || isspace(c);
}
int
@Orc
Orc / dateof.c
Created May 19, 2017 20:00
print a file date in a git-aware form (needed by pull.sh)
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <libgen.h>
#include <time.h>
main(argc, argv)
char **argv;
@Orc
Orc / pull.sh
Created May 19, 2017 20:02
create a git repository from a pile of tarballs (one tarball per commit, ordered cronologically, with the git dates forged to match the tarball dates)
#! /bin/ksh
#
extractomatic() {
tarball=$1
first_in_archive=`tar tzf $tarball | head -1`
path=`dirname ${first_in_archive}/thing`
when=`dateof $tarball`
export GIT_COMMITTER_DATE="$when"
@Orc
Orc / cu.c
Created July 18, 2017 02:09
A cu wrapper to fill the time between realizing that apple shipped an insufficiently privileged cu & being able to boot the machine into recovery mode for a `csrutil disable`
#include <stdio.h>
#include <unistd.h>
main(argc, argv)
char **argv;
{
/* to get around the goddamn macos privilege protection racket */
execv("/usr/bin/cu", argv);
perror("cu");
}
@Orc
Orc / tgoto.c
Created March 27, 2019 03:21
A tgoto() implementation for systems that don't have termcap
/*
* partial implementation of termlib's tgoto() function, with
* the optimization of caching compiled strings so they don't
* need to be recompiled evey time tgoto is called.
*
* "partial implementation" because I've got yet implemented %<xy
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@Orc
Orc / orphans.sh
Last active March 30, 2019 09:09
orphans: a q&d shell script to look for orphan functions in my code
#! /bin/sh
#
# Find functions that are defined but not referenced in a body of C code
test -f tags || ctags -M *.c
test -f tags || exit 1
FILES=`awk -F' ' '{print $2}' < tags | sort |uniq`
#! /bin/sh
HOSTS="tinyd gateway gehenna credit downbelow netbsd"
if [ ! "$1" ]; then
echo "usage: $0 {cmd}" 1>&2
exit 1
fi
cmd=$1