Skip to content

Instantly share code, notes, and snippets.

View tsuna's full-sized avatar

Benoit Sigoure tsuna

View GitHub Profile
public static void main(String[] args) throws Exception {
Socket echoSocket = null;
PrintWriter out = null;
String host = null;
int port = 0;
while (true) {
try {
@tsuna
tsuna / count_hbase.sh
Created November 17, 2011 18:42
Script to get stats on the number of KeyValue and size of an HBase table, directly from HFiles
#!/bin/bash
# Copyright (c) 2010, 2011 Benoit Sigoure. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
@tsuna
tsuna / mysql.scala
Created November 7, 2011 10:57
Twitter Querulous leaking connections?
/*
This is for https://github.com/nkallen/querulous/issues/24
I must be doing something wrong but I can't see what. In my loadtests it's pretty apparent
that new MySQL connections are always created all the time and are never re-used, so my app
then runs out of FD.
*/
package whatever
import java.sql.ResultSet
@tsuna
tsuna / ztc.py
Created September 30, 2011 21:22
Template for a simple HTTP server for Zero Touch Provisioning with Arista switches
#!/usr/bin/python
# Copyright (c) 2011 StumbleUpon, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
@tsuna
tsuna / re2-bitstate.s
Created September 24, 2011 08:23
RE2's BitState::ShouldVisit disassembled manually
/*./re2/prog.h:100*/ 0x0000000000411f0b <+523>: mov 0x50(%rbx),%rdi # rdi = visited_
/*./re2/prog.h:100*/ 0x0000000000411f0f <+527>: add $0x1,%edx # edx = text_.size() + 1
/*re2/bitstate.cc:97*/ 0x0000000000411f12 <+530>: imul %esi,%edx # esi = id, edx = id * (text_.size() + 1)
/*re2/bitstate.cc:97*/ 0x0000000000411f15 <+533>: add %r14d,%edx # r14d = p, edx = id * (text_.size() + 1) + p
/*re2/bitstate.cc:97*/ 0x0000000000411f18 <+536>: sub %eax,%edx # eax = text_.begin(), edx = n
/*re2/bitstate.cc:98*/ 0x0000000000411f1a <+538>: mov %edx,%eax # eax = n
/*re2/bitstate.cc:98*/ 0x0000000000411f1c <+540>: mov %edx,%ecx # ecx = n
/*re2/bitstate.cc:98*/ 0x0000000000411f1e <+542>: shr $0x5,%eax # eax = n >> 5 = n / VisitedBits
/*re2/bitstate.cc:98*/ 0x0000000000411f21 <+545>: and $0x1f,%ecx # ecx = n & (VisitedBits - 1)
/*re2/bitstate.cc:98*/ 0x0000000000411f24 <+548>: mov
@tsuna
tsuna / nagiosirc.pl
Created August 10, 2011 22:38
Handy little bot to get Nagios notifications on IRC
#!/usr/bin/perl -w
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
@tsuna
tsuna / memcachemon.py
Created August 10, 2011 06:43
Memcache collector for tcollector
#!/usr/bin/env python
import socket
import subprocess
import sys
import time
COLLECTION_INTERVAL = 15 # seconds
@tsuna
tsuna / gist:1119725
Created August 2, 2011 07:07
TSDB query start time underflow
diff --git a/src/core/TsdbQuery.java b/src/core/TsdbQuery.java
index 2edd53c..8776e89 100644
--- a/src/core/TsdbQuery.java
+++ b/src/core/TsdbQuery.java
@@ -401,7 +401,8 @@ final class TsdbQuery implements Query {
// but this doesn't really matter.
// Additionally, in case our sample_interval is large, we need to look
// even further before/after, so use that too.
- return getStartTime() - Const.MAX_TIMESPAN * 2 - sample_interval;
+ final long t = getStartTime() - Const.MAX_TIMESPAN * 2 - sample_interval;
@tsuna
tsuna / tsdq.py
Created February 27, 2011 09:29
Quick script to run a couple queries against a TSD and time it
#!/usr/bin/python
import httplib
import json
import os
import shutil
import time
def purge_tsd_cache():
for dir in (dir for dir in os.listdir("/tmp/tsd") if dir[0] != "."):
@tsuna
tsuna / 0001-Add-support-for-HBase-0.90.patch
Created January 28, 2011 01:36
Add support for HBase 0.90 in asynchbase.
From 7a538914c93f8a92b9c80e5c533e73d97e8423c8 Mon Sep 17 00:00:00 2001
From: Benoit Sigoure <[email protected]>
Date: Thu, 27 Jan 2011 17:33:37 -0800
Subject: [PATCH] Add support for HBase 0.90.
In order to enable the new code, the JVM must be given the following
system property in argument:
-Dorg.hbase.async.v0.90
For HBASE-3174, revision r1029115 (or 08e64aae in Git) changed the