Skip to content

Instantly share code, notes, and snippets.

@yanatan16
yanatan16 / generator_wrapper.js
Last active September 23, 2018 22:08
Wrapping a callback-based function into an ES6 Generator (requires node 0.11+)
var q = require('q')
function generatorify(fn, context) {
return function() {
var deferred = q.defer(),
callback = makeCallback(deferred),
args = Array.prototype.slice.call(arguments).concat(callback);
fn.apply(context, args);
return deferred.promise;
};
@christopherperry
christopherperry / ExpiringLruCache.java
Last active February 16, 2024 15:12
LruCache for Android with expiring keys. Instead of modifying LruCache directly I used delegation to get around final keyword usage and a dirty hack to override everything else.
import android.os.SystemClock;
import android.support.v4.util.LruCache;
import java.util.HashMap;
import java.util.Map;
/**
* An Lru Cache that allows entries to expire after
* a period of time. Items are evicted based on a combination
* of time, and usage. Adding items past the {@code maxSize}