Skip to content

Instantly share code, notes, and snippets.

View typhonius's full-sized avatar

Adam Malone typhonius

View GitHub Profile
@typhonius
typhonius / cache_plotter.php
Created February 4, 2014 06:09
Memcache by default will not accept objects larger than 1M. This script looks through all the Drupal cache tables (provided they're named correctly) and discovers any objects that would blow this requirement. Table names cannot be prepared as these are not variables that cannot be altered at runtime without changing the meaning of the query. It …
<?php
$user = '';
$pass = '';
$database = '';
$limit = 1000000;
$dsn = 'mysql:dbname=' . $database . ';unix_socket=/var/run/mysqld/mysqld.sock';
try {
@typhonius
typhonius / nginx_top_forwards
Created February 9, 2014 10:45
Will split all forwarded for IPs and count how many there are.
watch 'grep -o "forwarded_for=\".*\" " nginx.log | cut -d= -f2 | sed -e "s/\"//g" | tr "," "\n" | tr -d " " | sort -n | uniq -c | sort -nr | head -n20'
@typhonius
typhonius / newmac
Created February 22, 2014 23:02
Sets a new mac address
newmac() {
MAC=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`
echo "Setting MAC address to $MAC"
sudo ifconfig en0 ether $MAC
}
@typhonius
typhonius / pound.cfg
Created February 23, 2014 07:52
pound configuration file
User "apache"
Group "apache"
#RootJail "/var/pound/jail"
#Alive 60
ListenHTTPS
HeadRemove "X-Forwarded-Proto"
AddHeader "X-Forwarded-Proto: https"
Address 0.0.0.0
Port 443
user_restrictions_create_form:
route_name: user_restrictions.create_form
title: 'Add rule'
appears_on:
- user_restrictions.list_form
@typhonius
typhonius / cacheplotter.drush.inc
Created April 30, 2014 09:51
I feel dirty putting the Drupal 6.x integration in there but it's still a supported API version so w/e. This checks your db cache tables for sizes of values. Useful if you're using memcache and are worried about exceeding the max page size.
<?php
/**
* @file
* Drush command to check for overly large items in DB cache tables that will
* not work with memcache.
*/
/**
* Implements hook_drush_command().
@typhonius
typhonius / ghetto_load_detector.sh
Created August 8, 2014 07:49
Ultra dirty, super basic, nagios replacement.
#!/bin/bash
STLOAD=$(cat /proc/loadavg | awk '{print $1}')
while true; do
FINLOAD=$(cat /proc/loadavg | awk '{print $1}')
if (( $(echo "$STLOAD $FINLOAD" | awk '{ if ($1 >= 8 && $2 >= 8) print 1}') )); then
if [[ -z $TIME ]]; then
TIME=$(date +"%s")
fi
@typhonius
typhonius / more_ape_tests.patch
Last active August 29, 2015 14:08
further tests for ape
diff --git a/ape.test b/ape.test
index 756cfeb..f34a7fe 100644
--- a/ape.test
+++ b/ape.test
@@ -31,6 +31,7 @@ class ApeTestHelper extends DrupalWebTestCase {
$modules[] = 'path';
$modules[] = 'user';
$modules[] = 'common_test';
+ $modules[] = 'ape_redirect_test';
parent::setUp($modules);
@typhonius
typhonius / cidr2varnish.pl
Last active August 29, 2015 14:10
Changes IP address CIDRs to varnish vcl regex.
#!/usr/env/perl
use strict;
use warnings;
use Net::Netmask;
use Regexp::Assemble::Compressed;
print "Enter the filename to varnishize: ";
my $filename = <STDIN>;

Keybase proof

I hereby claim:

  • I am typhonius on github.
  • I am typhonius (https://keybase.io/typhonius) on keybase.
  • I have a public key whose fingerprint is 81AC 744D AEA4 BB5F 6971 D78E 8521 A8CC D186 9962

To claim this, I am signing this object: