Skip to content

Instantly share code, notes, and snippets.

@cldwalker
cldwalker / explore_datafy_nav.clj
Created August 11, 2020 06:03 — forked from sashton/explore_datafy_nav.clj
Clojure datafy/nav exploration
(ns explore-datafy-nav
"Sample code demonstrating naving around a random graph of data.
The graph very likely will have circular references, which is not a problem.
To see the results, execute the entire file.
Each step in the nav process will be printed out, as well as the initial db.
Subsequent executions will generate a new random db."
(:require [clojure.datafy :refer [datafy nav]]
[clojure.pprint]))
(defn generate-db
(defroutes chapter-routes
;; Example story-slug: 42-my-first-story
;; Example chapter-slug: 99-introduction
;; (util/parse-uid "42-my-first-story") -> 42
;; (util/parse-uid "99-introduction") -> 99
(GET "/chapters/:chapter-slug" [story-slug chapter-slug]
(let [story (some-> story-slug util/parse-uid db/find-story-by-uid)
chapter (some-> chapter-slug util/parse-uid db/find-chapter-by-uid)]
(and story chapter
(zizkov.views/show-chapter layout story chapter)))))
@cldwalker
cldwalker / run_example.rb
Created December 28, 2009 22:37 — forked from jeroenvandijk/run_example.rb
Example of using Boson to call subcommands in one file
# In example.rb
module Example
extend self
# This method does something
def command1(arg1, arg2, options = {})
end
# This method does something else
def command2(arg1, arg2, options = {})
@cldwalker
cldwalker / chars.rb
Created December 18, 2009 09:10 — forked from jeroenvandijk/chars.rb
Example of using Boson as an option parser
#!/usr/bin/env ruby
module Chars
extend self
def scale(args, options={})
scale = options[:scale]
chars = args.map { |x| Chars.char(x.to_i).map { |row| row.split("") } }
print_chars scale_vertically(scale_horizontally(chars, scale), scale)
end