Skip to content

Instantly share code, notes, and snippets.

@guipn
guipn / bayes.hs
Created September 8, 2014 00:54
Simple Bayesian inference of the chance someone is infected with a disease.
{--
- These functions handle the common scenario presented in introductory classes on Bayesian Inference.
-
--}
type Probability = Double
type Prior = Probability
type AccuracyPos = Probability
type AccuracyNeg = Probability
type BayesianInf = Probability
@guipn
guipn / beatletroca.js
Last active August 29, 2015 14:02
Beat Letroca
var dict = process.argv[2],
inputLetters = process.argv[3],
words = require('fs')
.readFileSync(dict, {encoding: 'utf8'})
.toLowerCase()
.replace(/\/.+/g, '')
.split(/\r\n/);
@guipn
guipn / wc.hs
Last active August 29, 2015 14:02
word count
module Main where
import qualified Data.Map as Map
import qualified Data.List as List
import qualified Data.Ord as Ord
main :: IO ()
main = interact $ prettyPrint . toSortedList . counts . List.words
@guipn
guipn / filechecks.hs
Created May 27, 2014 01:28
Calculate File Checksums
import qualified Data.ByteString.Lazy as BL
import Data.Digest.Pure.MD5
import Data.Digest.Pure.SHA
import System.Environment
main = do
args <- getArgs
content <- BL.readFile $ args !! 0
putStrLn $ "SHA-1:\t\t" ++ (showDigest $ sha1 content)
putStrLn $ "SHA-256:\t" ++ (showDigest $ sha256 content)
@guipn
guipn / gist:9457511
Created March 10, 2014 00:44
Are all values unique?
function allUnique(values) {
return values.reduce(function (unique, next) {
if (unique.indexOf(next) === -1) {
unique.push(next);
}
return unique;
}, []).length === values.length;
var fs = require('fs'),
cfg = JSON.parse(fs.readFileSync('respawn.json', { encoding: 'utf8' })),
now = new Date(),
t_stamp = now.getFullYear() + '-' +
(now.getMonth() + 1) + '-' +
now.getDate();
function copy(source, target) {
@guipn
guipn / excellent.htm
Last active December 23, 2015 18:59
Indent ugly Excel formulas...
<html>
<head>
<title>Excellent</title>
<style type="text/css">
body {
text-align: center;
}
</style>
</head>
<body>
@guipn
guipn / rpn.hs
Last active December 19, 2015 17:18
Simple RPN calculator in Haskell.
module Main where
import System.Environment(getArgs)
type Value = Double
type Operand = Value
type Result = Value
type BinaryOp = Operand -> Operand -> Result
type Arguments = [String]
type Stack = [Value]
@guipn
guipn / def_a_prop.js
Created March 26, 2013 07:04
Demonstration of Object.defineProperty on arrays. The algorithm followed is specified in 15.2.3.6 and 15.4.5.1.
var a = [];
Object.defineProperty(a, '0', {
get: function () {
console.log("Here it is.");
}
});
a.push(10);
void a[0]; // logs 'Here it is.'.
@guipn
guipn / rpn.c
Last active December 14, 2015 17:29
A monolithic, simple RPN calculator with a decent structure.
/* An extensible RPN calculator.
* gcc -std=c99 -Wall -Wextra -pedantic rpn.c -o rpn
*
* example: ./rpn 10 20 / 2 "*" -> 1.00
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>