Skip to content

Instantly share code, notes, and snippets.

@tantaman
tantaman / gist:1285639
Created October 13, 2011 21:49
exercies: binary search - clojure
(defn bsrch [needle haystack]
(loop [low (int 0) high (count haystack) mid (quot (count haystack) 2)]
(if (= (haystack mid) needle)
mid
(if (= high low)
-1
(if (> needle (haystack mid))
(recur (int (inc mid)) high (quot (+ mid high) 2))
(recur low (int (dec mid)) (quot (+ low mid) 2))
)))
@tantaman
tantaman / Cakefile
Created January 22, 2012 14:48 — forked from mattmccray/Cakefile
Cakefile for compiling Coffee and LESS files, optionally compressing them with YUIC
###
Web Toolkit v0.4 (by M@ McCray)
http://gist.github.com/515035
NOTE: This is meant to be used as a Cakefile (Coffee's RAKE equivalent).
###
puts = require("util").puts
<!doctype html>
<html>
<head>
<title>Three.js : WebGL Canvas Texture Text Example</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
@tantaman
tantaman / gist:2762813
Created May 21, 2012 15:04
Its simple to make backbonejs (and other items) amd modules when you can make assumptions about your execution environment. Assumptions here: jQuer, define, _ are in the global scope. No need for commonjs support.
// Backbone.js 0.9.0
// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
define(function() {
var obj = {};
obj._ = window._;
obj.jQuery = window.jQuery;
(function(){
@tantaman
tantaman / example_usage.markdown
Created May 22, 2012 20:27 — forked from lwe/example_usage.markdown
iPhoto-like preview batches (Video in action: http://www.vimeo.com/6639381)

in action: http://www.vimeo.com/6639381

javascript:

var pp = "/images/test/images_";
var images_p1 = [ pp + '1.jpg', pp + '2.jpg', pp + '3.jpg', pp + '4.jpg', pp + '5.jpg' ];
var images_p2 = [ pp + '6.jpg', pp + '7.jpg', pp + '8.jpg', pp + '9.jpg', pp + '10.jpg' ];

$('.preview').slideview(function(e) { return e.id == "p1" ? images_p1 : images_p2; }, { size: 75 });
@tantaman
tantaman / webserver.js
Created May 25, 2012 22:03
simple static file serv example
var Express = require("express");
var webServ = Express.createServer();
webServ.use(Express.static('../workspace'));
webServ.listen(8080);
console.log("Web server listening on port: 8080");
@tantaman
tantaman / readme.md
Created June 21, 2012 16:21
Event to be notified whenever an element is removed from the DOM via jQuery
@tantaman
tantaman / Comparison.md
Created July 9, 2012 01:13
Impact on memory under different methods of object construction

Using Chrome's Heap Dump to compare the memory consumption of the two approaches:

index-lean.html: (11% retained size)

Lean

index-hog.html (52% retained size)

Hog

@tantaman
tantaman / Main.java
Created July 27, 2012 00:40
Embedding CometD in an existing JVM
package com.tantaman.cometd.embed.example;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.cometd.bayeux.server.BayeuxServer;
import org.cometd.bayeux.server.ConfigurableServerChannel;
@tantaman
tantaman / example.js
Created September 11, 2012 00:58
Replace and still call an existing method on some Javascript object
var someObject = {
method: function() {
console.log("Original method");
}
}
var oldMethod = someObject.method;
someObject.method = function() {
oldMethod.apply(this, arguments);