Skip to content

Instantly share code, notes, and snippets.

Avatar

Steve Coffman StevenACoffman

  • Khan Academy
  • Ann Arbor, MI
View GitHub Profile
@StevenACoffman
StevenACoffman / fizzbuzz.js
Last active Aug 29, 2015 — forked from TGOlson/fizzbuzz.js
Point-free JavaScript FizzBuzz Kata
View fizzbuzz.js
var R = require('ramda');
var factorOf = R.compose(R.equals(0), R.flip(R.modulo));
var getFizzBuzz = R.cond([
[factorOf(15), R.always('FizzBuzz')],
[factorOf(5), R.always('Buzz')],
[factorOf(3), R.always('Fizz')],
[R.T, R.identity]
]);
View fizzbuzz.js
// fizzbuzz ramda-style
var R = require('ramda');
R.forEach(R.cond([
[R.pipe(R.modulo(R.__, 15), R.equals(0)), R.always('FizzBuzz')],
[R.pipe(R.modulo(R.__, 3), R.equals(0)), R.always('Fizz')],
[R.pipe(R.modulo(R.__, 5), R.equals(0)), R.always('Buzz')],
[R.T, R.identity]
]), R.range(1, 101));
//with a helper function
@StevenACoffman
StevenACoffman / setenv.sh
Created Sep 3, 2015 — forked from terrancesnyder/setenv.sh
./setenv.sh - example setenv.sh with defaults set for minimal time spent in garbage collection
View setenv.sh
#! /bin/sh
# ==================================================================
# ______ __ ____
# /_ __/___ ____ ___ _________ _/ /_ ( __ )
# / / / __ \/ __ `__ \/ ___/ __ `/ __/ / __ |
# / / / /_/ / / / / / / /__/ /_/ / /_ / /_/ /
# /_/ \____/_/ /_/ /_/\___/\__,_/\__/ \____/
#
# Multi-instance Apache Tomcat installation with a focus
# on best-practices as defined by Apache, SpringSource, and MuleSoft
@StevenACoffman
StevenACoffman / build.gradle
Last active Nov 12, 2015
Failing gradle to init new grails with gradle plugin --stacktrace --debug 2> stderr.txt > stdout.txt
View build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.1.2"
}
}
version "0.1"
@StevenACoffman
StevenACoffman / build.gradle
Created Nov 13, 2015
Default build.gradle from Grails 3.0.9 generated with grails create-app new-document
View build.gradle
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
@StevenACoffman
StevenACoffman / generate_range.js
Last active Dec 23, 2015
Generate an array in a particular range
View generate_range.js
const start = 5;
const end = 20;
let myArray = Array.from(new Array(end - start)).map((_, index) => start + index);
console.log(myArray); // -> 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
//alernative
myArray = [...(new Array(end - start))].map((_, index) => start + index);
console.log(myArray); // -> 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
//alternative: arrayFrom takes optional map function parameter to avoid intermediate creation
myArray = Array.from(new Array(end - start),((_, index) => start + index)); // -> 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
View promise_example.js
'use strict';
const start = Date.now();
const ordinals = {
1: 'First',
2: 'Second',
3: 'Third',
4: 'Fourth',
5: 'Fifth'
};
const whatIsHappening = (result) => console.log(`${ordinals[result]} @ ${Date.now() - start} ms`);
@StevenACoffman
StevenACoffman / index.js
Last active Jan 27, 2016 — forked from roman01la/index.js
Broken but not sure why
View index.js
const mapping = (f) => (reducing) => (result, input, index) => reducing(result, f(input, index));
const filtering = (predicate) => (reducing) => (result, input, index) => predicate(input) ? reducing(result, input, index) : result;
const ALPHABET = 'abcdefghijklmnopqrstuvwxyz'.split('');
const NUMBERS = '0123456789'.split('');
const isAlphaNumeric = (letter) => ALPHABET.indexOf(letter) !== -1 || NUMBERS.indexOf(letter) !== -1;
const periodicallyPad = (current, index) => index !== 0 && index % 5 === 0 ? ' ' + current : current;
const concatenate = (xs, x, index) => xs.concat(x);
const result = 'I AM SO EXCITED ABOUT TRANSDUCERS'.toLowerCase().split('')
@StevenACoffman
StevenACoffman / BigBingo
Created Aug 1, 2016 — forked from alangpierce/BigBingo
BigBingo (as of early July 2014)
View BigBingo
Snapshot of Khan Academy's BigBingo A/B testing framework and related code.
Here's a basic overview:
-summarize.py is the most interesting file. It contains all stages of the
summarize task, as well as the publish and archive steps that happen at the
end.
-bq_pipelines.py contains lots of useful pipelines for interacting with
BigQuery. QueryToTableBatchPipeline can run many simultaneous queries, and will
properly handle all batching and retry logic.
-config.py is where all experiment configuraiton lives. For this Gist, I
@StevenACoffman
StevenACoffman / MineFieldMapper.java
Created Aug 30, 2016
MineSweeper Kata 45-minute Randori Result at Ithaka
View MineFieldMapper.java
import java.util.*;
public class MineFieldMapper {
public List<String> map(List<String> mineField) {
if (mineField.size() == 3) {
return Arrays.asList("1", "*", "1");
}
String s = mineField.get(0);