Skip to content

Instantly share code, notes, and snippets.

@gtrak
gtrak / EDN.txt
Last active April 9, 2018 06:59
EDN Resources
Obligatory Philosophical Rich Hickey talk about systems-level IPC and data formats
http://www.youtube.com/watch?v=ROor6_NGIWU
* EDN
EDN Spec and Rationale:
https://github.com/edn-format/edn
(ns playingwithmacros.core
(:require [clojure.java.browse :refer [browse-url]]
[clojure.pprint :as pp]
[clojure.core.strint :as strint]))
(defmacro my-simple-macro
"A docstring"
[first-arg second-arg & varargs]
"A return value of some kind")
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
(require 'auto-complete)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/dict")
(require 'auto-complete-config)
(ac-config-default)
@gtrak
gtrak / gist:6514209
Last active December 22, 2015 18:39
a = ["first", "second", "third", "fourth"]
puts "#{a}"
puts a[0]
puts a[3]
b = {"key1" => "value1",
"key2" => "value2"}
require 'mechanize'
def google_search(query_text)
agent=Mechanize.new
goog = agent.get "http://www.google.com"
search = goog.form_with(:action => "/search")
search.field_with(:name => 'q').value = query_text
results = search.submit
return results
end
@gtrak
gtrak / gist:6346408
Last active December 21, 2015 18:19
Clojure.test hacks.
(defmacro rcf
"Reports from the calling stack frame, useful for utility
assertion functions to workaround clojure.test's reporting of file-and-line info."
[& expr]
`(let [reports# (atom [])
out# (with-redefs [clojure.test/do-report (fn [m#] (swap! reports# conj m#))]
~@expr)
final# @reports#]
(doseq [m# final#]
(clojure.test/do-report m#))))
<btn icon="icon-step-backward">Replay</btn>
angular.module('myApp', []).directive('btn', function() {
return {
scope: { icon: '@' },
template: '<button class="btn span4"><i class="{{icon}}"></i>{{extra}}</button>',
restrict: 'E'
}
Error: Invalid isolate scope definition for directive btn: <i class=@icon></i>
JS:
angular.module('myApp', []).directive('btn', function() {
return {
scope: { inner: '<i class=@icon></i>' },
template: '<button class="btn span4">{{inner}}</button>',
restrict: 'E',
replace: true,
transclude: true
@gtrak
gtrak / pre.clj
Last active December 20, 2015 19:08
user> (clojure.pprint/pprint (macroexpand-all '(defn constrained-fn [f x]
{:pre [(pos? x)]
:post [(= % (* 2 x))]}
(f x))))
(def
constrained-fn
(fn*
([f x]
(if
(pos? x)
; nREPL 0.1.7
user> (defmacro my-macro [name params] `(defn ~name ~params (prn 1)))
#'user/my-macro
user> (my-macro a [b c d])
#'user/a
user> (a)
ArityException Wrong number of args (0) passed to: user$a clojure.lang.AFn.throwArity (AFn.java:437)
user> (a 1 2 3)
1
nil