Skip to content

Instantly share code, notes, and snippets.

View lildata's full-sized avatar

Programming is fun lildata

View GitHub Profile
object x {
// stream a sql query
def sql( str:String ):Stream[ResultSet] = withStatement { s =>
val rs = s executeQuery str
new Iterator[ResultSet] { def hasNext = rs.next ; def next = rs }.toStream
}
// loan a sql statement
@lildata
lildata / companionOf.scala
Last active August 29, 2015 14:21 — forked from piotrga/gist:5928581
Get companion object instance with new Scala reflection API
trait ReflectionSugars{
import scala.reflect.runtime.{universe => ru}
private lazy val universeMirror = ru.runtimeMirror(getClass.getClassLoader)
def companionOf[T](implicit tt: ru.TypeTag[T]) = {
val companionMirror = universeMirror.reflectModule(ru.typeOf[T].typeSymbol.companionSymbol.asModule)
companionMirror.instance
}
}
; A REPL-based, annotated Seesaw tutorial
; Please visit https://github.com/daveray/seesaw for more info
;
; This is a very basic intro to Seesaw, a Clojure UI toolkit. It covers
; Seesaw's basic features and philosophy, but only scratches the surface
; of what's available. It only assumes knowledge of Clojure. No Swing or
; Java experience is needed.
;
; This material was first presented in a talk at @CraftsmanGuild in
; Ann Arbor, MI.
@lildata
lildata / jgraph.clj
Last active August 29, 2015 14:23 — forked from weissjeffm/jgraph.clj
; nREPL 0.1.7-preview
user> (use 'seesaw.core)
nil
user> (def myframe (frame :title "Hello" :on-close :exit))
#'user/myframe
user> (import com.mxgraph.view.mxGraph)
com.mxgraph.view.mxGraph
user> (def mygraph (mxGraph.))
#'user/mygraph
user> (defn display [content]
(ns async-tut1.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [goog.dom :as dom]
[goog.events :as events]
[cljs.core.async :refer [<! put! chan]])
(:import [goog.net Jsonp]
[goog Uri]))
(def wiki-search-url
"http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=")
@lildata
lildata / mapdb.clj
Created October 8, 2015 09:17 — forked from hideshi/mapdb.clj
This is hash map database written in Clojure. See also: http://d.hatena.ne.jp/hideshi_o/20121123/1353698397
;mapdb.clj
(ns db.mapdb
(:use
[clojure.contrib.duck-streams :only (reader)]
[clojure.java.io :only (writer)]
[clojure.string :only (split)]
[clojure.contrib.server-socket :only (create-server close-server)]))
(def database-file "/Users/hideshi/Dev/Clojure/db/dbfile")
@lildata
lildata / busy-cursor.clj
Created October 26, 2015 21:48 — forked from daveray/busy-cursor.clj
Clojure/Seesaw busy cursor example
(ns busy-cursor.core
(:use seesaw.core))
(defn long-running-task
[]
(Thread/sleep 5000)
"The result")
(defn run-task-with-busy-cursor
[c]
@lildata
lildata / table-test.clj
Created October 26, 2015 21:48 — forked from daveray/table-test.clj
Highlighting table rows with Seesaw
(ns table-test.core
(:use [seesaw core table swingx]))
; A predicate that decides whether a row should be highlighted
; adapter is an instance of JXTable.TableAdapter
; http://projects.joshy.org/projects/painterreview/swingx/org/jdesktop/swingx/JXTable.TableAdapter.html
(defn hl-predicate [renderer adapter]
; Highligh all rows where :age is over thirty
(> (.getValueAt adapter (.row adapter) 0) 30))
@lildata
lildata / gist:ae9dbe13b95dd228b580
Created November 11, 2015 18:17 — forked from daveray/gist:1055523
Async Workflows in Seesaw
(ns seesaw.async
(:use [seesaw core]))
; see http://dotnetslackers.com/articles/net/Programming-user-interfaces-using-f-sharp-workflows.aspx#1478
(defmacro async
"Macro that executes an async call (the first form), ignores its result, and the
executes the body normally."
[async-call & body]
`(~@(apply list (first async-call) `(fn [& args#] ~@body) (rest async-call))))
@lildata
lildata / gist:c318a44b18d7d6de24a9
Created January 31, 2016 16:10 — forked from bayan/gist:3382884
Clojure DSL to generate static HTML
;; Generating static HTML using Clojure macros
;; It is possible to write a DSL in Clojure that generates HTML markup without the need to write a separate parser and compiler (e.g. HAML).
;; Our aim here would be to write code that converts the following Clojure code into the HTML below it
;; (html
;; (head)
;; (body
;; (h1 "An example")