Skip to content

Instantly share code, notes, and snippets.

View pierre's full-sized avatar

Pierre-Alexandre Meyer pierre

View GitHub Profile
@pierre
pierre / ScribeSender.java.patch
Created December 6, 2010 22:35
Handle gracefully idle connections with Scribe in the eventtracker library
diff --git a/src/main/java/com/ning/metrics/eventtracker/ScribeSender.java b/src/main/java/com/ning/metrics/eventtracker/ScribeSender.java
index e8ffdda..f9b707b 100644
--- a/src/main/java/com/ning/metrics/eventtracker/ScribeSender.java
+++ b/src/main/java/com/ning/metrics/eventtracker/ScribeSender.java
@@ -24,42 +24,65 @@ import org.apache.commons.logging.LogFactory;
import org.apache.thrift.transport.TTransportException;
import scribe.thrift.LogEntry;
import scribe.thrift.ResultCode;
import java.io.ByteArrayOutputStream;
/*
* Copyright 2010 Ning, Inc.
*
* Ning licenses this file to you under the Apache License, version 2.0
* (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@pierre
pierre / smile vs json
Created February 10, 2011 21:06
auto detection rullez
/*
* Copyright 2011 Ning, Inc.
*
* Ning licenses this file to you under the Apache License, version 2.0
* (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
public class SubscriberConfig {
@JsonValue
public String name;
@JsonValue
public String type;
@JsonMagicThisIsHowYouShouldResolveMyType
public Class getClassForJsonNode(HashMap<Object, Object> rawJson) {
return Class.forName(((String) rawJson).get("type") + "Config");
#!/usr/bin/env ruby
if ARGV[0] == "-k"
orig_lines=`/bin/df #{ARGV.join(" ")}`.split("\n")
puts orig_lines[0]
orig_lines[1..-1].each do |line|
numbers_line = line.split()
numbers_line[1] = numbers_line[2].to_i + numbers_line[3].to_i
puts numbers_line.join(" ")
end
else
package com.ning.metrics.eventtracker;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.IOException;
@pierre
pierre / gist:1095375
Created July 20, 2011 17:09
Ruby Smile extension
ruby-1.8.7-p334 :001 > require 'smile'
=> true
ruby-1.8.7-p334 :002 > p = Smile::Parser.new("data.smile")
=> #<Smile::Parser:0x100362210>
ruby-1.8.7-p334 :003 > puts p.check_header
true
=> nil
ruby-1.8.7-p334 :008 > p = Smile::Parser.new("dummy.txt")
=> #<Smile::Parser:0x1003324e8>
ruby-1.8.7-p334 :009 > puts p.check_header
// Look for JVM bug
if (selected==0 && wait>0 && (now-before)<wait/2 && _selector.selectedKeys().size()==0)
{
if (_jvmBug++>5) // TODO tune or configure this
{
// Probably JVM BUG!
Iterator iter = _selector.keys().iterator();
while(iter.hasNext())
{
@pierre
pierre / gist:1207473
Created September 9, 2011 22:14
dot stuff
Simple:
digraph G {
rankdir = BT
node [shape = "box"]
HDFS -> Event -> Schema
}
More complex:
@pierre
pierre / gist:1237974
Created September 23, 2011 17:40
streaming
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/json")
@Timed
public StreamingOutput listingToJson(
@QueryParam("path") final String path,
@QueryParam("recursive") final boolean recursive,
@QueryParam("pretty") final boolean pretty,
@QueryParam("raw") final boolean raw
) throws IOException