Skip to content

Instantly share code, notes, and snippets.

Scott Feeney graue

Block or report user

Report or block graue

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View flow-verifier.js
// from this
type SavedPlaylistItem = {
id: string,
checksum: number,
};
// generate this
function getSavedPlaylistItem(payload: Object): ?SavedPlaylistItem {
@graue
graue / fluxtalk.txt
Created Dec 31, 2014
Notes on Bill Fisher and Jing Chen's Flux talk
View fluxtalk.txt
https://speakerdeck.com/fisherwebdev/fluxchat
https://www.youtube.com/watch?v=i__969noyAM
Stores: "fat models", contain all data for a particular domain
Also application logic for that domain
Setup: Register with the dispatcher (a pub/sub system, distributes
actions to all the stores registered to listen to it)
View gtboom.js
// Fine with 100 tests — not so good with `gentest -n 1000 gtboom.js`
// (as of gentest 0.1.1)
//
// Adapted from Jamie Brandon's double-check example:
// https://github.com/jamii/dcboom/blob/master/src/dcboom/core.cljs
var t = gentest.types;
forAll([t.arrayOf(t.arrayOf(t.string))],
'simulate sparse/complex failure',
@graue
graue / testingStyles.js
Last active Aug 29, 2015
Styles of property-based testing in JavaScript
View testingStyles.js
// Option #1
prop('addition is commutative', [Number, Number], function(a, b) {
return add(a, b) === add(b, a);
});
// Option #2
prop('addition is commutative', function(any) {
var a = any(Number);
var b = any(Number);
return add(a, b) === add(b, a);
@graue
graue / gentest_bundle_5a96613.js
Created Jul 25, 2014
Gentest bundle for browsers
View gentest_bundle_5a96613.js
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
window.gentest = require('./index');
},{"./index":2}],2:[function(require,module,exports){
exports.run = require('./lib/run');
exports.sample = require('./lib/sample');
exports.types = require('./lib/types');
var errors = require('./lib/errors');
exports.FailureError = errors.FailureError;
View BurtlePRNG.js
function BurtlePRNG(seed) {
seed >>>= 0;
var ctx = this.ctx = new Array(4);
ctx[0] = 0xf1ea5eed;
ctx[1] = ctx[2] = ctx[3] = seed;
for (var i = 0; i < 20; i++) {
this.next();
}
return this;
}
View maze.js
// Adapted from Clojure code by Pablo Torres
// Original: https://gist.github.com/ptn/3c94f540b2e8d26bafce
var Immutable = require('immutable');
var V = Immutable.Vector;
var I = Immutable.fromNative;
// Helper: shuffle an immutable vector, returning a new one.
function shuffle(vec) {
var out = [];
View collatz_quine.py
# 3 10 5 16 8 4 2 1
import sys
def collatz(n):
out = str(n)
while n > 1:
if n % 2 == 1:
n = n*3 + 1
else:
n = n / 2
View collatz.rs
// Prints Collatz sequence from a given integer.
// By Scott Feeney, released under CC0 Public Domain Dedication 1.0.
use std::io;
fn main() {
let mut num = read_number();
loop {
println!("{:d}", num);
match next_collatz(num) {
@graue
graue / expectKeys.js
Created May 19, 2014
Function to warn if unexpected keys are in an object
View expectKeys.js
// Shameless yak-shaving. I don't even remotely need this for
// anything right now, but wrote it due to a lament that keys
// in JavaScript {options: 'objects'} aren't checked for
// correctness and typos/misspelling can easily go unnoticed.
var _ = require('underscore');
// Expect all keys in the object to be from the list in "allowed".
// Emit a warning if they don't.
// TODO: Should compile down to nothing in production as this is
You can’t perform that action at this time.