Skip to content

Instantly share code, notes, and snippets.

View jarrodhroberson's full-sized avatar

Jarrod Roberson jarrodhroberson

View GitHub Profile
// Only add if it doesn't exist yet!
if (!String.prototype.format) {
String.prototype.format = function() {
var str = this.toString();
if (!arguments.length)
return str;
var args = typeof arguments[0],
args = (("string" == args || "number" == args) ? arguments : arguments[0]);
for (arg in args)
str = str.replace(RegExp("\\{" + arg + "\\}", "gi"), args[arg]);
@jarrodhroberson
jarrodhroberson / TestRandomzingIterator.java
Created February 6, 2014 05:15
Answer to a Stackoverflow question
import org.junit.Test;
import javax.annotation.Nonnull;
import java.util.*;
public class TestRandomzingIterator
{
@Test
public void testRandomIteration()
{
@jarrodhroberson
jarrodhroberson / codex.json
Last active August 29, 2015 13:56
JSON Schemas
{
"$schema": "http://json-schema.org/schema#",
"definitions": {
"uuid": {
"title": "uuid",
"description": "UUID ( http://regex101.com/r/eJ7gN2 )",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
@jarrodhroberson
jarrodhroberson / debounce.js
Created February 8, 2014 14:46
Returns a function, that, as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for N milliseconds. If `immediate` is passed, trigger the function on the eading edge, instead of the trailing.
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function() {
@jarrodhroberson
jarrodhroberson / HealthStateSerializer.java
Last active August 29, 2015 13:56
ObjectName Serializer for Jackson, recursively serializes to JSON
package com.vertigrated.mbean.jackson;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import weblogic.health.HealthState;
import java.io.IOException;
@jarrodhroberson
jarrodhroberson / java_pid_finder.sh
Created February 14, 2014 03:00
Get the PID of a running Java process using only Bash tools
ps -ax | grep "java -jar" | grep -v "grep" | cut -d " " -f 1
@jarrodhroberson
jarrodhroberson / jasper_reports_dependency_fragment.xml
Created February 14, 2014 03:04
How to combine GWT and Jasper Reports using Maven
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>3.7.4</version>
<exclusions>
<exclusion>
<artifactId>jdtcore</artifactId>
<groupId>eclipse</groupId>
</exclusion>
</exclusions>
@jarrodhroberson
jarrodhroberson / jsapi_sample.cpp
Created February 14, 2014 03:11
SpiderMonkey in Xcode 3.2.3
#define XP_UNIX
#include "jsapi.h"
/* The class of the global object. */
static JSClass global_class = {
"global", JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
JSCLASS_NO_OPTIONAL_MEMBERS
};
@jarrodhroberson
jarrodhroberson / TestThreadStackSizes.java
Created February 14, 2014 03:15
How to determine how many threads you can create from Java
public class TestThreadStackSizes
{
public static void main(final String[] args)
{
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(final Thread t, final Throwable e)
{
System.err.println(e.getMessage());
System.exit(1);
}
@jarrodhroberson
jarrodhroberson / inet_mdns.erl
Created February 14, 2014 03:19
Bonjour / Zeroconf in Erlang with Caching Responses with Subscriptions
-module(inet_mdns).
-include_lib("kernel/src/inet_dns.hrl").
-export([open/2,start/0]).
-export([stop/1,receiver/1]).
-export([subscribe/2,unsubscribe/2,getsubs/1]).
% gets a timestamp in ms from the epoch
get_timestamp() ->
{Mega,Sec,Micro} = erlang:now(),