Skip to content

Instantly share code, notes, and snippets.

package net.reznik.gist;
import static io.netty.buffer.Unpooled.copiedBuffer;
import static io.netty.handler.codec.http.HttpHeaders.isKeepAlive;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
@dawnbreaks
dawnbreaks / MyList.scala
Last active August 29, 2015 14:21
create your own list collection, just for fun
package com.lubin.study;
import scala.annotation.tailrec
sealed trait MyList[+A]
abstract class MyListOpt[+A](myList: MyList[A]) {
def head(): A
def tail(): MyList[A]
def setHead[B >: A](head: B): MyList[B]
@dawnbreaks
dawnbreaks / OrderingAndOreredTest.scala
Last active August 29, 2015 14:20
scala ordering /ordered/ implicitly conversion / view bounds / context bound example
package com.lubin.study
import scala.Ordered.orderingToOrdered
object OrderingAndOrderedTest extends App {
class Fraction(n: Int, d: Int) {
def value: Double = n.asInstanceOf[Double] / d.asInstanceOf[Double]
override def toString(): String = n + "/" + d
}
@dawnbreaks
dawnbreaks / TestAsyncHttpClient.java
Created April 1, 2015 09:31
Test for AsyncHttpClient
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import com.ning.http.client.AsyncCompletionHandler;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.Response;
import com.ning.http.client.providers.netty.NettyAsyncHttpProviderConfig;

#Create bitbucket branch

##Create local branch

$ git checkout -b sync
Switched to a new branch 'sync'
$ git branch
  master
* sync
package com.crm.test;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.linkedin.parseq.BaseTask;
import com.linkedin.parseq.Context;
public class BigLockCalculator extends CalculatorBase {
private interface Status {
int NotStarted =1;
int Starting =2;
int Started =3;
int Disposed =4;
}
private AtomicInteger _status = new AtomicInteger(Status.NotStarted);
///////////////////////////////////////////////////////
// Talk is cheap. Show me the code. - Linus Torvalds
///////////////////////////////////////////////////////
public abstract class CalculatorBase : IDisposable {
protected void StartCore() {
// ...
}
/*
** Copyright (c) 2012, Alex Fok alexfokil@gmail.com
** All rights reserved.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the Lesser GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
public static byte[] serialize(Object o) throws IOException
{
// Kryo kryo = new Kryo();
// kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
// Output output = new Output(4096, -1);
// kryo.writeClassAndObject(output,o);
// output.close();
// return output.toBytes();
ByteArrayOutputStream ostream = new ByteArrayOutputStream();