Skip to content

Instantly share code, notes, and snippets.

View yelcat's full-sized avatar
🎯
Focusing

ycat yelcat

🎯
Focusing
View GitHub Profile
@yelcat
yelcat / BenchmarkUtils.java
Created July 26, 2012 08:25
benchmark test for HDFS hflush hsync call
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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
@yelcat
yelcat / web.py
Created August 1, 2012 14:21
A complete web.py application.
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, name):
if not name:
@yelcat
yelcat / models.py
Created August 14, 2012 14:41
channels.models.py
from django.db import models
from django.contrib.auth.models import User
class Category(models.Model):
parent = models.ForeignKey('self', null=True)
name = models.CharField(max_length=10)
def __unicode__(self):
return self.name
@yelcat
yelcat / PictureDTOAssembler.java
Created September 27, 2012 02:34
图片中心链接转换代码样例
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import static com.google.common.base.Preconditions.checkState;
/**
public class OrderRegionalTopology {
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("orderSource", new OrderEnabledMockSpout(), 5);
builder.setBolt("regional", new RegionalStatisticsBolt(), 20)
.fieldsGrouping("orderSource", new Fields("IP"));
Config conf = new Config();
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("regional", conf, builder.createTopology());
public class OrderEnabledMockSpout implements IRichSpout {
private final static String[] ipAddress = new String[]
{"10.13.43.154", "10.112.43.12", "10.13.45.123", "10.113.43.4"};
private SpoutOutputCollector collector;
@Override
public boolean isDistributed() {
return true;
}
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
outputFieldsDeclarer.declare(new Fields("IP", "BizOrderId"));
}
private final static String[] ipAddress = new String[]
{"10.13.43.154", "10.112.43.12", "10.13.45.123", "10.113.43.4"};
public void nextTuple() {
Utils.sleep(4000);
final Random rand = new Random();
collector.emit(new Values(ipAddress[rand.nextInt(ipAddress.length)], Math.abs(rand.nextLong())));
}
public class RegionalStatisticsBolt implements IBasicBolt {
private Map<String, AtomicLong> regionalCounterMapping = new HashMap<String, AtomicLong>();
@Override
public void prepare(Map map, TopologyContext topologyContext) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override