Skip to content

Instantly share code, notes, and snippets.

@p120ph37
p120ph37 / minio-client.sh
Last active July 21, 2023 18:37
MinIO S3 in Alpine with instance-IAM-role credentials
# Using AWS instance IAM role to provide credentials to minio-client cli.
# Works in Alpine 3.18+ (the minio-client package is not available in 3.17)
# Should also work anywhere else minio, curl, and jq can run.
# Provides a very-lightweight way to access S3 from Alpine
apk add minio-client curl jq
export MC_HOST_s3=$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/$(curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/ | head -1) | jq -r '"https://\(.AccessKeyId):\(.SecretAccessKey):\(.Token)@s3.amazonaws.com"')
mcli ls s3/mybucket
@p120ph37
p120ph37 / README.md
Last active January 25, 2021 18:13
Like `tee`, but with dynamically-attached socket clients
teesocket.pl

Like tee, but with dynamically-attached socket clients

Usage

Server mode

./teesocket.pl -s /tmp/my.sock

@p120ph37
p120ph37 / dnsping.c
Created November 21, 2020 01:49
Monitor the latency of hostname resolution
#include <arpa/inet.h>
#include <limits.h>
#include <math.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
extern int h_errno;
@p120ph37
p120ph37 / dns ping
Created November 19, 2020 23:00
Time the DNS query response time for a particular domain name
perl -MTime::HiRes=gettimeofday,tv_interval -e'my $tv=[gettimeofday];gethostbyname($ARGV[0]);print tv_interval($tv)."\n"' -- example.com
@p120ph37
p120ph37 / install_stuntman.sh
Created June 19, 2020 16:07
Stuntman install for CentOS
yum install -y curl make gcc-c++ boost-devel openssl-devel
curl http://www.stunprotocol.org/stunserver-1.2.16.tgz | tar -xz
cd stunserver
make
cp stunserver /usr/sbin
cat - >/etc/init.d/stunserver <<'END'
#!/bin/sh
# chkconfig: 345 91 09
### BEGIN INIT INFO
# Provides: stunserver
@p120ph37
p120ph37 / BuildInfoExample.java
Last active April 28, 2020 20:28
Using BuildInfo in Gradle without Spring Boot
import java.io.IOException;
import java.util.Map.Entry;
import java.util.Properties;
public class BuildInfoExample {
public static void main(String[] args) throws IOException {
Properties buildInfo = new Properties();
buildInfo.load(BuildInfoExample.class.getClassLoader().getResourceAsStream("META-INF/build-info.properties"));
for(Entry<Object, Object> entry : buildInfo.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
@p120ph37
p120ph37 / setupOSX.sh
Last active February 25, 2020 04:42 — forked from tylerwalts/setupOSX.sh
This is a bash script to setup Mac OS X defaults on a new mac.
#!/bin/bash
#
# Set up OSX preferences
#
# Inspired by: https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###########################################
# CONFIG
if [ "$#" -lt 2 ]; then
echo -e "Usage: $0 {hostname} {timezone}\nExample: $0 machiavellia America/New_York"
@p120ph37
p120ph37 / ExampleUsage.java
Last active December 4, 2018 15:11
Servlet Parameter Validator Utility Class
public class ExampleUsage extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final ParameterValidator validator = new ParameterValidator()
.regex("userName", "^[a-z0-9.]{1,20}$")
.regex("fullName", "^[A-Za-z0-9.]{1,40}$", false)
.regex("street", "^[A-Za-z0-9 ]{1,30}$")
.regex("city", "^[A-Za-z ]{1,30}$")
.regex("zip", "^[A-Za-z0-9 ]{1,20}$")
###
package autodeps;
###
use strict;
use warnings;
use Cwd qw/cwd abs_path/;
use File::Basename qw/dirname/;
use File::Spec::Functions qw/catdir/;
@p120ph37
p120ph37 / Single_line_BadIdea.bgptheme
Last active September 25, 2018 22:57
A theme for https://github.com/magicmonty/bash-git-prompt, based on Single_line_Ubuntu, but with some spacing adjustment and with the Git path colorized and the branch name injected at the base of it rather than the end.
override_git_prompt_colors() {
gp_pwd() {
local git_top="$(git rev-parse --show-toplevel 2> /dev/null)"
case "$1" in
out) local out="${git_top:+$(dirname $git_top)/}"; out="${out:-$PWD}"; printf '%s' "${out/#$HOME/~}" ;;
in) printf '%s' "${git_top:+${PWD#$git_top}}" ;;
*) printf '%s' "${git_top:+$(basename $git_top)}" ;;
esac
}
# Based mostly on Single_line_Ubuntu, but with some excess space removed