This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2014 Matthew Roberts | |
* MIT License, http://opensource.org/licenses/MIT | |
*/ | |
package org.matthewroberts; | |
import java.io.Serializable; | |
import java.lang.reflect.Field; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2014 Matthew Roberts | |
* MIT License, http://opensource.org/licenses/MIT | |
*/ | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
/** | |
* Checks to see if a String can be used as a valid Integer without resorting to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a single line command to executed directly in the CLI. This will NOT run as a shell script | |
# as-is. This assumes you have Python installed and should work on any Mac OS X system and most | |
# linux systems. | |
# | |
# This changes to the user's home directory, creates and changes into a public_html directory, | |
# creates a file called index.html with the contents "Hello, {username}", starts a Python HTTP server, | |
# and finally attempts to open your default browser to the webpage. If this last step doesn't happen, | |
# simply open a browser and go to http://127.0.0.1:8080. | |
cd && mkdir public_html && cd public_html && echo 'Hello,' $USER >> index.html && python -m SimpleHTTPServer 8080 & open http://127.0.0.1:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Assembles a hashmap, omitting null or empty values at runtime. This | |
* can be used in an abstract class and properly accessed in a child class. | |
* | |
* @return returns a hashmap of the current class fields that are not null | |
*/ | |
public Map<String, String> getNonNullMap() { | |
Class<?> clazz = null; | |
Map<String, String> classMap = new HashMap<String, String>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date; | |
import java.util.Timer; | |
import java.util.TimerTask; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
/** | |
* Sets up a singleton to run a scheduled task. This ensures that only one | |
* instance of the task will run at once and allows monitoring of that task. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Handles the generation of the randomized grid and associated functions. | |
* | |
* @author Matthew Roberts | |
* matthew.bowen.roberts@gmail.com | |
* matthewroberts.org | |
*/ | |
public class GridGenerator { | |
private static final int MAX_RANDOM = 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<Integer, Integer[]> values = populate(); // should typically be a 2D array of type 'int' instead | |
for (int i = values.size() - 2; i >= 0; i--) { | |
for (int j = 0; j <= i; j++) { | |
values.get(i)[j] += | |
Math.max(values.get(i + 1)[j], values.get(i + 1)[j + 1]); | |
} | |
} | |
int largestPathSum = values.get(0)[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import com.sun.jersey.api.client.Client; | |
import com.sun.jersey.api.client.ClientResponse; | |
import com.sun.jersey.api.client.WebResource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Recursive quicksort method. Pivot is calculated at 1/2 the difference | |
* between supplied bounds. | |
* | |
* @param lowerBound | |
* the lower bound of indexed inputs - e.g., usually 0 | |
* @param upperBound | |
* the upper bound of indexed inputs - e.g., usually array.length | |
* @param array | |
* the array to sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
* There is absolutely no error checking in this game. It's used here as | |
* a basic example only. | |
* | |
* @author matthewroberts | |
* | |
*/ | |
public class TicTacToe { |