Skip to content

Instantly share code, notes, and snippets.

View ClassCubeGists's full-sized avatar

ClassCubeGists

View GitHub Profile
@ClassCubeGists
ClassCubeGists / CodeWordChecker.java
Last active May 18, 2018 12:54
CodeWordChecker solution - AP 2018 FRQ - https://clsc.be/25
public class CodeWordChecker implements StringChecker {
private int min;
private int max;
private String no;
public CodeWordChecker(int mi, int ma, String n) {
min = mi;
max = ma;
no = n;
}
@ClassCubeGists
ClassCubeGists / PartA.java
Last active May 18, 2018 12:54
WordPairList Solution - AP 2018 FRQ - https://clsc.be/26
public WordPairList(String[] words) {
allPairs = new ArrayList<>();
for (int i=0; i<words.length; i++)
for (x=i+1; x<words.length; x++)
allPairs.add(new WordPair(words[i], words[x]);
}
@ClassCubeGists
ClassCubeGists / PartA.java
Last active May 18, 2018 12:53
FrogSimulation solution - AP 2018 FRQ - https://clsc.be/28
public boolean simulate() {
int hops = 0;
int cntPos = 0;
while (hops < maxHops && cntPos >= 0 && cntPos < goalDistance) {
cntPos += hopDistance();
hops++;
}
return cntPos >= goalDistance;
}
@ClassCubeGists
ClassCubeGists / PartA.java
Last active May 18, 2018 12:55
Solution to 2018 AP FRQ ArrayTester - https://clsc.be/27
public static int[] getColumn(int[][] arr2D, int c) {
int[] out = new int[arr2D.length];
for (int r=0; r<arr2D.length; r++)
out[r] = arr2D[r][c];
return out;
}
@ClassCubeGists
ClassCubeGists / bindEditor.js
Last active February 14, 2018 20:27
Example code for blocking browser refreshes when using the Ace editor. Written for a blog post at https://clsc.be/1w
var edit = ace.edit('editor');
edit.commands.addCommand({
name: "blockCtrlR",
exec: function () {
editor.promptRefresh(false);
},
bindKey: {mac: "cmd-r", win: "ctrl-r"}
});
edit.commands.addCommand({
@ClassCubeGists
ClassCubeGists / ImageGridTest.java
Created October 22, 2017 18:25
JUnit test code used for example on https://moodle.classcube.com
import java.lang.reflect.Field;
import java.util.Arrays;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;
public class ImageGridTest {
private int rows;
@ClassCubeGists
ClassCubeGists / VowelCounter.java
Created October 19, 2017 00:53
Solution for problem on ClassCube Moodle demo site https://moodle.classcube.com
import java.io.*;
import java.util.*;
public class VowelCounter {
public static void main( String[] args ) {
// Your code goes here...
int cnt = 0;
try {
Scanner f = new Scanner(new File("words.dat"));
@ClassCubeGists
ClassCubeGists / Demo.java
Last active October 15, 2017 20:19
Code samples for a quick demo on Java NullPointerException https://clsc.be/12
import java.util.ArrayList;
public class Demo {
private ArrayList<String> words;
public Demo( String[] theWords ) {
for (String s: theWords) {
words.add(s);
}
}
public class PrintSquare {
public void printSquare() {
// Your code goes here...
}
}
@ClassCubeGists
ClassCubeGists / OutputCaptureTest.java
Last active July 11, 2019 01:09
Capturing stdOut and stdErr as part of a JUnit test. See https://classcube.com/junit-compare-output/ for explanations.
import java.util.*;
import java.io.*;
import static org.junit.Assert.*;
import org.junit.Test;
@SuppressWarnings( "unchecked" )
public class OutputCaptureTest {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();