Skip to content

Instantly share code, notes, and snippets.

@hackerb9
hackerb9 / IBM5100-NYT-1975-Sept-10.png
Last active August 20, 2021 20:36
Screenshot from New York Times, September 10, 1975, page 75 (via "Times Machine")
IBM5100-NYT-1975-Sept-10.png
@hackerb9
hackerb9 / gitfixssh
Created August 20, 2021 05:34
Fix existing github repository to use ssh access instead of username/password
#!/bin/bash
# A temporary script for a temporary problem.
# I have a bunch of github repositories that no longer work
# for git push because the original URL uses the deprecated
# username/password combo. This script repairs the remote
# origin so it uses ssh.
# B9 August 2021
@hackerb9
hackerb9 / bogodisk
Created August 1, 2021 05:19
A quick hack, no-frills disk speed test. Works with any mountable filesystem (SSD/SATA/IDE/tmpfs...). Just specify the directory you'd like to write the test file to -- defaults to /tmp. Uses 'dd' for a quick test (default is 64MB) and then tries hdparm to run a three second test of direct I/O (no filesystem). It's just a shell script, so this s…
#!/bin/bash -e
# Bogus disk speed tester by b9 2016-2021
# Well, not exactly bogus, but overly simplistic.
TMPDIR=/tmp # where to write the file
COUNT=64 # number of blocks
BS=1 # blocksize (in *MEGA*bytes)
total=$((COUNT*BS))
[ "$1" ] && TMPDIR="$1" # Usage: bogodisk [dir [count]]
@hackerb9
hackerb9 / lookup.py
Last active November 4, 2019 07:14
Simplest example of parsing text files of ITIS taxonomy
#!/usr/bin/python3
# globals
name={}
hierarchy={}
vernacular={}
synonyms={}
def loaddb():
"Load up databases into dictionaries: name, hierarchy, vernacular"
@hackerb9
hackerb9 / iptables-redirect.conf
Created August 11, 2019 16:50
/etc/fail2ban/action.d/iptables-redirect.conf: After login failures, redirect to a different port. Handy for sending attackers to your honeypot
# Fail2Ban configuration file
#
# Redirect from a certain port to a different port on the same host
# Example usage:
# # By default redirects port=22, toport=2222, protocol=tcp
# action = iptables-redirect[name=cowrie]
#
# # Can specify other defaults if you'd like.
# action = iptables-redirect[name=web, proto=tcp, port=80, toport=8080]
#!/bin/bash
# XXX showanddelete hacked to show best view by default and to
# change the image every five seconds if no key pressed.
# Maximum number of seconds to wait for a response from the terminal
# after a an escape sequence query. Usually, terminals respond much
# faster than 0.1 seconds, but may need to be increased for slow links
# (e.g., RS232C, ssh).
TIMEOUT=0.1
@hackerb9
hackerb9 / example.svg
Last active April 5, 2024 16:57
Extract vector images from funky PDF files
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hackerb9
hackerb9 / bwtest.sh
Last active May 7, 2024 20:02
Busybox compatible simple speedtest that downloads a file to /dev/null. Useful for sshing into various routers and seeing where the bottleneck is.
#!/bin/sh
# Silly speed test just by downloading a file directly to /dev/null
# Useful on routers which only have busybox installed.
# ↄ⃝🄯 B9 2016, 2018, 2023. Creative Commons Zero.
# NOTA BENE: cachefly has worked for over a decade, however they may
# be getting tired of scripts like this. Starting February 2023, their
# 100mb.test file is empty and the 50mb.test file holds 100MB.
dotest() {
@hackerb9
hackerb9 / ttest.bc
Last active June 27, 2019 12:32
Example of performing Student's t-test using the GNU bc calculator. The heart of this is just the short function at the beginning, the rest is there to make using it easier. (For example, there's a t-table builtin to tell you if the means are significantly different.)
/* Student's t-test (Two Independent Samples) */ /* -*- c -*- */
/* Implemented in GNU bc by hackerb9, 2018. */
/* Copyright assigned to FSF. */
/*
*
* µ₀ - µ₁
* t = ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
* ⎡ ⎤ ½
* ⎢ (ΣA² - (ΣA)²/n₀) + (ΣB² - (ΣB)²/n₁) ⎛ 1 1 ⎞ ⎥
@hackerb9
hackerb9 / ttest.bc
Created September 13, 2018 08:02
Example of performing Student's t-test using the GNU bc calculator. The heart of this is just the short function at the beginning, the rest is there to make using it easier. (For example, there's a t-table builtin to tell you if the means are significantly different.)
/* Student's t-test (Two Independent Samples) */
/* Implemented in GNU bc by hackerb9, 2018. */
/* Copyright assigned to FSF. */
/*
*
* µ₀ - µ₁
* t = ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
* ⎡ ⎤ ½
* ⎢ (ΣA² - (ΣA)²/n₀) + (ΣB² - (ΣB)²/n₁) ⎛ 1 1 ⎞ ⎥