Skip to content

Instantly share code, notes, and snippets.

View jarrodhroberson's full-sized avatar

Jarrod Roberson jarrodhroberson

View GitHub Profile
@jarrodhroberson
jarrodhroberson / String.prototype.format.js
Created November 16, 2017 00:55
String.prototype.format
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;
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.*;

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
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
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))
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
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
{
/**
package com.vertigrated.rtti;
import com.google.common.collect.ImmutableSortedMap;
import org.junit.Test;
import java.io.Serializable;
public class MapAsJavaBeanProxyTest
{
@Test
package com.vertigrated.rtti;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.reflect.AbstractInvocationHandler;
import com.google.common.reflect.Reflection;
import javax.annotation.Nonnull;
import java.lang.reflect.Method;
import java.util.Map;