Skip to content

Instantly share code, notes, and snippets.

#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;
@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 <iostream>
#include <vector>
#include <string>
#include <algorithm>
class A
{
};
class B
@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
// 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 / 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._
@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
package squtest
import org.squeryl.PrimitiveTypeMode._
import org.squeryl.Schema
import org.squeryl.annotations.Column
import org.squeryl.SessionFactory
import org.squeryl.Session
import org.squeryl.KeyedEntity
import org.squeryl.adapters.H2Adapter
import java.util.Date
@kevinlynx
kevinlynx / scala-jna.scala
Created October 10, 2013 13:10
JNA used in scala
package test
import com.sun.jna._
import com.sun.jna.ptr._
trait Kernel32 extends Library {
def GetDiskFreeSpaceA(lpRootPathName: String,
lpSectorsPerCluster: IntByReference, lpBytesPerSector: IntByReference,
lpNumberOfFreeClusters: IntByReference, lpTotalNumberOfClusters: IntByReference): Boolean
def GetComputerNameW(outName: Array[Char], size: IntByReference): Boolean
@kevinlynx
kevinlynx / function-literal.scala
Last active December 24, 2015 21:39
function literal in scala
object Test2 {
//Also: def callFn(a: Int, f: (Int) => Int) = {
def callFn(a: Int, f: Int => Int) = {
a + f(a)
}
// 2 parameters
def callFnMult(a: Int, f: (Int, Int) => Int) = {
a + f(a, a)