Skip to content

Instantly share code, notes, and snippets.

View jerrypnz's full-sized avatar

Jerry Peng jerrypnz

  • Auckland, New Zealand
View GitHub Profile
@jerrypnz
jerrypnz / traverse.rs
Created August 1, 2019 10:07
Future traverse in rust
use futures::future::{lazy, try_join_all, Future, RemoteHandle};
use futures::task::SpawnExt;
pub trait SpawnFuture {
fn spawn_future<T, E, F>(&mut self, f: F) -> RemoteHandle<Result<T, E>>
where
T: Send + 'static,
E: Send + 'static,
F: FnOnce() -> Result<T, E> + Send + 'static;
}
@jerrypnz
jerrypnz / Test.hs
Last active November 13, 2015 08:39
FP101x Practice: JSON Parser
Main> parse json "\"hello world!\n\""
[(JsString "hello world!\n","")]
Main> parse json "true"
[(JsBoolean True,"")]
Main> parse json "false"
[(JsBoolean False,"")]
@jerrypnz
jerrypnz / evalMonadWithRead.hs
Last active August 29, 2015 14:20
Expr Evaluator with Read
--- Using a monad to implement the evaluation example but this time using "do"
import Control.Applicative
import Control.Monad
data Expr = C Float |
Expr :+ Expr|
V String |
Let String Expr Expr |
Read
@jerrypnz
jerrypnz / LICENSE
Last active August 29, 2015 14:03
Ganglia Multidisk Extension Module
#/*******************************************************************************
#* Portions Copyright (C) 2007 Novell, Inc. All rights reserved.
#*
#* Redistribution and use in source and binary forms, with or without
#* modification, are permitted provided that the following conditions are met:
#*
#* - Redistributions of source code must retain the above copyright notice,
#* this list of conditions and the following disclaimer.
#*
#* - Redistributions in binary form must reproduce the above copyright notice,
@jerrypnz
jerrypnz / ab -n 1000 -c 100
Created July 15, 2013 15:42
breeze test_http_server ab测试结果,单线程,服务器返回一段127 bytes的HTML。好慢啊,摔!
[~]$ /usr/sbin/ab -n 1000 -c 100 http://127.0.0.1:8000/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Server Software: breeze/0.1.0
Server Hostname: 127.0.0.1
Server Port: 8000
Document Path: /
@jerrypnz
jerrypnz / poll.rkt
Last active November 20, 2018 22:10
Play with Racket stateful servlet. This demo is a polling program.
#lang racket
(require web-server/http
web-server/managers/none
web-server/servlet
web-server/servlet-env)
(provide interface-version manager star-polling-app)
(define interface-version 'v2)
@jerrypnz
jerrypnz / test_watchers.clj
Created November 6, 2012 09:33
Clojure wrapper for Java 7 WatchService (java.nio.files)
(load-file "./watch_service.clj")
(refer 'watch-service)
(defn print-ev
[ev ctx]
(println "[foo]" ev " --> " ctx)
(println "Parent Dir:" (.getParent ctx)))
(defn print-ev-2
[ev ctx]
@jerrypnz
jerrypnz / jstack.txt
Created October 26, 2012 09:18
JVM stuck in DestroyJavaVM thread
2012-10-26 17:12:28
Full thread dump Java HotSpot(TM) 64-Bit Server VM (20.8-b03 mixed mode):
"Attach Listener" daemon prio=10 tid=0x00007fa790001000 nid=0x428e waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
================================= Suspicious DestroyJavaVM thread ================================
"DestroyJavaVM" prio=10 tid=0x00007fa7b8007800 nid=0x425c waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
=================================================================================================
public class PrintAB {
// The code below would print overlapped A and B sequences like:
// ...
// A
// A
// B
// B
// ...
//