Skip to content

Instantly share code, notes, and snippets.

@fredrick
fredrick / test.log
Created May 17, 2012
Precision error in calculating variance
View test.log
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 Mar 21, 2012
Vector Array subclass
View curriedVector.js
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 Mar 21, 2012
Practical JavaScript currying
View curry.js
function Add(a) {
return {
to: function(b) { return a + b; }
}
}
@fredrick
fredrick / drive.js
Created Feb 11, 2012
Prototype monads/currying
View drive.js
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 Feb 1, 2012
Handling multipart events in Mongoose Query callback?
View models.js
var mongoose = require('mongoose');
function User() {
return mongoose.model('users', new mongoose.Schema({
username: String,
email: String,
name: String
}));
}
@fredrick
fredrick / UserQuery.js
Created Feb 1, 2012
Async.js and Node.js
View UserQuery.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 Jan 30, 2012
Fill image technique
View page.html
<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 Jan 25, 2012
Top 1000 words of President Obama's 2012 State of the Union Address
View SOTU.tsv
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
View ema.wilder.iterative.js
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
View getscala.sh
wget http://www.scala-lang.org/downloads/distrib/files/scala-2.9.1.final.tgz
tar -xzvf scala-2.9.1.final.tgz
You can’t perform that action at this time.