Skip to content

Instantly share code, notes, and snippets.

const Decimal = require('decimal.js');
function cdf(n, k, p) {
const probability = new Decimal(p);
const lambda = new Decimal(n).times(probability);
let total = new Decimal(0);
for (let i = 0; i <= n-k; i++) {
const res = lambda.pow(i).dividedBy(factorial(i));
total = total.plus(res);
}
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const CRDT = require('../')
const transmit = require('./transmit')
@dirkmc
dirkmc / interceptor.js
Last active January 20, 2016 17:01
Intercept requests from Amazon ELB and proxy them to a back end service depending on the IP indicated by the PROXY protocol
// Config looks like this:
/*
proxy: {
port: 5000,
// Indicates if there is a PROXY protocol enabled Load Balancer
// between us and the client
useProxyProtocol: true,
status: {
path: '/status.json',
// How many times can a host fail to respond before it is
var _ = require('underscore');
var async = require('async');
var config = require('config');
var request = require('superagent');
var conntrack = require('service-base').net.conntrack;
var logger = require('service-base').logger;
var errorHandler = require('errorhandler');
var httpProxy = require('http-proxy');
var iphash = require('./iphash');
var env = process.env.NODE_ENV || 'development';
@dirkmc
dirkmc / gist:1509670
Created December 22, 2011 09:29 — forked from schacon/gist:1
the meaning of gist
Forked
This is gist.
There are many like it, but this one is mine.
It is my life.
I must master it as I must master my life.
Without me gist is useless.
Without gist, I am useless.
@dirkmc
dirkmc / scala-list-map.markdown
Created December 22, 2011 08:47
Scala List map

Use List.map() to transform a list of elements into another list:

val fruitPics = List("banana.jpg", "orange.jpg", "strawberry.jpg", "apple.jpg")
val fileSizes = fruitPics.map(fruit => new java.io.File(parentDir, fruit).length)
// fileSizes: List(12321423, 643423, 234233, 2342343)
@dirkmc
dirkmc / scala-list-for-each.markdown
Created December 22, 2011 08:34
Scala List for each

Use foreach to iterate over a list

val fruits = List("banana", "orange", "strawberry", "apple", "pear")
fruits.foreach(fruit => println(fruit))

For simple operations you can just use an underscore instead of naming the argument:

@dirkmc
dirkmc / scala-list-example.markdown
Created December 22, 2011 07:35
Creating Lists with Scala

Scala encourages developers to create data structures that cannot be modified.

To create an immutable list:

val fruits = List("apple", "pear", "orange")

Concatenate two lists:

@dirkmc
dirkmc / newgist.markdown
Created December 22, 2011 06:23
Testing out a new gist

Just testing this out for now.

Here's some explicitly marked java code:

    import java.lang.String;
    public static void main(String args[]) {
        System.out.println("cheese v3.0");
    }
import org.scribe.extractors.UrlParameterExtractor;
// import ...
public class TwitterAuth extends Controller {
public static void signInWithTwitter() throws Exception {
Token requestToken = Twitter.getService().getRequestToken();
Cache.set(requestToken.getToken(), requestToken, "60min");
String authorizationUrl = Twitter.getService()
.getAuthorizationUrl(requestToken);