Skip to content

Instantly share code, notes, and snippets.

View claj's full-sized avatar

Linus Ericsson claj

  • Sweden
  • 22:24 (UTC +02:00)
View GitHub Profile
(import 'org.apache.commons.mail.SimpleEmail)
(doto (SimpleEmail.)
(.setHostName "smtp.gmail.com")
(.setSslSmtpPort "465")
(.setSSL true)
(.addTo "you@gmail.com")
(.setFrom "you@gmail.com" "Lucky Clojurian")
(.setSubject "Hello from clojure")
(.setMsg "Wasn't that easy?")
(.setAuthentication "you@gmail.com" "yourpassword")
@alandipert
alandipert / midi.clj
Created March 31, 2010 12:37
Play music with Clojure and javax.sound.midi
(import '(javax.sound.midi MidiSystem Synthesizer))
(defn play-note [synth channel note-map]
(let [{:keys [note velocity duration]
:or {note 60
velocity 127
duration 1000}} note-map]
(. channel noteOn note velocity)
(Thread/sleep duration)
(. channel noteOff note)))
@djpowell
djpowell / finger_tree_stats.clj
Created November 11, 2010 14:53
fingertree stats
(ns finger-tree-stats
(:use [clojure.data.finger-tree]))
(defrecord stats [^double number ^double mean ^double variance])
(def null-stats (stats. 0 0 Double/NaN))
(defn make-stats
[^double x]
(stats. 1 x 0))
@ithayer
ithayer / create-heroku
Created July 4, 2011 19:20
Clojure on Heroku with Noir and Mongo Demo
# Commands to initialize a simple heroku noir app. You can cut and paste them together.
# Install latest version of noir. If an older version is installed, remove it first.
lein plugin install lein-noir "1.1.0-SNAPSHOT"
# Create new noir project.
lein noir new noir-mongo-heroku
cd noir-mongo-heroku
# Create instructions for heroku.
echo 'web: lein run' > Procfile
# Create git repository.
@ibdknox
ibdknox / alephNoir.clj
Created October 2, 2011 19:53
aleph and noir
(require '[noir.server :as server])
(use 'noir.core 'aleph.http 'lamina.core)
(defn async-response [response-channel request]
(enqueue response-channel
{:status 200
:headers {"content-type" "text/plain"}
:body "async response"}))
(defpage "/" [] "hey from Noir!")
@mrh0057
mrh0057 / browser-repl.bat
Created October 24, 2011 22:03
ClojureScript Inferior Lisp Mode Windows
@echo off
setLocal EnableDelayedExpansion
if "%CLOJURESCRIPT_HOME%" == "" set CLOJURESCRIPT_HOME=%~dp0..\
set CLASSPATH=%CLOJURESCRIPT_HOME%\src\clj;%CLOJURESCRIPT_HOME%\src\cljs;%CD%\src\cljs;%CD%\src\clj;%CD%\test\cljs;%CD%\test\clj"
for /R "%CLOJURESCRIPT_HOME%\lib" %%a in (*.jar) do (
set CLASSPATH=!CLASSPATH!;%%a
)
for /R "%CD%\lib" %%a in (*.jar) do (
@hiredman
hiredman / core.clj
Created October 25, 2011 22:56
srepl.clj
(ns srepl.core
(:use [clojure.main :only [repl]]
[clojure.pprint :only [pprint with-pprint-dispatch code-dispatch]])
(:import (jline.console ConsoleReader)
(jline.console.completer Completer))
(:gen-class))
(defmulti super-dispatch class)
(defmethod super-dispatch :default [thing]
@daveray
daveray / seesaw-repl-tutorial.clj
Created December 7, 2011 04:55
Seesaw REPL Tutorial
; 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.
(defn vec->tree [calls]
(-> (reduce (fn [tree [op was-ret?]]
(if was-ret?
(-> tree
(z/append-child op)
(z/up))
(-> tree
(z/append-child [op])
(z/down)
(z/rightmost))))
@stuarthalloway
stuarthalloway / gist:2002582
Created March 8, 2012 18:39
Datomic extent query
;; Datomic example code
;;
;; The extent of entity ?x is all datoms that are about ?x.
;; Drop this into your rules.
;;
;; Demonstrates
;;
;; 1. recursive query (extent calls itself)
;; 2. disjunction (different extent bodies are ORed)
;; 3. component attributes (e.g. your arm is a component, your brother isn't)