This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// utility to shrink/recompress an image if it's big or non-JPEG | |
// input is a Blob (superclass of File, so File also ok), output a Blob | |
const MAX_DIM = 1536; | |
const QUALITY = 0.80; | |
export default function shrinkImage(blob) { | |
return new Promise((resolve, reject) => { | |
const url = URL.createObjectURL(blob); | |
const img = document.createElement('img'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from this | |
type SavedPlaylistItem = { | |
id: string, | |
checksum: number, | |
}; | |
// generate this | |
function getSavedPlaylistItem(payload: Object): ?SavedPlaylistItem { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
NewerOlder