Skip to content

Instantly share code, notes, and snippets.

View gschaffner's full-sized avatar

Ganden Schaffner gschaffner

  • Andrew Jayich Lab @ UCSB
View GitHub Profile
@gschaffner
gschaffner / APCS-Test-Practice-Barron's-3.java
Last active May 2, 2016 22:19
APCS Written Test Practice Barron's 3
// 1a
public boolean isAisleSeat(int row, int seatNumber) {
return seatNumber == 0 || seatNumber == SEATS_PER_ROW - 1;
}
// 1b
public boolean twoTogether() {
for(int i = 0; i < NUM_ROWS; i++) {
for(int j = 0; j < SEATS_PER_ROW - 1; j++) {
if(seats[i][j] == 0 && seats[i][j + 1] == 0) {
@gschaffner
gschaffner / APCS-Test-Practice-Barron's-2.java
Last active May 2, 2016 04:30
APCS Written Test Practice Barron's 2
// 1a
public String extractCity(String cityZip) {
return CityZip.substring(0, cityZip.indexOf(','));
}
// 1b
public void printNames() {
System.out.println(lines.get(0));
for(int i = 1; i < lines.size() - 1; i++) {
// I forgot the -1 in the header above
@gschaffner
gschaffner / APCS-Test-Practice-Barron's-1.java
Last active May 23, 2021 12:51
APCS Written Test Practice Barron's 1
// 1a
public static void reverseArray(int[] arr) {
for(int i = 0; i = arr.length / 2; i++) {
arr[i] = arr[i] + arr[arr.length - i - 1];
arr[arr.length - i - 1] = arr[i] - arr[arr.length - i - 1];
arr[i] = arr[i] - arr[arr.length - i - 1];
}
}
// 1b
@gschaffner
gschaffner / APCS-Test-Practice-2015.java
Last active April 28, 2016 04:51
APCS Written Test Practice 2015
// 1a
public static int arraySum(int[] arr) {
int sum = 0;
for(int elem : arr)
if(elem != null)
sum += elem;
return sum;
}
// 1b
@gschaffner
gschaffner / APCS-Test-Practice-2014.java
Last active April 21, 2016 04:02
APCS Written Test Practice 2014
// 1a
public static String scrambleWord(String word) {
String newWord = "";
for(int i = 0; i < word.length - 1; i++) {
if(word.charAt(i) == 'A' && word.charAt(i + 1) != 'A') {
newWord += word.charAt(i + 1) + word.charAt(i);
i++;
} else {
newWord += word.charAt(i);
}
@gschaffner
gschaffner / APCS-Test-Practice-2013.java
Created April 14, 2016 05:51
APCS Written Test Practice 2013
// 1a
public DownloadInfo getDownloadInfo(String title) {
for(DownloadInfo elem : downloadList) {
if(elem.getTitle().equals(title)) {
return elem;
}
}
return null;
}
@gschaffner
gschaffner / cVimrc
Last active April 25, 2017 02:16
cVim Settings
set noautofocus " The opposite of autofocus; this setting stops
" sites from focusing on an input box when they load
let barposition = "top"
set autoupdategist
let blacklists = ["*://www.reddit.com/*", "*://ganden.duckdns.org/*", "*://mail.google.com/*", "*://docs.google.com/*", "*://*gistboxapp.com/*", "*://www.codecademy.com/*", "*://*yappy.im/*", "*://*airtable.com/*", "*://quizlet.com/*"]