Skip to content

Instantly share code, notes, and snippets.

ClassCubeGists

View GitHub Profile
@ClassCubeGists
ClassCubeGists / CodeWordChecker.java
Last active May 18, 2018
CodeWordChecker solution - AP 2018 FRQ - https://clsc.be/25
View CodeWordChecker.java
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
WordPairList Solution - AP 2018 FRQ - https://clsc.be/26
View PartA.java
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
FrogSimulation solution - AP 2018 FRQ - https://clsc.be/28
View PartA.java
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
Solution to 2018 AP FRQ ArrayTester - https://clsc.be/27
View PartA.java
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 Feb 14, 2018
Example code for blocking browser refreshes when using the Ace editor. Written for a blog post at https://clsc.be/1w
View bindEditor.js
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({
View ImageGridTest.java
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 Oct 19, 2017
Solution for problem on ClassCube Moodle demo site https://moodle.classcube.com
View VowelCounter.java
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 Oct 15, 2017
Code samples for a quick demo on Java NullPointerException https://clsc.be/12
View Demo.java
import java.util.ArrayList;
public class Demo {
private ArrayList<String> words;
public Demo( String[] theWords ) {
for (String s: theWords) {
words.add(s);
}
}
View PrintSquare.java
public class PrintSquare {
public void printSquare() {
// Your code goes here...
}
}
@ClassCubeGists
ClassCubeGists / OutputCaptureTest.java
Last active Jun 6, 2017
Capturing stdOut and stdErr as part of a JUnit test. See https://classcube.com/junit-compare-output/ for explanations.
View OutputCaptureTest.java
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();
You can’t perform that action at this time.