Skip to content

Instantly share code, notes, and snippets.

@kevinlynx
kevinlynx / netty-discardserver.scala
Last active December 25, 2015 10:29
scala netty Discard Server sample
package netty.sample
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import io.netty.buffer.ByteBuf
import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.ChannelOption
import io.netty.channel.ChannelOption._
import io.netty.channel.ChannelFuture
import io.netty.channel.ChannelInitializer
@kevinlynx
kevinlynx / netty-timeclient.scala
Created October 13, 2013 14:40
netty time server/client sample in scala
package netty.sample
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import io.netty.buffer.ByteBuf
import io.netty.bootstrap.Bootstrap
import io.netty.channel._
import io.netty.channel.nio._
import io.netty.channel.socket._
import io.netty.channel.socket.nio._
// e.g: copyDir("folder\\", "destFolder\\", false);
bool copyDir(const char *r_szSrcPath, const char *r_szDesPath, bool recur) {
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
char l_szTmp[MAX_PATH];
strcpy(l_szTmp, r_szSrcPath);
char l_szSrcPath[MAX_PATH];
char l_szDesPath[MAX_PATH];
strcpy(l_szSrcPath, r_szSrcPath);
@kevinlynx
kevinlynx / bt-metainfo.scala
Created October 20, 2013 13:41
request torrent meta info from peer based on netty and scala
/*
* http://www.bittorrent.org/beps/bep_0010.html
* http://www.bittorrent.org/beps/bep_0009.html
*/
package netty.sample
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import io.netty.buffer.ByteBuf
import io.netty.bootstrap.Bootstrap
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
class A
{
};
class B
@kevinlynx
kevinlynx / request-metainfo.scala
Created October 25, 2013 14:28
the second version to request torrent metainfo by protocol bep09/10
/*
* http://www.bittorrent.org/beps/bep_0010.html
* http://www.bittorrent.org/beps/bep_0009.html
*/
package bep.impl
import java.io._
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import io.netty.buffer._
#include <assert.h>
#include <vector>
#include <map>
class DecisionStmt {
public:
enum { DECISION_RET = (unsigned) -1 };
typedef std::map<unsigned, int> CondResult;
typedef std::vector<CondResult> AccResults;
typedef std::vector<unsigned> CondList;
int length(char *str) {
int s = 0;
for (; *str; ++str) ++s;
return s;
}
char *reverse(char *str) {
int size = length(str);
for (int i = 0; i < size / 2; ++i) {
str[i] ^= str[size - i - 1];
package lichecker
import scala.concurrent._
import scala.concurrent.duration.Duration
import ExecutionContext.Implicits.global
import com.codemacro.AsyncTask
object FutureList {
def run[T, T2](args: List[T], fn: => T => T2, max: Int): List[T2] = {
@kevinlynx
kevinlynx / actor.cpp
Last active August 29, 2015 14:01
actor model
class Printer : public Theron::Actor
{
public:
// Constructor, passes the framework to the baseclass.
Printer(Theron::Framework &framework) : Theron::Actor(framework)
{
// Register the message handler.
RegisterHandler(this, &Printer::Print);
}