Skip to content

Instantly share code, notes, and snippets.

View kamermans's full-sized avatar
😏

Steve Kamerman kamermans

😏
View GitHub Profile
@kamermans
kamermans / mktests.sh
Created March 16, 2014 02:15
Add empty PHPUnit test files for each PHP file in your project
#!/bin/bash
for FILE in $(find ./src/ -type f -name "*.php" | sed -e 's#/src/#/tests/#' -e 's#\.php$#Test.php#'); do
mkdir -p $(dirname $FILE) 2>/dev/null
touch "$FILE"
done
@kamermans
kamermans / download_ubuntu_14_04.pl
Created April 17, 2014 06:35
Automatically downloads Ubuntu 14.04 when it is released
#!/usr/bin/perl
use POSIX qw(strftime);
$url = 'http://releases.ubuntu.com/14.04/ubuntu-14.04-server-amd64.iso';
$check_delay = 300;
$|++;
while (1) {
@kamermans
kamermans / ServeCommand.php
Created August 8, 2014 03:21
Silex/Symfony command to start the builtin PHP webserver, inspired by Laravel/Illuminate
<?php
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
// Use this if you are using knplabs/console-service-provider for Silex console applications
use Knp\Command\Command;
@kamermans
kamermans / ThreadedStreamProcessor.php
Created December 31, 2014 20:18
PHP Threaded Stream Processor
<?php
class ThreadedStreamProcessor {
private $batch_size;
private $max_workers;
private $writer;
public function __construct($max_workers=null, $batch_size=10000) {
$this->max_workers = $max_workers?: max(1, $this->getCpuCores(true) - 1);
@kamermans
kamermans / xen-vmware-prep.sh
Last active August 29, 2015 14:14
Prepares an Ubuntu VM on XenServer to be moved to VMware via the vCenter Converter
#!/bin/sh
#
# This script prepares an Ubuntu VM that is hosted on Xen
# to be moved to a VMware server via the vCenter Converter
#
# WARNING!: This script will almost certainly mess up your VM
# so you should snapshot it in Xen first. Worst case, you will
# need to fix /etc/fstab and /etc/defaults/grub to get it working
#
# Note that unless you have my magic converter-helper-vm-x64.iso
@kamermans
kamermans / getRsyslogMetric.pl
Last active August 29, 2015 14:18
Rsyslog impstats data parser for Zabbix (or anything else really)
#!/usr/bin/env perl
# Rsyslog Stats parser by Steve Kamerman
# To use:
#
# 1. Enable imstats in /etc/rsyslog.conf by putting this at the top:
#
# module(load="impstats"
# interval="300"
# severity="7"
@kamermans
kamermans / cleanup_releases.pl
Created April 16, 2015 02:20
Capistrano releases batch cleanup script
#!/bin/bash
ROOT_DIR="/u/apps"
KEEP_RELEASES=5
echo "Cleaning releases folders (retaining $KEEP_RELEASES):"
for APP_DIR in $(find $ROOT_DIR -maxdepth 2 -type d -name releases); do
CURRENT_RELEASE=$(readlink -f "$APP_DIR/../current" | xargs basename)
echo " $APP_DIR (current: $CURRENT_RELEASE)"
@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 / 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 / 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 = {};