Skip to content

Instantly share code, notes, and snippets.

@syou6162
Created October 7, 2013 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syou6162/6860778 to your computer and use it in GitHub Desktop.
Save syou6162/6860778 to your computer and use it in GitHub Desktop.
#_(defdeps
[[org.clojure/clojure "1.5.1"]
[info.yasuhisay/clj-utils "0.1.1"]
[org.clojure/tools.cli "0.2.1"]])
(ns info.yasuhisay.dep-util
(:use [clojure.string :only (split)])
(:use [clj-utils.random :only (shuffle-with-random)])
(:require [clojure.tools.cli :as cli]))
(defn- get-cli-opts [args]
(cli/cli args
["-h" "--help" "Show help" :default false :flag true]
["--filename" "Filename to be read"]
["--k" "Number to output sentences" :default 10 :parse-fn #(Integer. %)]))
(let [[options rest-args banner] (get-cli-opts *command-line-args*)]
(when (:help options)
(println banner)
(System/exit 0))
(let [results (->> (split (slurp (:filename options)) #"\n\n")
(shuffle-with-random)
(take (:k options)))]
(doseq [sent results]
(println (str sent "\n")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment