Skip to content

Instantly share code, notes, and snippets.

View tsuna's full-sized avatar

Benoit Sigoure tsuna

View GitHub Profile
@tsuna
tsuna / ScannerTest.java
Last active December 16, 2015 18:49 — forked from AlexYangYu/gist:5476160
Recursive asynchronous HBase scanning
package me.alexyang.scanner;
import java.nio.charset.Charset;
import java.util.ArrayList;
import org.jboss.netty.util.CharsetUtil;
import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;
import org.hbase.async.HBaseClient;
@tsuna
tsuna / mapredrpc.py
Created April 23, 2013 07:55
Simple example of how to send a Hadoop RPC to the JobTracker from pure-Python code
#!/usr/bin/python
import socket
import struct
from protobuf import IpcConnectionContext_pb2 as IpcConnectionContext
from protobuf import RpcPayloadHeader_pb2 as RpcPayloadHeader
# --- Connection header ---
# Client.writeConnectionHeader()
preamble = (
@tsuna
tsuna / load.py
Created November 19, 2012 21:02
Trivial script to load random data in OpenTSDB as quickly as possible.
#!/usr/bin/python
import os
import socket
import sys
import time
ITERATIONS = 4000
TAGS = 50
@tsuna
tsuna / mysqlpool.scala
Created March 30, 2012 00:15
MySQL JDBC connection pool for Scala + Finagle
// Copyright (C) 2012 Benoit Sigoure
// Copyright (C) 2012 StumbleUpon, Inc.
// This library is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,
@tsuna
tsuna / HBase.scala
Created March 7, 2012 16:59
Atomic increment coalescing for asynchbase
// Copyright (C) 2012 Benoit Sigoure
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser 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 WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,
// see <http://www.gnu.org/licenses/>.
@tsuna
tsuna / avgkvsz.scala
Created February 29, 2012 07:45
Get average size of a KeyValue from HBase using asynchbase in Scala with the Finagle compatibility layer
import java.util.ArrayList
import scala.collection.JavaConversions._
import com.stumbleupon.async.{Callback, Deferred}
import org.hbase.async.{HBaseClient, KeyValue, Scanner}
import com.twitter.util.{Future, Promise, Return, Throw}
/** Converts a Deferred into a Future. */
implicit def futureFromDeferred[A](d: Deferred[A]): Future[A] = {
val promise = new Promise[A]
@tsuna
tsuna / gist:1865324
Created February 19, 2012 19:33
Output of brew install -v tcptraceroute
==> Downloading http://michael.toren.net/code/tcptraceroute/tcptraceroute-1.5beta7.tar.gz
File already downloaded in /Users/tsuna/Library/Caches/Homebrew
/usr/bin/tar xf /Users/tsuna/Library/Caches/Homebrew/tcptraceroute-1.5beta7.tar.gz
==> ./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/tcptraceroute/1.5beta7 --with-libnet=/usr/local --mandir=/usr/local/Cellar/tcptraceroute/1.5beta7/share/man
./configure --disable-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/tcptraceroute/1.5beta7 --with-libnet=/usr/local --mandir=/usr/local/Cellar/tcptraceroute/1.5beta7/share/man
checking build system type... i686-apple-darwin11.3.0
checking host system type... i686-apple-darwin11.3.0
checking target system type... i686-apple-darwin11.3.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
@tsuna
tsuna / setbench.java
Created February 9, 2012 18:56
Java integer hash set micro-benchmark
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import com.stumbleupon.mr.HashIntSet; // OpenJDK's HashSet hacked to use built-in `int'
import gnu.trove.set.hash.TIntHashSet;
import com.google.caliper.Param;
import com.google.caliper.SimpleBenchmark;
final class setbench {
@tsuna
tsuna / devirt.java
Created February 6, 2012 07:44
Java micro-benchmark on virtual method calls.
import com.google.caliper.SimpleBenchmark;
interface iface {
int foo();
}
class base implements iface {
public int foo() {
return (int) System.nanoTime();
}
@tsuna
tsuna / server.py
Created January 5, 2012 01:44
A simple example of a threaded TCP server in Python.
#!/usr/bin/python
# A simple example of a threaded TCP server in Python.
#
# Copyright (c) 2012 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,