Skip to content

Instantly share code, notes, and snippets.

View wrossmann's full-sized avatar
👺
¯\_(ツ)_/¯

Wade Rossmann wrossmann

👺
¯\_(ツ)_/¯
  • Victoria, BC
View GitHub Profile
<?
foreach($filters as $pos => $filter) {
if( ! $filter instanceof Filter\FilterInterface ) {
throw new \InvalidArgumentException(
sprintf('Argument 3 passed to %s::%s must be an array of instances of %s, %s given for index %d',
__CLASS__, __FUNCTION__, 'Filter\FilterInterface', get_class($filter), $pos)
);
}
}

Directory structure:

src/
	Foo.php
	Foo/
		Exception.php
		Excecption/
			Unauthorized.php
			NotFound.php

Method.php

@wrossmann
wrossmann / StupidDecode.php
Created May 1, 2015 21:09
Reverse the lame home-rolled 'encryption' someone posted
<?php
// supplied encoding function
function stupidEncode($input, $key) {
$k = $key;
$r = $input;
$l = strlen($r);
$e = "";
for($i=0; $i < $l; $i++){
Script:
ARGS_COMMAND='find logs -type f ! -size 0 -exec grep -l "Broken pipe" {} \;'
parallel -j $MAXJOBS -i bash -c $EXEC_COMMAND -- $($ARGS_COMMAND)
Bash -x output:
++ find logs -type f '!' -size 0 -exec grep -l '"Broken' 'pipe"' '{}' '\;'
find: missing argument to `-exec'
// a complex iterator
function gen() {
$pagesize = 50;
while( $items = $someapi->paginated_operation($pagesize) ) {
foreach( $items as $item ) {
yield $item;
}
}
}
@wrossmann
wrossmann / bork.rb
Created March 7, 2016 21:23
Ruby::Mysql2::bork
require 'mysql2'
my = Mysql2::Client.new(:host => 'localhost', :username => 'root', :database=>'test')
stmt = my.prepare('INSERT INTO user (salt, password) VALUES(?,?);')
salt = "1a7v95zj1xa1l26g80meeaplc7294dp"
hashed = "4542511a19a5b18fd6801653ddc97b6e6ef3e855f4736720d791c4f4eed78957c0b5906921725a3ad0d8e98cf6722243f64e552382a37eb839f204d4fe6770ae"
stmt.execute(salt, hash)
# woops, that should be 'hashed', not 'hash'.
<?php
$cur = $seconds;
for( $i = count( $this->multipliers ) - 1; $i >= 0; $i -- ) {
$ps = $this->periodSize( $i );
$parts[] = (int) floor( $cur / $ps );
$cur -= $cur - ($cur % $ps);
}
var_dump($parts);
In Metrics:
host-*.CPUload.{load1,load5,load15}
Function:
averageSeriesWithWildcards($in, 1)
Out Metrics, Expected:
host-*.CPUload.load1,
host-*.CPUload.load5,
host-*.CPUload.load15
[exactly 3 series]
Out Metrics, Actual:
@wrossmann
wrossmann / outline.md
Created September 6, 2018 22:22
Whisper Aggregation Backfill

whisper-aggregation-backfill

Assumptions:

  • All metrics and aggregations have matching retentions
  • A proper metric aggregator is already running
  • The resulting metric file will then be used in a whisper-fill operation against the aggregator's actual metric files.

Procedure

@wrossmann
wrossmann / git_bash_prompt.sh
Created November 1, 2018 18:12
Simple and full-featured bash prompt with git info
# I've seen a _lot_ of code written to make bash prompts that are just _OK_,
# but there's no reason to invoke python/ruby/etc and parse git output since
# git ships with a pretty outstanding utility.
# 1. Load the library that already ships with git
source /usr/share/doc/${git_doc_path_here}/contrib/completion/git-prompt.sh
# 2. Set your options
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1