Skip to content

Instantly share code, notes, and snippets.

@Folcon
Folcon / clipboard-utils.clj
Created August 24, 2011 11:50
Just a quick clipboard slip/slurp I put together because I didn't find anything similar, don't know if it's useful for anyone but found it invaluable when getting large strings being returned from the repl and sticking the result in an editor for more car
(defn get-clipboard []
(.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit)))
(defn slurp-clipboard []
(try
(.getTransferData (.getContents (get-clipboard) nil) (java.awt.datatransfer.DataFlavor/stringFlavor))
(catch java.lang.NullPointerException e nil)))
(defn spit-clipboard [text]
(.setContents (get-clipboard) (java.awt.datatransfer.StringSelection. text) nil))
@michiakig
michiakig / three.cljs
Created August 19, 2011 20:53
three.js demo in ClojureScript
(ns three.demo)
(def camera (THREE.Camera. 75 (/ window/innerWidth
window/innerHeight) 1 10000))
(set! (.z (.position camera)) 1000)
(def scene (THREE.Scene.))
(def geometry (THREE.CubeGeometry. 200 200 200))
(def obj (js/Object.))
(set! (.color obj) 0xff0000)
(set! (.wireframe obj) true)
(def material (THREE.MeshBasicMaterial. obj))
@daveray
daveray / gist:1138754
Created August 11, 2011 01:59
Seesaw File Chooser
(use 'seesaw.core)
(use 'seesaw.chooser)
(def open-action
(action :name "Open" :key "menu O"
:handler
(fn [e]
(if-let [f (choose-file)]
(text! (select (to-root e) [:#my-text]) f)))))
@jolby
jolby / REPL_session.clj
Created August 6, 2011 23:31
Working load-externs function for closure.clj (Clojurescript)
cljs.closure> (load-externs {})
[#<JSSourceFile externs.zip//es3.js> #<JSSourceFile externs.zip//es5.js> #<JSSourceFile externs.zip//w3c_event.js> #<JSSourceFile externs.zip//w3c_event3.js> #<JSSourceFile externs.zip//gecko_event.js> #<JSSourceFile externs.zip//ie_event.js> #<JSSourceFile externs.zip//webkit_event.js> #<JSSourceFile externs.zip//w3c_dom1.js> #<JSSourceFile externs.zip//w3c_dom2.js> #<JSSourceFile externs.zip//w3c_dom3.js> #<JSSourceFile externs.zip//gecko_dom.js> #<JSSourceFile externs.zip//ie_dom.js> #<JSSourceFile externs.zip//webkit_dom.js> #<JSSourceFile externs.zip//w3c_css.js> #<JSSourceFile externs.zip//gecko_css.js> #<JSSourceFile externs.zip//ie_css.js> #<JSSourceFile externs.zip//webkit_css.js> #<JSSourceFile externs.zip//google.js> #<JSSourceFile externs.zip//deprecated.js> #<JSSourceFile externs.zip//fileapi.js> #<JSSourceFile externs.zip//flash.js> #<JSSourceFile externs.zip//gears_symbols.js> #<JSSourceFile externs.zip//gears_types.js> #<JSSourceFile externs.zip//gecko_xml.js> #
@fogus
fogus / compile-hello.sh
Created August 5, 2011 16:17
using an external lib in clojurescript
# from your project directory
cljsc src {:optimizations :advanced} > hello.js
open hello.html
# igrigorik { ~ } > rvm use jruby
# Using /Users/igrigorik/.rvm/gems/jruby-1.6.2
# igrigorik { ~ } > gem install mvn:org.clojure:clojure
# Successfully installed mvn:org.clojure:clojure-1.3.0.b.1-java
# 1 gem installed
require 'rubygems'
require 'java'
require 'maven/org.clojure/clojure'
@jolby
jolby / core.cljs
Created August 2, 2011 00:12
Clojurescript on Appcelerator Titanium
(ns tiexample.core)
(defn ^{:export dbg} dbg [s]
(js* "Titanium.API.debug(~{s})"))
;;stolen from another gist I saw
(defn make-js-map
"makes a javascript map from a clojure one"
[cljmap]
(let [out (js-obj)]
@fehrenbach
fehrenbach / index.html
Created July 25, 2011 19:17
ClojureScript and Sencha Touch
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello World</title>
<script src="lib/touch/sencha-touch.js" type="text/javascript"></script>
<script type="text/javascript" src="out/goog/base.js"></script>
<script src="test.js" type="text/javascript"></script>
<script>goog.require('test');</script>
@ibdknox
ibdknox / cookies.clj
Created July 25, 2011 00:17
sessions and cookies
(require '[noir.cookies :as cookies])
(cookies/put! :user-id 2)
(cookies/get :user-id)
;; => 2
(cookies/get :username "anon")
;; => "anon"
;; you can also pass a map that has all the cookie's attributes
(defpartial error-item [[first-error]]
[:p.error first-error])
(defpartial user-fields [{:keys [firstname lastname]}]
(vali/on-error :firstname error-item)
(label "firstname" "First name: ")
(text-field "firstname" firstname)
(vali/on-error :lastname error-item)
(label "lastname" "Last name: ")
(text-field "lastname" lastname))