Skip to content

Instantly share code, notes, and snippets.

@jaydonnell
jaydonnell / example.clj
Created June 23, 2011 19:54
scala, clojure comparison
(defn admin-only [handler]
(fn [request]
(when (:admin (:session request))
(handler request))))
(defroutes admin-routes
(GET "/some-admin-only-page" (admin-page))
(GET "/another-admin-only-page" (other-admin-page)))
@jaydonnell
jaydonnell / gist:1023359
Created June 13, 2011 18:21
jruby fuzzy autocomplete
#require "completor/version"
require 'rubygems'
require 'bundler'
require 'java'
Bundler.require(:default, :development)
require 'csv'
COMPLETOR_ROOT = File.expand_path(File.dirname(__FILE__))
Dir.glob(File.join(COMPLETOR_ROOT, '..', 'jars', '*.jar')).each { |jar| require jar }
public Number returnGreater(Number value1, Number value2) {
if (value1.doubleValue() > value2.doubleValue()) {
return value1;
} else {
return value2;
}
}
for (int i = 0; i < allBoxesFast.size(); i++) {
SimpleSprite sprite = allBoxesFast.get(i);
sprite.render(container, g);
}
// TRY THIS
for(SimpleSprite sprite: allBoxesFast) {
sprite.render(container, g);
}
@jaydonnell
jaydonnell / gist:1012693
Created June 7, 2011 17:27
json rest benchmark
Java + Jersey + Guice + Jackson
Concurrency Level: 10
Complete requests: 2000
Failed requests: 0
Requests per second: 2868.75 [#/sec] (mean)
Percentage of the requests served within a certain time (ms)
50% 3
66% 3
75% 4
80% 4
@jaydonnell
jaydonnell / gist:1011114
Created June 6, 2011 21:08
scalate, guice, and jersey
@Path("/")
class HomeResource {
@Path("test")
@Produces(Array("application/json"))
@GET
def test(): String = {
return "{'foo': 'bar'}"
}
}
@jaydonnell
jaydonnell / gist:997325
Created May 28, 2011 23:06 — forked from swannodette/gist:997140
type-inf.clj
(ns logic.y
(:refer-clojure :exclude [== reify inc])
(:use [clojure.core.logic minikanren prelude nonrel match]))
(defna findo [x l o]
([_ [[?y '- o] . ?r] _] (project [x ?y] (== (= x ?y) true)))
([_ [_ . ?c] _] (findo x ?c o)))
(defn typedo [c x t]
(conda
yakkstr.com:80 77.88.25.26 - - [13/May/2011:19:57:52 -0700] "GET /tags/1703-glenn-beck HTTP/1.1" 200 1953 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
yakkstr.com:80 119.63.196.80 - - [13/May/2011:19:58:11 -0700] "GET /tags/28-introduction-of-sorts HTTP/1.1" 200 1953 "-" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
yakkstr.com:80 67.195.113.242 - - [13/May/2011:19:58:19 -0700] "GET /tags/504-food HTTP/1.0" 200 4584 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"
yakkstr.com:80 66.249.67.242 - - [13/May/2011:19:59:58 -0700] "GET /posts/3240-Borders-bookstores-gives-executives-8300000-in-bonuses-after-it-lays-off-6000-workers-and-goes-into-chapter-11-bankruptcy- HTTP/1.1" 200 5011 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
yakkstr.com:80 77.88.25.26 - - [13/May/2011:20:00:02 -0700] "GET /posts/1535-Its-piling-up HTTP/1.1" 200 5625 "-" "Mozilla/5.0 (compatible; YandexBo
yakkstr.com:80 77.88.25.26 - - [13/May/2011:19:57:52 -0700] "GET /tags/1703-glenn-beck HTTP/1.1" 200 1953 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
yakkstr.com:80 119.63.196.80 - - [13/May/2011:19:58:11 -0700] "GET /tags/28-introduction-of-sorts HTTP/1.1" 200 1953 "-" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"
yakkstr.com:80 67.195.113.242 - - [13/May/2011:19:58:19 -0700] "GET /tags/504-food HTTP/1.0" 200 4584 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"
yakkstr.com:80 66.249.67.242 - - [13/May/2011:19:59:58 -0700] "GET /posts/3240-Borders-bookstores-gives-executives-8300000-in-bonuses-after-it-lays-off-6000-workers-and-goes-into-chapter-11-bankruptcy- HTTP/1.1" 200 5011 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
yakkstr.com:80 77.88.25.26 - - [13/May/2011:20:00:02 -0700] "GET /posts/1535-Its-piling-up HTTP/1.1" 200 5625 "-" "Mozilla/5.0 (compatible; YandexBo
public boolean exists (String className) {
try {
Class.forName (className);
return true;
}
catch (ClassNotFoundException exception) {
return false;
}
}