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 / ios_platform_map.php
Last active April 7, 2016 02:22
Apple UIDeviceHardware platformString Map
<?php
/* Sources:
* https://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m
* https://github.com/squarefrog/UIDeviceIdentifier/blob/master/UIDeviceIdentifier/UIDeviceHardware.m
* http://theiphonewiki.com/wiki/Models
* http://www.everymac.com/systems/apple/iphone/specs/apple-iphone-5c-a1529-asia-pacific-australia-specs.html
* https://www.apple.com/ipad/LTE/
* http://www.enterpriseios.com/device/iPhone6,1
* http://stackoverflow.com/questions/12505414/whats-the-device-code-platform-string-for-iphone-5-5c-5s-ipod-touch-5
@kamermans
kamermans / sessionclean
Created August 13, 2014 00:08
Replacement PHP session cleaner for Ubuntu (place inside /usr/lib/php5/)
#!/bin/sh
# check if file-based sessions are enabled
file_storage=$(/usr/lib/php5/sessionstorage | grep '^files$' -c)
if [ "$file_storage" = "0" ]; then
exit 0
fi
# first find all used files and touch them (hope it's not massive amount of files)
@kamermans
kamermans / rc.php
Created August 29, 2014 18:40
A better psysh/rc.php that automatically loads your composer autoloader
<?php
/**
* This is a better Psysh rc.php
*/
$add_composer_autoloader = function(array $config) {
static $was_run = false;
if ($was_run) {
return $config;
@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 / install_jq.sh
Created January 22, 2015 17:21
Install jq (JSON Command Line processor)
#!/bin/bash -e
# This scripts installs jq: http://stedolan.github.io/jq/
JQ=/usr/bin/jq
curl https://stedolan.github.io/jq/download/linux64/jq > $JQ && chmod +x $JQ
ls -la $JQ
@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"