Skip to content

Instantly share code, notes, and snippets.

View kamermans's full-sized avatar
😏

Steve Kamerman kamermans

😏
View GitHub Profile
@kamermans
kamermans / fail2ban-allstatus.sh
Created July 11, 2011 17:06
Show status of all fail2ban jails at once
#!/bin/bash
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
for JAIL in $JAILS
do
fail2ban-client status $JAIL
done
@kamermans
kamermans / install-hiphop-fresh.sh
Created July 12, 2011 16:46
Script for installing and compiling HipHop for PHP on a fresh install of Ubuntu 11.04 x64
#!/bin/bash
# HipHop for PHP scripted installation
# by Steve Kamerman, July 12, 2011
echo -e "\e[00;31m**** Installing Prerequisites\e[00m"
sudo apt-get --yes install git-core cmake g++ libboost-dev libmysqlclient-dev libxml2-dev libmcrypt-dev libicu-dev openssl binutils-dev libcap-dev libgd2-xpm-dev zlib1g-dev libtbb-dev libonig-dev libpcre3-dev autoconf libtool libcurl4-openssl-dev libboost-system-dev libboost-program-options-dev libboost-filesystem-dev wget memcached libreadline-dev libncurses-dev libmemcached-dev libicu-dev libbz2-dev libc-client2007e-dev php5-mcrypt php5-imagick libgoogle-perftools-dev
echo -e "\e[00;31m**** Getting HIPHOP in 5 seconds ****\e[00m"
@kamermans
kamermans / mysql_countries.sql
Created December 7, 2011 04:43
MySQL Dump - continents and countries with 2 and 3 char codes, names and full names - Braintree compatible as of Dec 2011
/**
* Continents and Countries MySQL Tables compiled from Wikipedia, Braintree Payments documentation
* and a couple other places I don't recall at the moment. This data is compatible with the Braintree
* Payment API as of Dec 2011
*
* Compiled by Steve Kamerman, 2011
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
@kamermans
kamermans / simple_dnsbl.php
Created January 2, 2012 01:32
Simple DNSBL/RBL PHP function - trust me, it's better than checkdnsrr, fsock, socket_create, Net::DNSBL and Net::DNS
<?php
// Simple DNSBL/RBL PHP function - trust me, it's better than checkdnsrr, fsock, socket_create, Net::DNSBL and Net::DNS
// Here's a [better] way to quickly check if an IP is in a DNSBL / RBL. It works on Windows and Linux,
// assuming nslookup is installed. It also supports timeout in seconds.
function ipInDnsBlacklist($ip, $server, $timeout=1) {
$response = array();
$host = implode(".", array_reverse(explode('.', $ip))).'.'.$server.'.';
$cmd = sprintf('nslookup -type=A -timeout=%d %s 2>&1', $timeout, escapeshellarg($host));
@exec($cmd, $response);
@kamermans
kamermans / install-mysql-pcre-udf.sh
Created January 22, 2012 20:28
Install MySQL PCRE (Perl-Compatible Regular Expression) UDF on Amazon Linux / CentOS / RedHat / Fedora
#!/bin/bash -e
# UDF Documentation: http://www.mysqludf.org/lib_mysqludf_preg/
yum -y install pcre-devel gcc make automake mysql-devel
wget http://www.mysqludf.org/lib_mysqludf_preg/lib_mysqludf_preg-1.0.1.tar.gz
tar -zxvf lib_mysqludf_preg-1.0.1.tar.gz
cd lib_mysqludf_preg-1.0.1
./configure
make install
echo "You'll need to enter your MySQL password a few times to install the UDFs and test them"
@kamermans
kamermans / auto_subscribe_moderators.php
Created February 20, 2012 15:31
Subscribe all phpBB3 moderators to all forums/topics
#!/usr/bin/php
<?php
/**
* This script subscribes all global moderators to all forums.
* Put this in your phpBB3 directory and do "chmod 0700 auto_subscribe_moderators.php"
* You can use crontab to run this script so your moderators stay subscribed!
*/
// Path to the phpBB3 Config Script
require dirname(__FILE__).'/config.php';
@kamermans
kamermans / compute.conf
Created February 29, 2012 16:44
openstack-compute config file to use Rackspace UK API
# put this file in ~/.openstack/compute.conf
[openstack.compute]
username=your_user_name
apikey=your_api_key
auth_url=https://lon.auth.api.rackspacecloud.com/v1.0
@kamermans
kamermans / analyze_haproxy_performance.pl
Created April 6, 2012 15:41
HAProxy log analyzer to show response latency distribution from the console
#!/usr/bin/perl
# HAProxy Performance Statistics
# by Steve Kamerman
#
# To use, pipe your HAProxy log with timing information (like "0/0/1/1/3 200") to
# this script. It will output min, max, med, avg and a latency distribution graph.
#
# Info on timing logging in HAProxy: http://code.google.com/p/haproxy-docs/wiki/TimingEvents
#
@kamermans
kamermans / mongo_mapreduce.js
Created May 6, 2012 22:04
MongoDB Incremental Map Reduce script to aggregate unique values in batches based on date
map = function() {
if (!this.fruits) return;
var skip_fruits = {
'Watermelon':1,
'Grapefruit':1,
'Tomato':1 // yes, a tomato is a fruit
}
for (var fruit in this.fruits) {
if (skip_fruits[fruit]) continue;
var obj = {};
@kamermans
kamermans / mongo_monitor.php
Created May 6, 2012 22:08
HTML5 MongoDB process monitor with MapReduce visual progress meter
<?php
$db = new Mongo('mongodb://127.0.0.1');
$ops = $db->ua->selectCollection('$cmd.sys.inprog');
$ops_doc = $ops->findOne();
function duration($secs) {
$vals = array(
'y' => intval($secs / 86400 / 365),
'w' => intval($secs / 86400 / 7) % 52,
'd' => $secs / 86400 % 7,