Skip to content

Instantly share code, notes, and snippets.

(ns hiredman.beans)
(defn -it [& _]
[[] (ref {})])
(defn setter [tis nam tat]
(dosync
(commute (.state tis)
assoc nam tat)))
(ns prolog
(:use clojure.contrib.def
clojure.contrib.str-utils
clojure.set
clojure.test))
(defvar facts (ref {:forward {} :back {}}) "Hashmap of clauses (forward and back references)")
(defn passmap
"Applies f to items only when (pred item) returns true."
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(set! *warn-on-reflection* true)
package mypkg;
public class Ugly {
public Ugly(){}
public String foo(boolean i) { return "bool: " + i; }
public String foo(Object o) { return "obj: " + o; }
}
user> (def u (foo.TestInterop2.))
#'user/u
(use '[clojure.contrib.macro-utils :only [macrolet]])
(defmacro defplugin [& body]
(let [g (gensym)]
(macrolet [(defcommand [docs words cmdkey & method-stuff]
`(do (dosync (doseq [word# ~words]
(assoc ~g word# {:cmd ~cmdkey :doc ~docs})))
(defmethod respond ~cmdkey ~@method-stuff)))]
`(let [~g (ref [])]
~@body
(ns state.clj)
(comment
(def f
(statefully
x <- (*read*)
(*write* 42)
y <- (*read*)
(*update* str " was frobnicated!")
(set! *warn-on-reflection* true)
(import (org.mozilla.javascript Context NativeObject NativeArray))
(defn js-eval [string]
(let [cx (Context/enter)
scope (.initStandardObjects cx)]
(.evaluateString cx scope string "<js-eval>" 1 nil)))
(defprotocol Clojurify (clojurify [obj]))
(ns clj-swing.core)
(import '(javax.swing JFrame JLabel JTextField JButton JComboBox JPanel Timer)
'(java.awt.event ActionListener)
'(java.awt GridBagLayout GridLayout GridBagConstraints))
(require '[clojure.contrib.java-utils :as java])
(defmacro combo-box [[& items] & actions]
`(doto (JComboBox.)
(defun get-window-by-class (class)
"Return a window with the given class."
(first (filter-windows #'(lambda (w) (equal (window-class w) class)))))
(defun gimme (cmdline class)
"If a window matching CLASS is found switch to it, else launch cmdline."
(if class
(let ((wnd (get-window-by-class class)))
(if wnd
(display-window wnd)
(def file-info-extractors
{:filename #(.getName #^java.io.File %)
:path #(str (.toURI #^java.io.File %))
:modified #(.lastModified #^java.io.File %)})
(map #(reduce (fn [m [k e]]
(assoc m k (e %)))
{}
file-info-extractors)
(.listFiles (java.io.File. ".")))