Skip to content

Instantly share code, notes, and snippets.

View lambder's full-sized avatar

Lambder lambder

View GitHub Profile
(ns hiredman.schedule
(:import (java.util.concurrent ScheduledThreadPoolExecutor TimeUnit)))
(def unit {:minutes TimeUnit/MINUTES :seconds TimeUnit/SECONDS :hours TimeUnit/HOURS})
(def tasks (ref {}))
(def #^{:doc "ScheduledThreadPoolExecutor for scheduling repeated/delayed tasks"}
task-runner (ScheduledThreadPoolExecutor. (+ 1 (.availableProcessors (Runtime/getRuntime)))))
(defn multi-split-with
"Returns a lazy collection of lists which elements ..."
[pred coll]
(let [[head tail] (split-with pred coll)
tail-without-seps (drop-while (complement pred) tail)]
(lazy-seq
(if (seq tail-without-seps)
(cons head (multi-split-with pred tail-without-seps))
(list head)))))
// usage:
// var double = function(a){Functional.map(a, function{return 2*a})};
// double([1,2,3]) -> [2,4,6]
// var even = function(a){Functional.map(a, function{return a%2 == 0})};
// even([1,2,3,4,5,6,7]) -> [2,4,6]
var Functional = {
var Functional = {
isFunction: function(obj) {
return toString.call(obj) === "[object Function]";
},
reduce: function(accumulator, object, callback) {
var name, i = 0,
length = object.length,
isObj = length === undefined || Functional.isFunction(object);
[
{"name":"flare.analytics.cluster.AgglomerativeCluster","size":3938,"imports":["flare.animate.Transitioner","flare.vis.data.DataList","flare.util.math.IMatrix","flare.analytics.cluster.MergeEdge","flare.analytics.cluster.HierarchicalCluster","flare.vis.data.Data"]},
{"name":"flare.analytics.cluster.CommunityStructure","size":3812,"imports":["flare.analytics.cluster.HierarchicalCluster","flare.animate.Transitioner","flare.vis.data.DataList","flare.analytics.cluster.MergeEdge","flare.util.math.IMatrix"]},
{"name":"flare.analytics.cluster.HierarchicalCluster","size":6714,"imports":["flare.vis.data.EdgeSprite","flare.vis.data.NodeSprite","flare.vis.data.DataList","flare.vis.data.Tree","flare.util.Arrays","flare.analytics.cluster.MergeEdge","flare.util.Sort","flare.vis.operator.Operator","flare.util.Property","flare.vis.data.Data"]},
{"name":"flare.analytics.cluster.MergeEdge","size":743,"imports":[]},
{"name":"flare.analytics.graph.BetweennessCentrality","size":3534,"imports":["flare.animate.Transitioner","flare
$(function() {
//run the accordion plugin, set height of sections to height of content
$("#accordion").accordion({ autoHeight: false });
});
;(function($) {
//write new sammy application
var app = new Sammy.Application(function() {
with(this) {
//corresponds to routes such as #/section/1
get('#/section/:section_id', function() { with(this) {
@lambder
lambder / validate_doc_update.js
Created November 5, 2010 14:05
validate_doc_update
function(newDoc, oldDoc, userCtx) {
if (newDoc._deleted === true) {
// allow deletes by 'cluster admins', 'system admins' and matching users
// without checking the other fields
if ((userCtx.roles.indexOf('_admin') !== -1) || (userCtx.roles.indexOf('system_admin') !== -1) || (userCtx.name == oldDoc.name)) {
return;
} else {
throw({forbidden: 'Only admins may delete other user docs. **************'});
}
@lambder
lambder / non_blocking_factorial.js
Created January 11, 2011 11:27
Example of how to utilize setTimeout and accumulation to have non blocking long lasting recurrent calculations
function _factorial(acc, n, callback){
if(n==0){
callback(acc);
}else{
var callback_wrapper = function(result){
callback(result);
};
setTimeout(function(){_factorial(acc * n, n-1, callback_wrapper)}, 10);
}
}
<!DOCTYPE html>
<!-- Helpful things to keep in your <head/>
// Brian Blakely, 360i
// http://twitter.com/brianblakely/
-->
<head>
<!-- According to Heather Champ, former community manager at flickr,
you should not allow search engines to index your "Contact Us"
@lambder
lambder / andand.clj
Created March 1, 2011 14:10
Clojure quivalent of ruby's andand. Threads the expr through the forms, short circuiting in case of falsey result
(defmacro &&>
"Clojure quivalent of ruby's andand. Threads the expr through the forms, short circuiting in case of falsey result.
Inserts x as the second item in the first form, making a list of it if it is not a
list already. If there are more forms, inserts the first form as the
second item in second form, etc.
example:
(let [o {:a 123}]
(assert (= 124 (&&> o :a (+ 1))))
(assert (= nil (&&> o :a (+ 1) :c :b)))
(assert (= false (&&> false :a (+ 1) :c :b)))