Skip to content

Instantly share code, notes, and snippets.

Avatar

Jarrod Roberson jarrodhroberson

View GitHub Profile
@jarrodhroberson
jarrodhroberson / tictactoe.py
Created July 25, 2019 17:10
Python 3 TicTacToe Game for Console
View tictactoe.py
# Import needed modules
import os
import time
import re
# Regular Expression to validate that the input is in the expected format!
inputPattern = re.compile('^\d{1},\d{1}$')
#Initialize a 2D array to represent the board using a SPACE to represent unclaimed cells.
board = [[' ' for x in range(3)] for y in range(3)]
View NATURAL_ORDER.java
public static final Ordering<SubCategory> NATURAL_ORDER;
static
{
NATURAL_ORDER = new Ordering<SubCategory>() {
@Override
public int compare(@Nullable final SubCategory left, @Nullable final SubCategory right)
{
return ComparisonChain.start()
.compare(checkNotNull(left).categoryId, checkNotNull(right).categoryId)
@jarrodhroberson
jarrodhroberson / .bash_aliases
Last active April 24, 2018 14:02
bash scripts
View .bash_aliases
alias ll='ls -lha --color=always'
alias subl='subl --touch --cygstart --'
@jarrodhroberson
jarrodhroberson / String.prototype.format.js
Created November 16, 2017 00:55
String.prototype.format
View String.prototype.format.js
String.prototype.format = function() {
var self = this,
formats = self.match(/{(:?\d*)}/g), // an array of formats `{}` found in the string
counter = 0, // A counter to keep track of what index to replace with
args = arguments; // Dereferencing arguments for use in the nested code blocks
if (formats) {
formats.forEach(function(format) { // We loop through each format expression in the array
var namedMatch = format.match(/{:(\d+)}/), // Checking if the format is a named replacement (i.e. {:1})
reg;
View StreamVsDecorator.java
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import javafx.util.Pair;
import javax.annotation.Nonnull;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import static com.google.common.collect.Iterables.*;
View Oracle Drop If Exists.md

From Oracle: If Table Exists:

The best and most efficient way is to catch the "table not found" exception: this avoids the overhead of checking if the table exists twice; and doesn't suffer from the problem that if the DROP fails for some other reason (that might be important) the exception is still raised to the caller:

BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE mytable';
EXCEPTION
   WHEN OTHERS THEN
      IF SQLCODE != -942 THEN

RAISE;

@jarrodhroberson
jarrodhroberson / IsEmpty.java
Last active September 3, 2019 00:10
Custom IsEmpty Hamcrest Matcher
View IsEmpty.java
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import javax.annotation.Nonnull;
import java.lang.reflect.InvocationTargetException;
/** Matches any class that has an <code>isEmpty()</code> method
* that returns a <code>boolean</code>
@jarrodhroberson
jarrodhroberson / UUID SQL.md
Last active September 5, 2017 19:57
converting RAW UUID types to Strings via SQL
View UUID SQL.md
Database Storage Type How to convert
Oracle RAW(16) REGEXP_REPLACE(binary-guid, '(.{8})(.{4})(.{4})(.{4})(.\*)', '\1-\2-\3-\4-\5')()
SQL Server UNIQUEIDENTIFIER CONVERT(CHAR(36), binary-guid)
MySQL BINARY(16) CONCAT_WS('-',`` SUBSTR(HEX(binary-guid), 1, 8),`` SUBSTR(HEX(binary-guid), 9, 4),`` SUBSTR(HEX(binary-guid), 13, 4),`` SUBSTR(HEX(binary-guid), 17, 4),`` SUBSTR(HEX(binary-guid), 21))
View CloseAllResourcesWhenYouAreDonePreJava7.java
import java.sql.*;
public class CloseAllResourcesWhenYouAreDonePreJava7
{
public static void main(final String[] args)
{
try
{
final Connection cn = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "");
try
@jarrodhroberson
jarrodhroberson / MapTransforms.java
Created January 20, 2016 21:04
Overlay/Merge an ImmutableMap over another ImmutableMap
View MapTransforms.java
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
public class MapTransforms
{
/**