Skip to content

Instantly share code, notes, and snippets.

View adamblank's full-sized avatar

Adam Blank adamblank

  • California, US
View GitHub Profile
@adamblank
adamblank / underscore.reverseTemplate.js
Last active December 27, 2015 12:48
_.reverseTemplate() attempts to reverse engineer the original object used to generate a rendered underscore.js template output by comparing the output string to the template string.
/* Extend the underscore global object with the following method:
*
* https://gist.github.com/adamblank/7328089
*
* reverseTemplate attempts to reverse engineer the original object used to generate
* the rendered output by comparing the output string to the underscore template string.
*
* Paramaters
* - renderedOutput - the string that was generated from the template
* - template - the template string used to generate the compiled underscore template (not the compiled template function.)
@adamblank
adamblank / cheese.json
Created December 6, 2013 20:40
JSON array of every type of cheese.
[
"Abbaye de Belloc",
"Abbaye du Mont des Cats",
"Abertam",
"Abondance",
"Ackawi",
"Acorn",
"Adelost",
"Airag",
"Airedale",
@adamblank
adamblank / underscore.compile.js
Last active December 30, 2015 19:39
Add a compile method to underscore, to accommodate for typeahead's expected API
_.compile = function(templ) {
var compiled = this.template(templ);
compiled.render = function(ctx) {
return this(ctx);
};
return compiled;
}
@adamblank
adamblank / webkit.scrollbar.css
Created December 10, 2013 19:36
webkit styled minimalist gray scrollbar
::-webkit-scrollbar{
width: 10px;
}
::-webkit-scrollbar-track-piece{
background-color: #FFF;
}
::-webkit-scrollbar-thumb{
background-color: #CBCBCB;
@adamblank
adamblank / jsonToTable.js
Created January 26, 2014 19:35
Generate generic HTML table from JSON
function generateTable(arr) {
var content = {},
headers = [],
longest = 0;
function setEmpies(content) {
for (var key in content) {
if (!content[key].affected) {
content[key].push('');
/*
* Boilerplate thread local singleton
*/
protected Singleton() {} //enforce singleton pattern with protected constructor
private static ThreadLocal<Singleton> instance = null; //the current thread instance
/** Get the singleton instance of this service
* If no instance exists for this thread, instantiate one
*
var stock_prices = [15,14,11,10,8,6,5,2,1];//[10,11,12,15,8,9,10,14,11];//[10, 9, 8, 10, 13, 11, 9, 10, 15];
var max_and_min = [];
var i = stock_prices.length - 1;
for (i; i >= 0; i--) {
if (max_and_min.length && (max_and_min[0].min == null || max_and_min[0].min > stock_prices[i])) {
max_and_min[0].min = stock_prices[i];
}
if (!max_and_min.length || max_and_min[0].max < stock_prices[i]) {
var arr = [1, 7, 3, 4];
var brute = function(arr) {
var i = 0;
var final_arr = [];
var temp_arr;
var j;
for (i; i < arr.length; i++) {
temp_arr = arr.slice();
temp_arr.splice(i, 1);
public class Node {
protected String data;
protected Node next;
public Node(final String data, final Node next) {
this.data = data;
this.next = next;
}
public Node getNext() {
import java.util.*;
public class MyApp {
protected List<Integer[]> meetings = new ArrayList<>();
public MyApp() {
meetings.add(new Integer[] { 3, 5});
meetings.add(new Integer[] { 0, 1});
meetings.add(new Integer[] { 4, 8});