Skip to content

Instantly share code, notes, and snippets.

View bracki's full-sized avatar

Jan Brauer bracki

View GitHub Profile
@bracki
bracki / reindex.py
Created January 30, 2012 21:34
Simple reindex for elasticsearch using pyes
>>> import pyes
>>> conn = pyes.es.ES("localhost:9200")
>>> all = conn.scan(pyes.query.MatchAllQuery(), 'index', 'type')
>>> for a in all:
... hits = a['hits']['hits']
... for hit in hits:
... conn.index(hit['_source'], 'new_index', 'type', hit['_id'], bulk=True)
@bracki
bracki / bootstrap.sh
Created March 30, 2012 08:05
Simple bootstrap of virtualenv for Jenkins
#!/bin/bash
VENV="$WORKSPACE/.env"
if [ ! -e "virtualenv.py" ]; then
curl -O https://raw.github.com/pypa/virtualenv/master/virtualenv.py
fi
if [ -d $VENV ]; then
echo "**> virtualenv exists"
else
echo "**> creating virtualenv"
python virtualenv.py $VENV
@bracki
bracki / gist:2887329
Created June 7, 2012 08:06
Multi screen setups with disper - suitable for pair programming, conference talks, what not, needs NVIDIA graphic card
# Need to install disper, only works on NVIDIA
alias clone-screen='disper -c'
alias dual-screen='disper -e -t right -d DFP-1,DFP-0'
alias pair-screen='disper -c -d DFP-1,CRT-0'
alias single-screen='disper -s'
@bracki
bracki / fabfile.py
Created July 12, 2012 21:07
Run a task once, on the localhost only.
env.roledefs = {
'hosts' : ['foo', 'bar'],
'local' : []
}
@task
@roles('hosts')
def export_dummies():
run("rm -rf /tmp/exports")
@bracki
bracki / client.rb
Created November 29, 2012 17:32
Simple client
require 'socket'
@functions = {
:ADD => lambda {|a, b| a + b},
:SUBTRACT => lambda {|a, b| a - b},
:MULTIPLY => lambda {|a, b| a * b}
}
def build_response(msg)
m = msg.split(':')
@bracki
bracki / rvm2rbenv.txt
Created December 3, 2012 20:51 — forked from brentertz/rvm2rbenv.txt
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@bracki
bracki / ThriftOverHttp.scala
Last active September 6, 2017 10:04
Thrift HTTP transport implemented as a Filter for Twitter's Finagle.
class ThriftOverHttp extends Filter[ThriftClientRequest, Array[Byte], HttpRequest, HttpResponse] {
def apply(request: ThriftClientRequest, service: Service[HttpRequest, HttpResponse]) = {
val httpRequest = convertThriftRequestToHttpRequest(request)
val response = service(httpRequest)
response flatMap { res =>
Future.value(res.getContent().array())
}
}
private def convertThriftRequestToHttpRequest(request: ThriftClientRequest) = {
@bracki
bracki / TimedJsonWebSignatureSerializer.py
Last active May 1, 2018 22:21
A TimedJsonWebSignatureSerializer that checks for http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#expDef. A bit like the TimedSerializer, but with self contained expiry time.
from itsdangerous import JSONWebSignatureSerializer, BadSignature, SignatureExpired
import calendar
import datetime
class TimedJSONWebSignatureSerializer(JSONWebSignatureSerializer):
EXPIRES_IN_AN_HOUR = 3600
def __init__(self, secret_key, salt=None, serializer=None, signer=None, signer_kwargs=None, algorithm_name=None, expires_in=None):
(ns riemann.test.nagios
(:use riemann.nagios
clj-nsca.core
clojure.test)
(:require [riemann.logging :as logging]))
(logging/init)
(def test-event
{:host "host01" :service "test_service" :state "ok" :description "Quick brown fox"})