Skip to content

Instantly share code, notes, and snippets.

@manythumbed
manythumbed / ZmqLibrary.java
Created October 30, 2010 14:58
JNA wrapper for ZMQ
package blog.zeromq;
import com.sun.jna.Library;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.LongByReference;
public interface ZmqLibrary extends Library {
void zmq_version(int[] major, int[] minor, int[] patch);
@manythumbed
manythumbed / test-bare-bones-zmq.java
Created October 30, 2010 14:48
Unit test for barebones JNA ZMQ code
public void testVersion() {
assertNotNull(zmqLibrary);
int[] major = new int[1];
int[] minor = new int[1];
int[] patch = new int[1];
zmqLibrary.zmq_version(major, minor, patch);
assertEquals(2, major[0]);
assertEquals(0, minor[0]);
assertEquals(8, patch[0]);
}
@manythumbed
manythumbed / zmq-bare-bones.java
Created October 30, 2010 14:10
Minimal JNA ZMQ code
import com.sun.jna.Library;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.LongByReference;
public interface ZmqLibrary extends Library {
void zmq_version(int[] major, int[] minor, int[] patch);
}
user=> (table ["A" "B" "C"] ["1" "2" "3"] [["X" "Y" "Z"]])
({:tag :table, :attrs nil, :content ({:tag :thead, :attrs nil, :content ("\n\t\t" {:tag :tr, :attrs {:class "main"}, :content ({:tag :th, :attrs {:class "TH"}, :content ("A")} {:tag :th, :attrs {:class "TH"}, :content ("B")} {:tag :th, :attrs {:class "TH"}, :content ("C")})} "\n\t\t" {:tag :tr, :attrs nil, :content ({:tag :th, :attrs {:class "TH"}, :content ("1")} {:tag :th, :attrs {:class "TH"}, :content ("2")} {:tag :th, :attrs {:class "TH"}, :content ("3")})} "\n\t")} {:tag :tbody, :attrs nil, :content ({:tag :tr, :attrs {:class "even"}, :content ({:tag :td, :attrs {:class "first"}, :content ("X")} {:tag :td, :attrs nil, :content ("Y")} {:tag :td, :attrs nil, :content ("Z")})})} {:tag :tfoot, :attrs nil, :content ("\n\t\t" {:tag :tr, :attrs {:class "main"}, :content ({:tag :th, :attrs nil, :content ("A")} {:tag :th, :attrs nil, :content ("B")} {:tag :th, :attrs nil, :content ("C")})} "\n\t\t" {:tag :tr, :attrs nil, :content ({:tag :th, :attrs nil,
(ns blog.table
(:use [net.cgrand.enlive-html]))
(def table-template (html-resource "templates/table.html"))
(defn t [selector]
(select (html-resource table-template) selector))
(defsnippet header-cell table-template
[[:thead] [:tr first-child] [:th first-child]]
(defsnippet header-row table-template
[[:thead]]
[primary secondary]
[:tr] (content (map #(header-cell %) secondary))
[:tr.main] (content (map #(header-cell %) primary)))
user=> (header-row ["A" "B" "C"] ["1" "2" "3"])
({:tag :thead, :attrs nil, :content ("\n\t\t" {:tag :tr, :attrs {:class "main"}, :content ({:tag :th, :attrs {:class "TH"}, :content ("A")} {:tag :th, :attrs {:class "TH"}, :content ("B")} {:tag :th, :attrs {:class "TH"}, :content ("C")})} "\n\t\t" {:tag :tr, :attrs nil, :content ({:tag :th, :attrs {:class "TH"}, :content ("1")} {:tag :th, :attrs {:class "TH"}, :content ("2")} {:tag :th, :attrs {:class "TH"}, :content ("3")})} "\n\t")})
user=> (use 'blog.table :reload-all)
nil
(header-cell "X")
user=> ({:tag :th, :attrs {:class "TH"}, :content ("X")})
(def table-template (html-resource "templates/table.html"))
(defsnippet header-cell table-template
[[:thead] [:tr first-child] [:th first-child]]
[value]
[:th] (content value))
$ lein repl
"REPL started; server listening on localhost:4633."
user=> (use 'blog.table :reload-all)
<html>
<head><title>Table Template</title></head>
<body>
<table>
<thead>
<tr class="main"><th>H1</th><th>H2</th></tr>
<tr><th>HH1</th><th>HH2</th></tr>
</thead>
<tbody>
<tr class="odd"><td class="first">A</td><td>B</td><td>C</td>