Skip to content

Instantly share code, notes, and snippets.

View jarrodhroberson's full-sized avatar

Jarrod Roberson jarrodhroberson

View GitHub Profile
@jarrodhroberson
jarrodhroberson / Question18818482.java
Created September 16, 2013 02:21
How to run a Thread for a specific amount of time.
package com.stackoverflow.Q18818482;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.*;
public class Question18818482
{
@jarrodhroberson
jarrodhroberson / CalcMD5Worker.js
Created November 26, 2013 00:09
Reading a File in chunks with the HTML5 FileReader API and calculating MD5 hash codes of the contents with the spark-md5 library in a WebWorker.
importScripts('spark-md5.min.js');
function calcMD5(f) {
var blobSlice = Blob.prototype.slice;
var chunkSize = 2097152;
var chunks = Math.ceil(f.size/chunkSize);
var spark = new SparkMD5.ArrayBuffer();
var currentChunk = 0;
var fr = new FileReader();
@jarrodhroberson
jarrodhroberson / CellToolTip.js
Created December 3, 2013 03:44
ExtJS 4.x Grid Plugin to add ToolTips to each Cell in a Column with Process Config Function snippet for a Grid Panel.
Ext.define('Ext.grid.plugin.CellToolTip', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.CellQTip',
config: {
debug: false
},
init: function(grid) {
// You may not need the scope, but if you do, this binding will
@jarrodhroberson
jarrodhroberson / TrustTheGarbageCollector.java
Created December 10, 2013 07:11
Trust the Garbage Collector
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* See what it looks like in JVisualVM
* https://www.evernote.com/shard/s17/sh/430c9fd1-203a-45da-9194-b7cb20dbdf0f/4f67d91157f68db32e43badd9d806f1c/deep/0/Java-VisualVM.png
*/
public class TrustTheGarbageCollector
{
// 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