Skip to content

Instantly share code, notes, and snippets.

View kristopolous's full-sized avatar
💣
New releases are coming soon!

chris mckenzie kristopolous

💣
New releases are coming soon!
View GitHub Profile
@kristopolous
kristopolous / top-10-slow.sh
Last active November 3, 2022 02:59
top-10 URIs in the apache log in pure bash
#!/bin/bash
# This is a very crazy 1-liner that only uses builtins
#set -o noglob;declare -a mapper=() count=();exec 3<access.log; while read -a lines -u 3; do [[ ${lines[5]} != '"GET' ]] && continue; page="${lines[6]}"; ix=0;for i in "${mapper[@]}"; do [[ "$page" = "$i" ]] && break; (( ix++ )); done ; if [[ "$page" = "$i" ]]; then (( count[$ix] ++ )); else mapper+=( $page ); count[$ix]=1; fi; done; (( max=-1, winner=-1, show=10 )); while (( show > 0 )); do ix=0;for i in "${count[@]}"; do (( i > max )) && (( max=i, winner=ix )) ;(( ix++ ));done; builtin echo -e "${count[winner]}\t${mapper[$winner]}";(( count[$winner]=-1, max=0, show-- )); done;
# Here's a formatted nice version
# We need to make sure that bash doesn't do weird substitution
set -o noglob
declare -a mapper=() count=()
# And to avoid cat we do file descriptors
exec 3<access.log
@kristopolous
kristopolous / animal-say.sh
Last active October 31, 2022 05:05
Animal-say fortune, like cowsay but more animals and faster
#!/bin/bash
cat << ENDL
- - - ~ ~~~~==~#=###=#~==~~~~~ ~ - - -
$(fortune | sed -E 's/^\s+//g' | fold -sbw 40 | sed -E 's/^/ /')
- - - ~ ~~~~==~#=###=#~==~~~~~ ~ - - -
$(curl -s https://9ol.es/animals.db | shuf -n 1 | tr 'F' '\n' | gawk ' { if (FNR == 1) { printf " \\ ";} else if (FNR == 2) { printf " \\ "; } else { printf " " }; print $0 } ';)
ENDL
@kristopolous
kristopolous / simple-datepicker-react.js
Last active January 25, 2022 23:21
simple datepicker using Intl.DateTimeFormat
// this is more a guide than working code.
constructor(props) {
super(props);
let minimum_age = 21;
this.endyear = (new Date().getYear() + 1900) - minimum_age;
this.state = {
dob_year: this.endyear,
dob_month: 0
@kristopolous
kristopolous / generate-words.py
Created January 5, 2022 02:37
No solution word search
#!/usr/bin/env python3
# Here's the prompt:
#
# Construct a "word search" N x M letter grid where:
#
# * There are NO possible words horizontal or vertical
# * The letters appear random with no trivial patterns
# * The frequency distribution of letters is close to English prose
#
# This is a naive implementation
@kristopolous
kristopolous / transp.py
Last active September 20, 2021 07:22
transposition die roll example
#!/usr/bin/env python3
import random
def encode(plain):
plain = list(plain)
cypher = ''
while len(plain) > 0:
# Roll a die, add 3 to the result
step = random.randint(4,9)
# start at the beginning of the remaining string
#/bin/bash
# /etc/init.d/xdm: Login Procedure for Bob480
# Edited Sept-2001; Contact Author: [email protected]
n=$1
n=$n"."
[ $n == "stop." ] && exit
moveon=0
set PATH="/bin:/usr/bin:/sbin"
#!/usr/bin/python
import sys
import png
import os
import numpy as np
import json
import math
import time
import random
#!/usr/bin/python
import sys
import png
from pprint import pprint
cx = 0
width = 4000
height = 4000
image = [ [ 0 for y in range ( width ) ] for x in range( height ) ]
import sys, math
width=14400
height=10800
image = [ [ 0 for y in range ( width ) ] for x in range( height ) ]
maxval = 7
delta_lng = .9
delta_lat = delta_lng * 28/40
lng_low = -118.8
lng_high = lng_low + delta_lng
@kristopolous
kristopolous / tcpdump-on-device.md
Created May 31, 2017 19:45
tcpdump on a device without disk space

On the device to capture from we set up a FIFO that will be pushed off to another device on the network with disk, in this case we are using 192.168.1.11 as the "host"

On the host, we start up netcat that will be pushed into a capture file that we can analyze later, in this instance, we are listening on port 5001 $ nc -l -p 5001 > capture.cap

In a terminal on the device we make a fifo and then push it out over the network through netcat $ mknod /tmp/fifo p $ cat fifo | nc 192.168.1.11 5001