Skip to content

Instantly share code, notes, and snippets.

View r-moeritz's full-sized avatar

Ralph r-moeritz

  • QLD, Australia
  • 19:00 (UTC +10:00)
View GitHub Profile
@r-moeritz
r-moeritz / hello.clj
Created June 16, 2011 19:09
hello jwt in clojure : hello.clj
(ns jwt-examples.hello)
(defmacro create-listener [args & body]
(let [argsnum (if (< 0 (count args)) (count args) "") ]
`(proxy [ ~(symbol (str "Signal" argsnum "$Listener")) ] [] (trigger ~args ~@body))))
(import [eu.webtoolkit.jwt WObject Signal WApplication WBreak WtServlet
WEnvironment WLineEdit WPushButton WText Signal$Listener Signal1
EventSignal WWidget Side]
[java.util EnumSet])
@r-moeritz
r-moeritz / core.clj
Created June 16, 2011 19:07
hello jwt in clojure : core.clj
(ns jwt-examples.core
(:use [jetty-wrapper.core :only [run-server]])
(:use [jwt-examples.hello :only [make-servlet]]))
(defn -main []
(run-server {:port 4000} "/*" (make-servlet)))
@r-moeritz
r-moeritz / hello-jwt.java
Created June 16, 2011 19:04
hello jwt in java
/*
* Copyright (C) 2009 Emweb bvba, Leuven, Belgium.
*
* See the LICENSE file for terms of use.
*/
package eu.webtoolkit.jwt.examples.hello;
import eu.webtoolkit.jwt.Side;
import eu.webtoolkit.jwt.Signal;
import eu.webtoolkit.jwt.WApplication;
@r-moeritz
r-moeritz / game.lisp
Created June 16, 2011 18:08
game related functions
(defun game-from-name (name)
(clsql:locally-enable-sql-reader-syntax)
(car (clsql:select 'game
:where [= [slot-value 'game 'name] name])))
(defun games ()
(sort (clsql:select 'game) #'> :key #'(lambda (g) (apply #'game-votes g))))
(defun add-game (name)
(unless (game-stored? name)
@r-moeritz
r-moeritz / connect.lisp
Created June 16, 2011 18:07
connect to db
;; Turn off caching of select queries
(setf clsql:*default-caching* nil)
;; Connection parameters
(defvar *database-type* :odbc)
(defvar *database-name* "RetroGames")
(defvar *database-user* "sa")
(defvar *database-server* "localhost")
(defvar *database-password* "password")
@r-moeritz
r-moeritz / game.lisp
Created June 16, 2011 18:06
game class
(clsql:def-view-class game ()
((id
:db-kind :key
:db-type "int identity(1,1)")
(name
:accessor game-name
:db-constraints (:unique :not-null)
:db-type "nvarchar(50)"
:initarg :name)
(votes
@r-moeritz
r-moeritz / new-game.lisp
Created June 16, 2011 18:05
new-game function
(define-url-fn (new-game)
(standard-page (:title "Add a new game")
(:script :type "text/javascript"
(str (ps
(defun validate ()
(when (= (@ ((@ document get-element-by-id) "name") value) "")
(alert "Please enter a name.")
(return false))))))
(:h1 "Add a new game to the chart")
(:form :action "/game-added.htm" :method "post"