Skip to content

Instantly share code, notes, and snippets.

@Arbow
Arbow / gist:257034
Created December 15, 2009 15:52
stackless python prime generator
# 相比sieve.go,内存占用少很多哦 - 对比 http://gist.github.com/257036
import stackless
def generate(channel):
i = 2
while True:
channel.send(i)
i = i+1
def filter_prime(in_chan, out_chan, prime):
@Arbow
Arbow / gist:257036
Created December 15, 2009 15:53
golang prime generator
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "fmt"
// Send the sequence 2, 3, 4, ... to channel 'ch'.
func generate(ch chan int) {
//From http://hg.openjdk.java.net/jdk7/jdk7/jdk/raw-file/bfd7abda8f79/src/share/classes/java/util/TimSort.java
/*
* Copyright 2009 Google Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
@Arbow
Arbow / CoroutineBenchmark.scala
Created January 28, 2010 16:52
Scala message send/receive benchmark
import scala.actors.{Actor}
import scala.actors.Actor._
import java.util.concurrent.CountDownLatch
object Main {
val PROCESSER_COUNT=Runtime.getRuntime().availableProcessors()
var perThreadRequests=10000
@Arbow
Arbow / KilimBenchmarkMain.java
Created January 30, 2010 06:24
Kilim Message send/receive Benchmark
package coroutine.kilim.benchmark;
import java.util.concurrent.CountDownLatch;
import kilim.Mailbox;
import kilim.Pausable;
import kilim.Task;
public class Main {
@Arbow
Arbow / coroutine-benchmark.py
Created January 30, 2010 07:43
Just like http://gist.github.com/290451, but stackless version
#!/usr/bin/env python
#coding=utf-8
import stackless
import sys
import time
per_thread_requests = 10000
def receive_task():
for i in xrange(0, per_thread_requests):
//Scala parallel version smallpt of http://www.cnblogs.com/miloyip/archive/2010/07/07/languages_brawl_GI.html
package parallel
class RandomLCG(var seed:Long) {
def nextDouble(): Double = {
seed = (214013L * seed + 2531011L) % 0x100000000L
seed * (1.0 / 4294967296.0)
}
}
@Arbow
Arbow / gist:977987
Created May 18, 2011 04:24
Java Generic
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<? extends Fruit> list = new ArrayList<Fruit>();
List<? super Apple> list1 = new ArrayList<Apple>();
@Arbow
Arbow / Thread.php
Created May 20, 2011 03:56
PHP Process Pool With Executor
<?php
//Found on http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html
//Modified by http://www.php-code.net
//Modified: add executor
class Thread {
var $pref ; // process reference
var $pipes; // stdio
var $buffer; // output buffer
var $output;
var $error;
@Arbow
Arbow / patch.diff
Created June 2, 2011 09:01
Netty 3.2.4 idle event trigger patch
diff -r a0c46f1a4e8b src/main/java/org/jboss/netty/channel/socket/DefaultSocketChannelConfig.java
--- a/src/main/java/org/jboss/netty/channel/socket/DefaultSocketChannelConfig.java Thu Jun 02 14:13:48 2011 +0800
+++ b/src/main/java/org/jboss/netty/channel/socket/DefaultSocketChannelConfig.java Thu Jun 02 16:55:06 2011 +0800
@@ -17,6 +17,7 @@
import java.net.Socket;
import java.net.SocketException;
+import java.util.concurrent.TimeUnit;
import org.jboss.netty.channel.ChannelException;