Skip to content

Instantly share code, notes, and snippets.

@p120ph37
p120ph37 / README.md
Last active Jan 25, 2021
Like `tee`, but with dynamically-attached socket clients
View README.md
teesocket.pl

Like tee, but with dynamically-attached socket clients

Usage

Server mode

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

@p120ph37
p120ph37 / dnsping.c
Created Nov 21, 2020
Monitor the latency of hostname resolution
View dnsping.c
#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 Nov 19, 2020
Time the DNS query response time for a particular domain name
View dns ping
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 Jun 19, 2020
Stuntman install for CentOS
View install_stuntman.sh
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 Apr 28, 2020
Using BuildInfo in Gradle without Spring Boot
View BuildInfoExample.java
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 Feb 25, 2020 — forked from tylerwalts/setupOSX.sh
This is a bash script to setup Mac OS X defaults on a new mac.
View setupOSX.sh
#!/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 Dec 4, 2018
Servlet Parameter Validator Utility Class
View ExampleUsage.java
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}$")
View autodeps.pm
###
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 Sep 25, 2018
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.
View Single_line_BadIdea.bgptheme
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
View gist:e4fb0bdc52d2f1961a45f77e22303bcc
task depsize {
group 'Help'
description 'Displays the sizes of all dependencies.'
doLast {
def size = 0, formatStr = "%,10.2f", out = new StringBuffer()
configurations.default.collect{it.length() / (1024 * 1024)}.each{size += it}
out << 'Total dependencies size:'.padRight(45)
out << "${String.format(formatStr, size)} Mb\n\n"
configurations.default.sort{-it.length()}.each {
out << "${it.name}".padRight(45)