Skip to content

Instantly share code, notes, and snippets.

@rodmcnew
rodmcnew / props.conf
Last active December 27, 2015 14:28
Prevent Splunk from breaking PHP stack traces into multiple error events with this LINE_BREAKER regular expression.
# props.conf is at /opt/splunk/etc/system/local/props.conf in debian/ubuntu
#
# Example log entry:
#[Wed Nov 06 17:10:30.436963 2013] [:error] [pid 1238] [client 127.0.0.1:51876] PHP Notice: this is a test warning 22 in /var/www/warning.php on line 2
#[Wed Nov 06 17:10:30.437020 2013] [:error] [pid 1238] [client 127.0.0.1:51876] PHP Stack trace:
#[Wed Nov 06 17:10:30.437037 2013] [:error] [pid 1238] [client 127.0.0.1:51876] PHP 1. {main}() /var/www/warning.php:0
#[Wed Nov 06 17:10:30.437050 2013] [:error] [pid 1238] [client 127.0.0.1:51876] PHP 2. trigger_error() /var/www/warning.php:2
#
# This will prevent Splunk from breaking PHP stack traces into multiple events:
SHOULD_LINEMERGE = false
@rodmcnew
rodmcnew / ProfileDoctrine.php
Last active August 29, 2015 14:05
Easily see what queries doctrine is running for a page load
<?php
/**
* Inside doctrine locate the executeQuery() method inside the \Doctrine\DBAL\Connection class.
* ADD THE FOLLOWING TO THE BEGINNING OF THE executeQuery() METHOD:
*/
/**
* ADDED TO PROFILE QUERIES
*/
if (!isset($GLOBALS['queryCount'])) {
#There are many other ways to do this but i've found using these commands work best and are the least error prone
### How to pull down ###
git fetch origin master; git merge origin/master
#If there is an error here, fix it with:
#Open all conflict files, fix them, save them (you could use a diff tool here)
git add .; git commit -m "Merged change"
git fetch origin master; git merge origin/master
@rodmcnew
rodmcnew / BasicAuthMiddleware.php
Created April 22, 2016 20:12
HTTP Basic Auth Implementing Zend\Stratigility\MiddlewareInterface
<?php
namespace App\Controller;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Zend\Stratigility\MiddlewareInterface;
/**
* Class HttpBasicAuth
@rodmcnew
rodmcnew / addAdvancedSAS
Created May 26, 2016 04:36
KSP add KER, MechJeb, and Advanced SAS to every command part (module manager must be installed first)
@PART[*]:HAS[@MODULE[ModuleCommand],!MODULE[MechJebCore]]:Final
{
MODULE
{
name = ModuleSAS
SASServiceLevel = 3
}
}
// Returns black or white foreground color depending on the background
var textColor = function (backgroundColor) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(backgroundColor);
if (!result) {
return '#000000';//Happens when not given hex
}
var shade = (parseInt(result[1], 16) + parseInt(result[2], 16) + parseInt(result[3], 16)) / 3;
return shade > 128 ? '#000000' : '#FFFFFF';
}
@rodmcnew
rodmcnew / repeat.js
Last active July 19, 2016 16:57
repeat.js
var exec = require('child_process').exec;
var cmd = process.argv[2];
console.log(' - - - ');
console.log('Running the following command repeatedly:');
console.log(cmd);
var count = 0;
var averageSumTime = 0;
var averageTime = 0;
/**
* Paste this code at the top of \Doctrine\DBAL\Connection:executeQuery()
*/
$startTime = microtime(true);
//Body of \Doctrine\DBAL\Connection:executeQuery() goes here
<html>
<head>
<!-- @TODO uso more official polymer urls than cdn.rawgit.com/download-->
<script src="https://cdn.rawgit.com/download/polymer-cdn/1.5.0/lib/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="https://cdn.rawgit.com/download/polymer-cdn/1.5.0/lib/iron-ajax/iron-ajax.html">
<style>
h1 {
text-align: center;
font-size: 50px;
@rodmcnew
rodmcnew / select-between-xml-tags.sql
Last active October 10, 2016 13:48
mysql - select between xml tags
SELECT
substring_index(substring_index(log, '<FUNTAG>', -1),'</FUNTAG>', 1) as funtag,
substring_index(substring_index(log, '<ANOTHERFUNTAG>', -1),'</ANOTHERFUNTAG>', 1) as anotherfuntag