Skip to content

Instantly share code, notes, and snippets.

View wheelerlaw's full-sized avatar
💻
Probably writing code

Wheeler Law wheelerlaw

💻
Probably writing code
  • Chicago
  • 02:26 (UTC -05:00)
View GitHub Profile
import java.io.IOException;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
/**
* Example demonstrating a ClassLoader leak.
*
* <p>To see it in action, copy this file to a temp directory somewhere,
@wheelerlaw
wheelerlaw / elevate.sh
Last active September 29, 2023 16:22
Running elevated commands from a non-elevated git-bash with the ability to pipe/redirect the output of the elevated command.
#!/usr/bin/env bash
elevate() {
powershell -Command "Start-Process cmd -ArgumentList \"/c\",\"$1 2>&1 | clip\" -Verb RunAs"
powershell -sta "add-type -as System.Windows.Forms; [windows.forms.clipboard]::GetText()"
}
import scala.collection.{AbstractIterator, Iterator}
import scala.collection.Iterator.empty
object ImplicitIteratorExtensions{
implicit final class InclusiveIterator[A](it: Iterator[A]){
/**
* The actual function to act upon the iterator. Emuluates a "do-while" loop. In other words, it will stop iterating on
* predicte failure, but will include that last result as a part of the iterator.
* @param predicate {A => Boolean} - A function that is evaluated on each result from the parent iterator.
* @return
@wheelerlaw
wheelerlaw / URLRegex.md
Last active June 28, 2018 17:55
A regex to parse and validate a URL. Language independent.
/
^(?:([^:\/?#]+):\/\/)?
(?:([a-zA-Z0-9\-_.+]+)(?:\:([a-zA-Z0-9\-_.+]+))?@)?
((?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)(?:\.(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?))*\.?)
(?:\:(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9]))?
(\/[^?#]*)?
(?:\?([^#]*))?
(?:#(.*))?$
/
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2'
}
}
apply plugin: com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
#!/bin/sh
# Use socat to proxy any protocol through an HTTP CONNECT firewall.
# Useful if you are trying to SSH into a remote server or clone git:// from inside a company.
#
# Requires that the proxy allows CONNECT to the port specified
# in this scripts arguments (e.g. git: 9418, SSH: 22, etc).
#
# Save this file as connectproxy somewhere in your path (e.g., ~/bin) and then run
# chmod +x connectproxy
# git config --global core.gitproxy connectproxy
@wheelerlaw
wheelerlaw / yaml2json
Created May 17, 2018 14:06
A very simple executable script to convert a YAML text stream to a JSON one.
#!/bin/sh
python3 -c '
import sys, yaml, json
try: json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)
except KeyboardInterrupt as e: print("Interrupted. Quitting..."); sys.exit(130)
'
@wheelerlaw
wheelerlaw / useful.sh
Last active March 6, 2023 21:19
A collection of useful bash scripts
#!/usr/bin/env bash
# List files that exist only in dir1. https://stackoverflow.com/a/24695424/1902896
comm -23 <(ls dir1 | sort) <(ls dir2 | sort)
# Find files with a certain name located in the specified directory
find <directory> -name "<file_name>" 2>/dev/null
# Find files with a certain name located in the specified directory, then loop over each file name, printing each one.
@wheelerlaw
wheelerlaw / vultr-hydrogen.sh
Last active June 25, 2020 01:18
Automate script to provision a server to function as an OpenConnect VPN server using Vultr
#!/usr/bin/env bash
sudo apt-get install -y ocserv software-properties-common
sudo add-apt-repository -y ppa:certbot/certbot
sudo apt-get update && sudo apt-get install -y certbot
sudo certbot certonly --standalone --preferred-challenges http -n --agree-tos --email whelderwheels613@gmail.com -d vpn.steele.co
(crontab -l 2>/dev/null; echo "@daily certbot renew --quiet && systemctl restart ocserv") | crontab -
sudo iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE
@wheelerlaw
wheelerlaw / p11-kit.sh
Last active May 18, 2018 00:35
Allow NSS applications to read the system certificate store
#!/usr/bin/env bash
find / -type f -name "libnssckbi.so" 2>/dev/null | while read line; do
sudo mv $line ${line}.bak
sudo ln -s /usr/lib/x86_64-linux-gnu/pkcs11/p11-kit-trust.so $line
done
sudo mount --bind -o nodev,ro /etc/ssl/certs /snap/core/current/etc/ssl/certs/
sudo mount --bind -o nodev,ro /usr/lib/x86_64-linux-gnu/pkcs11/p11-kit-trust.so /snap/firefox/85/libnssckbi.so