Skip to content

Instantly share code, notes, and snippets.

View ddellacosta's full-sized avatar

Dave Della Costa ddellacosta

View GitHub Profile
;; in reply to http://www.sids.in/blog/2010/05/06/html-parsing-in-clojure-using-htmlcleaner/
(ns html-parser
(:require [net.cgrand.enlive-html :as e]))
(defn parse-page
"Given the HTML source of a web page, parses it and returns the :title
and the tag-stripped :content of the page. Does not do any encoding
detection, it is expected that this has already been done."
[page-src]
(-> page-src java.io.StringReader. e/html-resource
@sattvik
sattvik / HelloActivity.clj
Created April 11, 2012 18:57
HelloActivity.clj
(ns com.example.hello_clojure.HelloActivity
(:gen-class :main false
:extends android.app.Activity
:exposes-methods {onCreate superOnCreate})
(:import [com.example.hello_clojure R$layout]))
(defn -onCreate
[this bundle]
(doto this
(.superOnCreate bundle)
@alexander-yakushev
alexander-yakushev / clojure-trivial-dialer.clj
Last active October 6, 2015 00:57
A simple demostration of neko.ui toolkit for building Android UI in Clojure
(ns test.leindroid.sample.main
(:use [neko.activity :only [defactivity set-content-view!]]
[neko.threading :only [on-ui]]
[neko.ui :only [make-ui]])
(:import android.widget.EditText
android.net.Uri
android.content.Intent))
(declare ^EditText edit
^android.app.Activity a)
@richhickey
richhickey / thread.clj
Created October 13, 2012 17:43
new thread macros draft
(defmacro test->
"Takes an expression and a set of test/form pairs. Threads expr (via ->)
through each form for which the corresponding test expression (not threaded) is true."
[expr
& clauses]
(assert (even? (count clauses)))
(let [g (gensym)
pstep (fn [[test step]] `(if ~test (-> ~g ~step) ~g))]
`(let [~g ~expr
~@(interleave (repeat g) (map pstep (partition 2 clauses)))]
@cemerick
cemerick / browser_repl.clj
Last active December 14, 2015 13:08
browser-REPL refactoring
;; ## Changes from cljs.repl.browser
;;
;; * Multiple concurrent browser-REPLs can be safely used
;; * The browser-REPL's HTTP server is now always-on
;; * Each browser-REPL session supports a new top-level "entry" URL that
;; can be used to easily start the REPL in a browser or other JS runtime
;; (i.e. you don't need to have a separate webapp running to initiate the
;; browser-REPL connection)
;; * The entry (and REPL) URLs are available in slots on the browser-REPL's
;; environment, making it trivial to automate browser-REPL sessions
@cgmartin
cgmartin / gist:5880732
Last active September 15, 2018 01:22
WebSocket subprotocol and origin validation with HTTP Kit
(ns my.server
(:use org.httpkit.server
[clojure.string :only [split trim lower-case]])
(:import [org.httpkit.server AsyncChannel]))
(defn origin-match? [origin-re req]
(if-let [req-origin (get-in req [:headers "origin"])]
(re-matches origin-re req-origin)))
(defn debounce
([c ms] (debounce (chan) c ms))
([c' c ms]
(go
(loop [start nil loc (<! c)]
(if (nil? start)
(do
(>! c' loc)
(recur (js/Date.) nil))
(let [loc (<! c)]
(ns react-cljs.core
(:require React))
(declare render)
(defn handle-change [e]
(render {:text (.. e -target -value)}))
(defn render [{:keys [text]}]
(React/renderComponent
(ns react-cljs.core
(:require-macros [reactjs.macros :refer [pure]])
(:require React [reactjs.core :as r]))
(enable-console-print!)
(declare render-ui)
(defn render-counter [id state cb]
(pure state
@stuartsierra
stuartsierra / concat.org
Created April 4, 2014 20:44
Demonstrations of Clojure `concat` StackOverflow

Concat StackOverflow

Demonstrations of how clojure.core/concat can produce a StackOverflow.

Classic concat bomb

This is the most obvious case: A loop that builds up a sequence by concatenation.