Skip to content

Instantly share code, notes, and snippets.

(declarepath ConawWalker)
(providepath ConawWalker
(stay-then-continue
(cond-path map? MAP-VALS coll? ALL)
ConawWalker))
(transform [ALL MAP-VALS ConawWalker (pred :tempid)] :tempid data)
;; given this data structure
(def data
[{:type :root,
:content
[{:line-type :comment, :text "#+title: Sample Org File"}
{:line-type :comment, :text "#+author: Seylerius"}
{:line-type :blank, :text ""}
{:line-type :paragraph,
:text "This is an attempt to test Org-Mode processing."}
{:line-type :blank, :text ""}]}
@nathanmarz
nathanmarz / specter.zip.clj
Created February 16, 2016 16:36
Integrate zippers with Specter
(ns specter.zip
(:use [com.rpl.specter.macros :only [defpath]]
[com.rpl specter])
(:require [clojure [zip :as zip]]))
(def VECTOR-ZIP (view zip/vector-zip))
(def NEXT (view zip/next))
(def RIGHT (view zip/right))
(def LEFT (view zip/left))
(def DOWN (view zip/down))
@nathanmarz
nathanmarz / demo.clj
Created January 11, 2016 18:53
Recursive navigation with Specter
(use 'com.rpl.specter)
(use 'com.rpl.specter.macros)
(defprotocolpath TreeWalker [])
(extend-protocolpath TreeWalker
Object nil
clojure.lang.PersistentVector [ALL TreeWalker])
(select [TreeWalker number?] [:a 1 [2 [[[3]]] :e] [4 5 [6 7]]])
(def MOVIES
[{:name "Lethal Weapon", :director "Paul Verhoeven", :rating 7.6}
{:name "RoboCop", :director "George P. Cosmatos", :rating 7.5}
{:name "Bad Movie", :director "James Cameron", :rating 4.2}
{:name "Great Movie", :director "James Cameron", :rating 10.0}
{:name "Lethal Weapon 3", :director "Ted Kotcheff", :rating 6.6}
{:name "Rambo III", :director "John McTiernan", :rating 5.4}
{:name "The Terminator", :director "Peter MacDonald", :rating 8.1}
{:name "Titanic", :director "James Cameron", :rating 8.3}
isolation.scheduler.machines:
"my-topology": 8
"tiny-topology": 1
"some-other-topology": 3
@nathanmarz
nathanmarz / gist:3234661
Created August 2, 2012 07:03
Grouped aggregation example
stream.groupBy(new Fields("val1"))
.aggregate(new Fields("val2"), new Sum(), new Fields("sum"))
@nathanmarz
nathanmarz / gist:3234656
Created August 2, 2012 07:03
Aggregate example
stream.aggregate(new Fields("val2"), new Sum(), new Fields("sum"))
@nathanmarz
nathanmarz / gist:3234653
Created August 2, 2012 07:02
Function example
stream.each(new Fields("x", "y"), new AddAndMultiply(), new Fields("added", "multiplied"));
@nathanmarz
nathanmarz / gist:3234652
Created August 2, 2012 07:02
Add and multiply function
public class AddAndMultiply extends BaseFunction {
public void execute(TridentTuple tuple, TridentCollector collector) {
int i1 = tuple.getInteger(0);
int i2 = tuple.getInteger(1);
collector.emit(new Values(i1 + i2, i1 * i2));
}
}