Skip to content

Instantly share code, notes, and snippets.

@fredrick
fredrick / test.log
Created May 17, 2012 02:53
Precision error in calculating variance
Push (Variance)
✗ 0.468596215155556
» expected 0.46859621515555566,
got 0.468596215155556 (==) // vector.test.js:359
✗ Broken » 38 honored ∙ 1 broken (0.022s)
@fredrick
fredrick / curriedVector.js
Created March 21, 2012 21:55
Vector Array subclass
var Vector = function(values) {
var vector = !(values instanceof Array) ?
Array.prototype.slice.call(arguments) :
values;
return function(i) {
if(typeof i === 'number')
return vector[i];
else
return vector;
};
@fredrick
fredrick / curry.js
Created March 21, 2012 19:51
Practical JavaScript currying
function Add(a) {
return {
to: function(b) { return a + b; }
}
}
@fredrick
fredrick / drive.js
Created February 11, 2012 23:36
Prototype monads/currying
function In(drive) {
this.drive = drive;
}
function Within(path) {
this.path = path;
}
In.prototype.within = function(path) {
var within = new Within(path);
@fredrick
fredrick / models.js
Created February 1, 2012 05:46
Handling multipart events in Mongoose Query callback?
var mongoose = require('mongoose');
function User() {
return mongoose.model('users', new mongoose.Schema({
username: String,
email: String,
name: String
}));
}
@fredrick
fredrick / UserQuery.js
Created February 1, 2012 02:24
Async.js and Node.js
var async = require('async');
// Waterfall through callbacks using Mongoose to query for a user
async.waterfall([
function(callback) {
/** Function 1. Find User.
* Pass `user` to Function 2.
*/
User.findOne({ username: 'fred' }, function(error, user) {
@fredrick
fredrick / page.html
Created January 30, 2012 21:08
Fill image technique
<div class="main column left">
<img src="/images/placeholder/graphic_630x420.jpg" alt="First 2012 Mission Creek Festival Announcement" />
<div class="headline">
<h3>First 2012 Mission Creek Festival Announcement</h3>
<p>
Iowa City’s Mission Creek Festival Returns March 27-April 1, 2012, and KRUI has the scoop on the star-studded line-up...and this is just the first announcement!
</p>
</div>
</div>
@fredrick
fredrick / SOTU.tsv
Created January 25, 2012 06:24
Top 1000 words of President Obama's 2012 State of the Union Address
Word Occurrences Frequency Rank
our 84 2.1% 1
you 37 0.9% 2
american 35 0.9% 2
jobs 34 0.8% 3
america 30 0.7% 4
we\ 30 0.7% 4
right 27 0.7% 4
new 27 0.7% 4
now 26 0.6% 5
@fredrick
fredrick / ema.wilder.iterative.js
Created January 12, 2012 21:58
Node.JS + v8 profiling
Array = require('gauss').Vector;
var prices = [22.2734, 22.194, 22.0847, 22.1741, 22.184, 22.1344,
22.2337, 22.4323, 22.2436, 22.2933, 22.1542, 22.3926,
22.3816, 22.6109, 23.3558, 24.0519, 23.753, 23.8324,
23.9516, 23.6338, 23.8225, 23.8722, 23.6537, 23.187,
23.0976, 23.326, 22.6805, 23.0976, 22.4025, 22.1725];
/* Use Wilder ratio on an exponential moving average period of 10,
1 million iterations
@fredrick
fredrick / getscala.sh
Created December 22, 2011 22:06
Install scala
wget http://www.scala-lang.org/downloads/distrib/files/scala-2.9.1.final.tgz
tar -xzvf scala-2.9.1.final.tgz