Skip to content

Instantly share code, notes, and snippets.

View dwburke's full-sized avatar

Dan Burke dwburke

  • New Relic
  • Michigan
  • 11:21 (UTC -05:00)
View GitHub Profile

Keybase proof

I hereby claim:

  • I am dwburke on github.
  • I am dwburke (https://keybase.io/dwburke) on keybase.
  • I have a public key whose fingerprint is 0106 655F A8B4 CAC0 41F8 F116 C79E A36B 43A4 49E0

To claim this, I am signing this object:

@dwburke
dwburke / ._ssh_add
Last active February 2, 2017 19:15
ssh-agent on login
# from http://mah.everybody.org/docs/ssh
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
@dwburke
dwburke / 1_create_queues.pl
Last active February 28, 2017 18:49
RMQ Headers Test
#!/usr/bin/env perl
use strict;
use warnings;
use JSON;
STDOUT->autoflush;
use Net::AMQP::RabbitMQ;
@dwburke
dwburke / install_rethinkdb_rpi.sh
Last active February 5, 2017 02:25
compile rethinkdb on raspberry pi
#!/bin/bash
# todo - modify swap
sudo apt-get install g++ protobuf-compiler libprotobuf-dev \
libboost-dev curl m4 wget libssl-dev
wget https://download.rethinkdb.com/dist/rethinkdb-2.3.5.tgz
tar xf rethinkdb-2.3.5.tgz
@dwburke
dwburke / simple_fork_queue.pl
Created February 6, 2017 20:13
Simple fork job queue with AnyEvent fork_call
#!/usr/bin/env perl
use strict;
use AnyEvent;
use AnyEvent::Util;
my $cv = AnyEvent->condvar;
$AnyEvent::Util::MAX_FORKS = 5;
@dwburke
dwburke / replace_all.cpp
Last active February 26, 2017 18:23
c++ string pattern replacement
// from http://stackoverflow.com/questions/2896600/how-to-replace-all-occurrences-of-a-character-in-string
// std::string tmp = ReplaceAll(description, std::string("%"), name);
std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
}
@dwburke
dwburke / c++.delete.from.list.cpp
Last active August 2, 2017 18:51
Delete while iterating std::list
for (auto i = list.begin(); i != list.end();) {
if (condition)
i = list.erase(i);
else
++i;
}
or
@dwburke
dwburke / create_kube_sa.sh
Created August 3, 2017 18:34
Create kubernetes service account
#!/bin/bash
set -eu
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "Usage: $0 <username>"
@dwburke
dwburke / Factory.h
Last active July 9, 2024 15:40
c++ factory
#pragma once
template <typename T, typename KEYT, typename... Args>
class Factory
{
public:
template <typename TDerived>
void registerType(KEYT key)
{
static_assert(std::is_base_of<T, TDerived>::value, "Factory::registerType doesn't accept this type because doesn't derive from base class");
@dwburke
dwburke / Pipe.h
Last active February 17, 2018 13:52
Pipe :: Class for running a system command and capturing output, automatically closing when it goes out of scope
class Pipe {
public:
Pipe() {};
Pipe(char *command, char *mode) {
open(command, mode);
};
~Pipe() {
if (pfp)
pclose(pfp);