Skip to content

Instantly share code, notes, and snippets.

View malcolmgreaves's full-sized avatar

Malcolm Greaves malcolmgreaves

View GitHub Profile
@malcolmgreaves
malcolmgreaves / BinomialHypothesisTest.scala
Last active November 8, 2016 17:34
Self-contained binomial hypothesis testing. Specifically 2-tailed test at a confidence interval of 95%.
object BinomialHypothesisTest {
def tTestBinomial(p1:Double, n1:Int, p2:Double, n2:Int): TtestRes = {
val k = (n1*p1 + n2*p2) / (n1 + n2).toDouble
val z = (p1 - p2) / math.sqrt( k*(1 - k) * (1 / n1.toDouble + 1 / n2.toDouble) )
if(z > scoreForTwoTailed95CiPval)
RejectNull
else
FailToReject
}
#include <cmath>
#include <iostream>
using std::cout;
using std::endl;
float quake3_hack(float number) {
float x2 = number * 0.5f;
float y = number;
long i = *(long*) & y;
UNDERSTANDING HASH FUNCTIONS
by Geoff Pike
Version 0.2 --- early draft --- comments and questions welcome!
References appear in square brackets.
1 INTRODUCTION
Hashing has proven tremendously useful in constructing various fast
data structures and algorithms. It is typically possible to simplify
@malcolmgreaves
malcolmgreaves / os_fp.py
Last active June 29, 2017 00:27
Listing all files from a given directory using functional programming.
from functools import partial
from operator import concat
from os.path import isfile
from fold import foldl
def _list_files_from(part, prev):
current = "%s/%s" % (prev, part)
if isfile(current):
@propensive
propensive / json.scala
Created November 26, 2012 14:53
Rapture I/O JSON extraction example
import rapture.io._
// Let's parse some JSON
val src: Json = Json.parse("""
{
"foo": "Hello world",
"bar": {
"baz": 42
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@malcolmgreaves
malcolmgreaves / val_max.scala
Last active February 23, 2018 04:20
Generic maximum function (max) with float-value-transforming typeclass (Val).
case class Scored[T](item: T, value: Double)
trait Val[-A] {
def valueOf(a: A): Double
}
object Val {
def apply[T: Val]: Val[T] =
implicitly[Val[T]]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@malcolmgreaves
malcolmgreaves / download.sh
Created April 24, 2018 20:41
Bash function for a better CLI remote file download experience.
#!/bin/bash
# Bash function to download a file with wget, showing a progress bar and enables
# re-downloading if interrupted. Also can automatically determine filename from
# supplied URL or override from command line.
# First argument is URL.
# Second optional argument is filename.
download () {
local URL="$1"
local FI="$2"
package mapreduce
/**
* This is an attempt to find a minimal set of type classes that describe the map-reduce programming model
* (the underlying model of Google map/reduce, Hadoop, Spark and others)
* The idea is to have:
* 1) lawful types that fully constrain correctness
* 2) a minimal set of laws (i.e. we can't remove any laws,
* 3) able to fully express existing map/reduce in terms of these types
*