Skip to content

Instantly share code, notes, and snippets.

View rrichardson's full-sized avatar
💭
⚔️ Hacking Away

Rick Richardson rrichardson

💭
⚔️ Hacking Away
View GitHub Profile
type Cloneable interface {
Clone() Cloneable;
}
type MapA map[int]string;
type MapB map[string]int;
func (m MapA) Clone() Clonable {
nmap := make(MapA);
package main
import "fmt"
import "reflect"
type Cloneable interface {
Clone() Cloneable;
}
type Mapable interface {
package main
import "fmt"
import "reflect"
type Cloneable interface {
Clone() Cloneable;
}
type MapA map[int]string;
case ServerRequest(key) =>
reply(sessionMap.get(key) match {
case Some(svr) =>
SessionSuccess(svr)
case None =>
SessionFailure("No session found for supplied key")
})
trait NeoIterable[T] extends Iterator[T] {
def first() : T = {
this.take(1).toList.head
}
}
implicit def jiterable2iterable[T](it: java.lang.Iterable[T]) = new Wrapper[T](it.iterator()) with NeoIterable[T]
use:
type bsonvalue =
| BDouble of float
| BString of string
| BObject of bsondoc
| BArray of list bsonvalue
| BBinary of int * string
| BUndefined
| BOid of string
| BBool of bool
| BDate of int64
getNextMsgID :: Peer -> IO Int64
getNextMsgID peer = modifyMvar (pCurrent peer) (\x -> do { let y = x + 1; return (y, y); } )
forMpar :: [a] -> (a -> IO b) -> IO [b]
forMpar xs fun = do
sem <- newQSem (length xs)
c <- newChan
forM_ xs (\x -> forkIO $ wrap fun x c sem)
waitQSem sem
collect (length xs) c []
where wrap f item chan qsem = f item >>= writeChan chan >> signalQSem qsem
collect 0 chan acc = return acc
collect count chan acc = do !i <- readChan chan; collect (count - 1) chan i::acc
syncRequests :: BsonDoc -> [Peer] -> IO [BsonDoc]
syncRequests doc prs = do
sem <- newQSem (length prs)
c <- newChan
forM_ prs $ \p -> do
(mid, msg) <- initMessage p MsgTypeCall 0 doc
registerSync p c sem mid
putMessage (pConn p) msg
waitQSem sem
collect (length prs) c []
<!DOCTYPE html>
<html class="no-js " lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script type="text/javascript">Olelo = {"path":"","page_name":"","page_new":true,"page_modified":false,"page_path":"","page_title":"Root","page_version":"","page_next_version":"","page_previous_version":"","page_mime":"text/x-creole","default_mime":"text/x-creole","user_logged_in":true,"user_name":"10.16.64.79"};</script><title>My Project - New Page</title><link href="/static/images/favicon.png?1" rel="shortcut icon" type="image/png"><base href="http://172.17.3.122:8080/"><link rel="stylesheet" href="/static/themes/atlantis/style.css?1289221523" type="text/css" title="atlantis"><script src="/static/script.js?1289221523" type="text/javascript" async="async"></script><link rel="stylesheet" href="/_/assets/assets.css?1289221523" type="text/css"><link rel="alternate" type="application/atom+xml" title="Sitewide Atom Changelog" href="/?format=atom&amp;output=changelog"><link rel="alternate" ty