| 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)) |
This file contains hidden or 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
| cut -d: -f1 /etc/group |
This file contains hidden or 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
| 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; |
This file contains hidden or 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
| package com.vertigrated.rtti; | |
| import com.google.common.collect.ImmutableSortedMap; | |
| import org.junit.Test; | |
| import java.io.Serializable; | |
| public class MapAsJavaBeanProxyTest | |
| { | |
| @Test |
This file contains hidden or 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.Map; | |
| import javax.annotation.Nonnull; | |
| import javax.annotation.Nullable; | |
| import com.google.common.collect.ImmutableMap; | |
| import com.google.common.collect.Maps; | |
| public class MapTransforms | |
| { | |
| /** |
This file contains hidden or 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.sql.*; | |
| public class CloseAllResourcesWhenYouAreDonePreJava7 | |
| { | |
| public static void main(final String[] args) | |
| { | |
| try | |
| { | |
| final Connection cn = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", ""); | |
| try |
This file contains hidden or 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 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> |
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;
This file contains hidden or 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 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.*; |
This file contains hidden or 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
| 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; |