View utils.js
/*
* Returns a list of all the text nodes under the given node.
*
* The order should be depth-first, first-to-last across siblings.
*/
function findTextNodes(node) {
var HTML_TEXT_NODE = 3;
if (node.nodeType == HTML_TEXT_NODE) {
return [node];
}
View diff.py
from __future__ import print_function # Py2 compat
from collections import namedtuple
import sys
# These define the structure of the history, and correspond to diff output with
# lines that start with a space, a + and a - respectively.
Keep = namedtuple('Keep', ['line'])
Insert = namedtuple('Insert', ['line'])
Remove = namedtuple('Remove', ['line'])
View default.js
{
// NOTE: Only expect this to work on FF, Chrome or Edge.
// There are several arrow functions sprinkled around,
// and caniuse suggests that these are the only browsers
// that can handle them natively
init: function(elevators, floors) {
// The backlog is (an approximation of) the number of people currently waiting at
// the given floor.
//
View TestDiGraph.java
import static org.junit.Assert.*;
import org.junit.Test;
public class TestDiGraph {
/*
* Refactoring the commonalities of comparing toposorts with multiple
* valid results, into its own function.
*/
public void assertCorrectSort(DiGraphInterface graph, String... correct) {
String[] sorted = graph.topoSort();
View BinaryHeapTest.java
import static org.junit.Assert.*;
import org.junit.Test;
public class BinaryHeapTest {
/**
* If you are expecting null, then don't use this function - it is not null
* safe.
*/
private void entryPairAssertEqual(EntryPair expect, EntryPair actual) {
if (expect.getPriority() != actual.getPriority() ||
View compute-offsets.pl
# Computes the offsets of values in a MIPS .data segment
my $in_data = 0;
my $mem_offset;
my $current_label = "";
# Gets rid of C escapes like \n - note that this is only meant to preserve
# the length of the string, so it uses single-character placeholders rather
# than actually interpreting the escapes. For example, it would replace:
#
# Foo\'s bar\n
View ObservableFrame2DTest.java
package a6.test;
import a6.Pixel;
import a6.ColorPixel;
import a6.Coordinate;
import a6.Region;
import a6.Frame2D;
import a6.ObservableFrame2D;
import a6.ObservableFrame2DImpl;
import a6.ROIObserver;
View uKanren.scala
/**
* An implementation of microKanren (and probably most of miniKanren), with
* a few extras. Currently, it supports:
*
* - The essential core of microKanren: Unify, Fresh, Disjunction, Conjunction
* - Standard terms: Variables, Atoms, TermCons, EmptyTerm.
* - An implicit conversion from type T to Atom[T]. This makes writing programs
* much easier.
* - A decent reifier, which converts terms to strings.
*
View fizzbuzz.s
// FizzBuzz in x86 assembly - written on 32-bit Linux using the GNU ASsembler
.data
FIZZSTR:
.asciz "Fizz"
BUZZSTR:
.asciz "Buzz"
NEWLINE:
.asciz "\n"
// strtoa stores its data here. Since FizzBuzz runs 1-100, it won't need more than 3 bytes
View crowd.html
<canvas id="canvas" width="600" height="600">
</canvas> </br>
Method: <input id="algorithm" type="text"> </input> <br/>
Timestep (Hz): <input id="timestep" type="text"> </input> <br/>
<input id="start_stop" type="button" value="Start" onclick="run()"> </input> <br/>
<script>
////////////////////
var PERSON_RADIUS = 1;
var PERSON_SPEED = 5;