Skip to content

Instantly share code, notes, and snippets.

@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 / gist:c0a6bd7579cb87446eeb
Last active July 15, 2020 00:38
A better one-line webserver in Perl
socket$_,2,1,6;setsockopt$_,1,2,pack"l",1;(bind$_,pack"snN3",2,pop)||die$!;listen$_,128;{accept+my($c),$_;fork&&redo;($_)=<$c>=~/(\/\S*)/;s/%([0-9a-f]{2})/pack"H2",$1/eig;s-/$-/index.html-;!/\.\./&&open$a,"<.$_"||last;syswrite$c,"HTTP/1.1 200\x0D\x0A\x0D\x0A";syswrite$c,$,until!sysread$a,$,,1024}
@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 / perl_inject.pl
Last active September 21, 2019 03:46
Inject an eval into a running Perl process using GDB and temporarily capture STDERR.
#!/usr/bin/perl
use warnings;
use strict;
use threads;
use File::Temp;
use POSIX qw/mkfifo/;
my $pid = shift @ARGV;
my $eval = shift @ARGV || 'require Carp; local $Carp::CarpLevel = 1; Carp::cluck(\'Currently\');';
my $thread = $ENV{'GDB_THREAD'} || 'all';
@p120ph37
p120ph37 / chunkedpost.c
Created August 30, 2015 18:46
Curl example with chunked post
/*
* HTTP POST with chunked encoding.
*
* Usage:
* cc chunkedpost.c -lcurl -o chunkedpost
* ./chunkedpost
*
*/
#include <stdio.h>
#include <stdlib.h>
@p120ph37
p120ph37 / gdrive-dropbox-sync.plist
Last active February 20, 2019 11:55
This is the launchd.plist file that keeps my Dropbox and Google Drive folders synchronized.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>local.gdrive-dropbox-sync</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string><string>-c</string>
<string>/usr/local/bin/unison \
-times \
@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}$")