Skip to content

Instantly share code, notes, and snippets.

@fredrick
fredrick / powermean.r
Last active December 16, 2015 07:48
Generalized/power mean with R
# Power mean
## Examples:
## p = 1, arithmetic mean
## p = 2, quadratic mean (RMS)
pmean <- function(x, p) {
library(TTR)
return(tail(TTR::SMA(x^p, length(x))^(1/p), n=1))
}
@fredrick
fredrick / Preferences.sublime-settings
Created October 29, 2012 02:13
Sublime Text 2 Preferences
{
"color_scheme": "Packages/User/Monokai Soda.tmTheme",
"ensure_newline_at_eof_on_save": true,
"translate_tabs_to_spaces": true,
"font_face": "Monaco",
"font_size": 12,
"theme": "Soda Light.sublime-theme"
}
@fredrick
fredrick / PythonBenchmark.md
Created June 8, 2012 22:27
Real World Comparison of Python Platform Performance

Real World Comparison of Python Platform Performance

Data parsing benchmark, using homogeneous Python source code across all platforms with the exception of, for Cython, type annotation and compilation to C. CPython 2.7.2 invoked with python, Cython 0.16 with python with test script loading compiled module, and PyPy 1.9 with pypy.

wc data.log
  21768456  360606156 3563967905 data.log
@fredrick
fredrick / wordpress.sql
Created May 23, 2012 01:42
WordPress Test Installation
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `wordpress`
--
-- --------------------------------------------------------
--
-- Table structure for table `wp_commentmeta`
@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 / 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>