Skip to content

Instantly share code, notes, and snippets.

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

Wade Rossmann wrossmann

👺
¯\_(ツ)_/¯
  • Victoria, BC
View GitHub Profile
@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++){
// a complex iterator
function gen() {
$pagesize = 50;
while( $items = $someapi->paginated_operation($pagesize) ) {
foreach( $items as $item ) {
yield $item;
}
}
}
<?php
$dom = new DOMDocument();
// cache of the wikipedia page
$dom->loadHTML(file_get_contents('abe.vigoda_cache.html'));
foreach($dom->getElementById('persondata')->getElementsByTagName("tr") as $row) {
foreach($row->childNodes as $node) {
if( $node->hasAttribute('class') ) {
var_dump($dom->saveXML($node));
}
<?php
require('creds.php');
if( isset($creds[$_POST['user']]) && ($creds[$_POST['user']] == md5($_POST['pass'])) ) {
echo "Authenticated";
} else {
echo <<<_eoi_
<form action="" method="POST">
<input name="user" type="text" />
<input name="pass" type="password" />
@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

The Problem

Your postgres server is out of space to the point that VACUUM FULL hits a table too large to write back out to disk even though other tables may still have space to give up.

The Solution

Start with the tables that have the least amount of "un-wasted" space as they will require the minimal amount of free space to process, and hopefully the cumulative effect of releasing all of the space from the smaller tables allows you to process your larger tables as you go. If not, then there's no solution available to you short of deleting data or expading your disk.

The Kludge