Skip to content

Instantly share code, notes, and snippets.

View spencerwi's full-sized avatar

Spencer Williams spencerwi

View GitHub Profile
@spencerwi
spencerwi / gist:6531144
Last active December 22, 2015 21:09
for a blog post
List<PersonEntity> attendees = conference.getAttendees();
Collections.sort(new Comparator<PersonEntity> {
@Override
public int sort(PersonEntity person1, PersonEntity person2) {
final int BOTH_ARE_EQUAL = 0;
int comparisonByArrivalDateResult = this.compareByArrivalDate(person1, person2);
if (comparisonByArrivalDateResult == BOTH_ARE_EQUAL) {
int comparisonByTicketTierResult = this.compareByTicketTier(person1, person2);
if (comparisonByTicketTierResult == BOTH_ARE_EQUAL) {
return this.compareByLastName(person1, person2);
@spencerwi
spencerwi / tsvtocsv.hs
Last active December 23, 2015 00:49
Convert TSV on stdin to CSV on stdout
import Data.List
import Text.Regex
encloseField :: String -> String
encloseField field
| "," `isInfixOf` field = "\"" ++ (escapeField field) ++ "\""
| otherwise = escapeField field
escapeField :: String -> String
escapeField field
@spencerwi
spencerwi / underscore-shell.js
Last active December 24, 2015 17:29
Start a quick Javascript repl with underscore preloaded using nodejs. Requires nodejs and npm-installed underscore.
var fs = require('fs');
var repl = require('repl');
var __ = require('underscore')._;
var files = {};
var jsonFiles = process.argv.slice(2);
jsonFiles.forEach(function(val) {
files[val] = JSON.parse(fs.readFileSync(val));
});
@spencerwi
spencerwi / docfrag.js
Last active December 28, 2015 06:09
Buffering DOM updates using DocumentFragments
/* Assumption: arrayOfElements is an array of DOM nodes created from a template or otherwise. */
/* Don't do this! This reflows the DOM a *lot* */
var targetNode = document.getElementById('target');
var appendToTargetNode = targetNode.appendChild.bind(targetNode);
arrayOfElements.forEach(appendToTargetNode);
/* Instead, use a DocumentFragment */
@spencerwi
spencerwi / displayNone.js
Created November 13, 2013 20:21
Poor-man's DocumentFragment using display:none
/* Again, the assumption: arrayOfElements is an array of DOM nodes created from a template or otherwise. */
/* We can set our targetNode to "display:none", change it, and then reset it, making it into a poor man's DocumentFragment */
var targetNode = document.getElementById('target');
var previousDisplayValue = targetNode.style.display;
targetNode.style.display="none"; /* 1 reflow */
var appendToNode = targetNode.appendChild.bind(targetNode);
arrayOfElements.forEach(appendtoTargetNode); /* 0 reflows */
@spencerwi
spencerwi / Main.elm
Last active February 24, 2016 22:36
Simple Elm FRP square demo
import Html exposing (div, text)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import StartApp as StartApp
import Signal as Signal
import Mouse as Mouse
import Effects as Effects
app = StartApp.start
{ init = (init, Effects.none)
@spencerwi
spencerwi / Mappable.java
Created May 6, 2016 15:23
HigherKindedTypes blog post code
public interface Mappable<A> {
public <B> Mappable<B> map(Function<A, B> f);
}
@spencerwi
spencerwi / Response.md
Last active July 29, 2016 22:33
In response to Wayne Grudem, regarding his endorsement of voting for Donald Trump as "morally good"

I also have found Grudem to be respectable in his Systematic Theology, but I'm disappointed in this article.

In summary, Grudem's points are:

  • Trump's not really that bad, is he? His sins, even though he wears them proudly, shouldn't be offensive to Christians.
  • Trump is the lesser of two evils. You don't want Hillary to win, do you? (Put another, even-more-cliched way, "not voting is the same as voting for Hillary" -- which is false, if I was never going to vote for Trump in the first place).
  • Christianity means doing what's best for America (and Trump is what's best for America).

I disagree with these premises; I do think the sins that Trump wears not just unrepentantly, but proudly, should be offensive to Christians, and should be more offensive to Grudem than they are; he minimizes outright insults that Trump has doubled-down on as "careless remarks" rather than the more Biblical "out of overflow of the heart, the mouth speaks" (as Jesus said in Luke 6).

Yes, Trump is egotistical. That fault can

declare abstract class TemporalAccessor {
get(field: TemporalField): number
query(query: TemporalQuery): any
range(field: TemporalField): ValueRange
}
declare abstract class Temporal extends TemporalAccessor {}
declare abstract class Clock {
static fixed(fixedInstant: Instant, zoneOffset: ZoneOffset): Clock
static system(zone: ZoneId): Clock
@spencerwi
spencerwi / CodeWarsTestRunner.scala
Last active September 17, 2016 18:48
Codewars test harness for scala (using scalatest)
import org.scalatest._;
import org.scalatest.events._;
class CodeWarsReporter extends Reporter {
def apply(event: Event) : Unit = event match {
case e: SuiteStarting => println(s"<DESCRIBE::> ${e.suiteName}")
case e: ScopeOpened => println(s"<DESCRIBE::> ${e.message}")
case e: TestStarting => println(s"<IT::>${e.testName}")
case e: TestSucceeded => {
println(s"<PASSED::>${e.testName}")