Skip to content

Instantly share code, notes, and snippets.

View combine_requests.js
var requestPromise;
function getCurrentState() {
if (requestPromise) return requestPromise;
requestPromise = ajaxRequestReturningPromise('GET', '/state.json');
reqrequestPromise.then(function() { requestPromise = null });
return requestPromise;
}
promise1 = getCurrentState()
View partition.hs
-- | The 'partition' function splits a list into sublists of length n.
partition :: Int -> [a] -> [[a]]
partition n xs = unfoldr step xs
where step :: [a] -> Maybe ([a], [a])
step [] = Nothing
step ys = Just (take n ys, drop n ys)
View gist:167422
// If you return a value from the `initialize()` method, that value
// is returned when you instantiate the class using `new`.
// Here, we use this to make `singleton` a class that generates
// new classes. The singleton instance is protected by a closure.
JS.singleton = new JS.Class({
initialize: function(name, parent, methods) {
var instance = null;
return new JS.Class(name, parent, {