Skip to content

Instantly share code, notes, and snippets.

package org.waveprotocol.wave.model.export;
import org.waveprotocol.wave.model.conversation.Conversation;
import org.waveprotocol.wave.model.conversation.ConversationBlip;
import org.waveprotocol.wave.model.conversation.ConversationView;
import org.waveprotocol.wave.model.conversation.TitleHelper;
import org.waveprotocol.wave.model.conversation.WaveBasedConversationView;
import org.waveprotocol.wave.model.conversation.WaveletBasedConversation;
import org.waveprotocol.wave.model.document.util.LineContainers;
import org.waveprotocol.wave.model.document.util.XmlStringBuilder;
@josephg
josephg / gist:952760
Created May 3, 2011 03:11
Benchmarks of various JS reverse loop implementations
var arr = []
for (var i = 0; i < 100000; i++) {
arr.push(i+1);
}
// This is what the coffeescript compiler produces for 'sum += arr[x] for x in [arr.nexts.length - 1..0]'
var coffee = function() {
var x, _ref, sum = 0;
for (x = _ref = arr.length - 1; _ref <= 0 ? x <= 0 : x >= 0; _ref <= 0 ? x++ : x--) {
@josephg
josephg / gist:972894
Created May 15, 2011 04:49
Sarah's ot code
<!DOCTYPE HTML>
<html>
<head>
<title>Wave textbox test page</title>
<meta charset="utf-8">
<style>
body {
width: 800px;
margin: auto;
}
@josephg
josephg / gist:1022202
Created June 13, 2011 01:34
Love coffeescript
# A synchronous processing queue. The queue calls process on the arguments,
# ensuring that process() is only executing once at a time.
#
# process(data, callback) _MUST_ eventually call its callback.
#
# Example:
#
# queue = require 'syncqueue'
#
# fn = queue (data, callback) ->
@josephg
josephg / gist:1071272
Created July 8, 2011 06:52
Compare if two numbers have the same sign, benchmark.
<script>
var arr = [];
for (var i = 0; i < 100000; i++) {
num = Math.floor(Math.random() * 4147483648) - 2147483648 ;
if(num <= 0) {
num--;
}
arr.push(num);
@josephg
josephg / bench.coffee
Created July 18, 2011 07:09
OT Benchmark
type = require './src/text'
fs = require 'fs'
assert = require 'assert'
check = (ops, check) ->
for {doc, op1, op2, result} in ops
op1_ = type.transform op1, op2, -1
op2_ = type.transform op2, op1, 1
op12 = type.compose op1, op2_
@josephg
josephg / text-tp2.h
Created July 18, 2011 19:40
TP2 Operational transform code for text, in C
//
// text-tp2.h
#import <Foundation/Foundation.h>
//typedef struct {
// NSString *str;
// int num_tombs;
// int tombs[];
//} Doc;
@josephg
josephg / site.coffee
Created September 11, 2011 04:28
coffeescript: In site.coffee, Parse error on line NaN: Unexpected ')'
request = (url, options, callback) ->
if typeof options is 'function'
[options, callback] = [{}, options]
options = {}
options.url = url
options.success = (obj) ->
callback(null, obj)
options.error = (err) ->
if err then callback(err) else callback(true)
handler = new goog.net.BrowserChannel.Handler()
handler.channelOpened = (channel) =>
document.body.innerHTML += '<p>Connected</p>'
errors =
2: 'request failed'
6: 'unknown session id'
handler.channelError = (channel, error) =>
faye = require 'faye'
client = new faye.Client 'http://josephgentle.com:4321/bayeux'
client.subscribe '/msg', (message) ->
console.timeEnd message
.callback ->
console.log 'Connected!'
seq = 0