This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait PositionChange1 { | |
type OrderIdT | |
type ExecutionT | |
sealed trait Message | |
case class Cancel(order: OrderIdT) extends Message | |
case class Exec(e: ExecutionT) extends Message | |
def positionChange(m: Message) = m match { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Vector() { ... } | |
Vector.prototype.norm = function() { ... } | |
function Vector2D() { | |
// Watch out! | |
// We need to invoque the parent constructor | |
// so we don't miss any initialization behaviour | |
Vector.call(this); | |
// (or Vector.apply(this, arguments)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Vector() { | |
this.data = []; | |
} | |
Vector.prototype.norm = function() { | |
var sumsq = 0; | |
for(var i in this.data) { | |
sumsq += this.data[i] * this.data[i]; | |
} | |
return Math.sqrt(sumsq); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Vector2D(x,y) { | |
this.data = [x,y]; | |
} | |
Vector2D.prototype.sum = function(o) { | |
var sx = this.data[0] + o.data[0], | |
sy = this.data[1] + o.data[1]; | |
return new Vector2D(sx,sy) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: client.js. | |
// Define the client object | |
var client = { | |
url: 'http://echo.jsontest.com/u/1/b/c', | |
fetch: function() { | |
return $.getJSON(this.url) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var p = $.getJSON('http://echo.jsontest.com/u/1/b/c'); | |
function displayData(data) { | |
$('.content').html(JSON.stringify(data, null, 2)) | |
} | |
function logData(data) { | |
console.log('data received', data); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f[a_, x_] := a - .5 (x - .7)^2 | |
randomize[r_][x_] := x + RandomReal[{-Abs[x]*r, Abs[x]*r}] | |
drop[a_][x_] := With[{ | |
rx = randomize[.15][.006], | |
ry = randomize[.15][.004], | |
yd = RandomChoice[{1, -1}]*randomize[1][x*.003]}, | |
Circle[{x, f[a, x] + yd}, {rx, ry}]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val items = getNodes("/List/Item", document) map(_.getTextContent()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.collect.Iterables; | |
// ... | |
Iterable<String> items = Iterables.transform(getNodes("/List/Item", document), | |
new Function<Node, String>() { | |
public String apply(@Nullable Node node) { | |
//noinspection ConstantConditions | |
return node.getTextContent(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function asyncMap(promises, callback) { | |
var results = []; | |
for(var p in promises) { | |
if(!promises.hasOwnProperty(p)) { continue; } | |
promises[p].done(function(result) { | |
results.push(callback(result)) | |
}) | |
} | |
return $.when.apply(null,promises).pipe(function() { return results }); | |
} |