Skip to content

Instantly share code, notes, and snippets.

@dermoth
dermoth / gist:1948436
Created March 1, 2012 08:56
test for m2php
<?php
// Never played with php includes before but that seems to work!
include '../Mongrel2/Connection.php';
include '../Mongrel2/Request.php';
include '../Mongrel2/Tool.php';
use Mongrel2\Request;
$fh=fopen('request_payloads.txt', 'r');
while (true) {
@dermoth
dermoth / range-2i_try2
Created June 6, 2012 17:53
mapred test
{
"inputs":{
"bucket":"webaccesslogs",
"index":"ts_int",
"start":1338712811,
"end":1338712814,
"timeout":60000
},
"query":[
{
@dermoth
dermoth / list_domains.sh
Last active December 16, 2015 04:19
CGI script in plain Bash...
#!/bin/bash
# Send all command output to STDERR while allowing us to write to STDOUT
# using fd 3
exec 3>&1 1>&2
set -eu
trap "echo -e 'Status: 500 Internal Server Error\n' >&3; exit 0" ERR
@dermoth
dermoth / check_things.php
Created April 13, 2013 05:18
Template php nagios check
<?php
# Template php nagios check
#
# Meant to work along with nagios's check_http. In addition to the
# returned string which is a standard nagios result, the script returns
# 403 and 503 errors on WARNING and CRITICAL respectively to make
# check_http return an equivalent status. The HTTP status printed by
# check_http is also the script result.
#
# Author: Thomas Guyot-Sionnest <tguyot@gmail.com>
@dermoth
dermoth / gist:9337183
Last active August 29, 2015 13:56
Bash (()) and error handling
[thomas_guyot@localhost ~]$ bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
[thomas_guyot@localhost ~]$ trap 'echo Argh' ERR
[thomas_guyot@localhost ~]$ variable=0
[thomas_guyot@localhost ~]$ ((variable++))
[thomas_guyot@localhost ~]$ echo $?
1
[thomas_guyot@localhost ~]$ echo $variable
1
@dermoth
dermoth / csv2tsv.py
Created February 26, 2015 11:24
Convert CSV to TSV, properly handling intra-field commas, newlines and quoted double-quotes, as per rfc4180 section 2. Also convert TSV separators to C-style escapes.
#!/usr/bin/env python
#
# Convert CSV to TSV, properly handling intra-field commas, newlines and
# quoted double-quotes, as per rfc4180 section 2. Also convert TSV separators
# to C-style escapes.
#
from __future__ import print_function
import sys, csv
@dermoth
dermoth / bench.py
Created March 20, 2015 05:26
arista-eosext/PCAPDecoder decode benchmark
#!/usr/bin/env python
import timeit
import locale
locale.setlocale(locale.LC_ALL, '') # Default user locale
#locale.setlocale(locale.LC_ALL, 'en_US') # ... or force it with this
runcnt=10000000
result = timeit.timeit(
@dermoth
dermoth / t.py
Last active August 8, 2017 04:23
# Copyright(C) 2017 by Abe developers.
# test_chain.py: test Abe Chain code with static data
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
@dermoth
dermoth / blk_ra.sh
Created August 15, 2017 04:49
Script performing read-ahead on bitcoin's blockfiles
#!/bin/bash
#
# blk_ra.sh - Script performing read-ahead on bitcoin's blockfiles
#
# In order to speed up data loading, this script performs read-ahead
# operations on the next block to be read by the bitcoin node.
#
# The expected setup for this speed-up to be effective is:
#
# - Blockchain index and chainstate database on SSD
@dermoth
dermoth / xchat_auto_ghost.py
Created August 15, 2017 18:25
AutoGhost X-Chat2 Module
"""AutoGhost X-Chat2 Module
NB: This module assumes SASL Authentication. It does not perform any auth;
merely ghost on connect *after* successful SASL authentication (and likely
before any other module can perform manual service auth).
"""
import xchat # pylint: disable=F0401
__module_name__ = "AutoGhost"