Skip to content

Instantly share code, notes, and snippets.

View jarrodhroberson's full-sized avatar

Jarrod Roberson jarrodhroberson

View GitHub Profile
import com.google.common.base.Joiner;
import javax.annotation.Nonnull;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@jarrodhroberson
jarrodhroberson / TimeZoneInfo.java
Created July 21, 2015 19:56
Dump TimeZone Information with an example of the current time in ISO8601 FULL
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import javax.annotation.Nonnull;
public class TimeZoneInfo
{
public static void main(@Nonnull final String[] args)
{
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
@jarrodhroberson
jarrodhroberson / PipedInputOutputStreams.java
Created June 14, 2015 08:44
How to use PipedInputStream and PipedOutputStream
import com.google.common.io.ByteStreams;
import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
public class PipedInputOutputStreams
{
public static void main(String[] args)
@jarrodhroberson
jarrodhroberson / Output.java
Last active August 29, 2015 14:22
Obfuscated String source code generator functions
final String bytes = new String(new byte[]{0x4a,0x61,0x72,0x72,0x6f,0x64}, Charsets.UTF_8);
@jarrodhroberson
jarrodhroberson / ObjectifyLoaderContextListener.java
Created April 12, 2015 10:34
Runtime Entity registration with very little overhead!
package com.vertigrated.servlet;
import com.google.appengine.api.ThreadManager;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.annotation.Entity;
import org.reflections.Reflections;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import org.slf4j.Logger;
@jarrodhroberson
jarrodhroberson / telemetry.ino
Last active August 29, 2015 14:13
arduino telemetry code for science fair 2015 project
#include <I2Cdev.h>
#include <LiquidCrystal.h>
#include "MPU6050_6Axis_MotionApps20.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
@jarrodhroberson
jarrodhroberson / ScannerExample.java
Last active August 29, 2015 14:07
Idiomatic Scanner Usage
package com.stackoverflow.scanner;
import javax.annotation.Nonnull;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.regex.Pattern;
import static java.lang.String.format;
@jarrodhroberson
jarrodhroberson / DocumentedRuntimeExceptionExample.java
Last active August 29, 2015 14:07
How to document possible exceptions but not weigh now clients code with mandatory try/catch noise!
public class DocumentedRuntimeExceptionExample
{
public static void main(final String[] args)
{
test();
}
public static void test() throws TestFailedRuntimeException
{
// do some stuff that may or may not throw an exception
import com.google.common.reflect.TypeToken;
@SuppressWarnings("unchecked")
public T get()
{
final Class<T> entityType = (Class<T>) new TypeToken<T>(getClass()) {}.getRawType();
try { return entityType.newInstance(); }
catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); }
}
var underscore = (function(underscore){
// Build several namespaces, globally...
var UUID = {};
var Sha1 = function(str){return Sha1.hash(str, true);};
var Utf8 = {};
var extend = function() {
var options, name, src, copy, copyIsArray, clone,