1. number23
  2. commons-lib

Commits

number23  committed c562d0e

change project groupId

  • Participants
  • Parent commits ee70e89
  • Branches master

Comments (0)

Files changed (14)

File README.md

View file
 
 Add this to your project.clj :dependencies list:
 
-    [de.no.number23/commons-lib "0.0.4"]
+    [org.clojars.number23/commons-lib "0.2.2"]
 
 and checkout API documentation for details.
 
 ## Usage
 
 ``` clojure
-(use 'de.no.number23.commons-lib.io)
+(use 'org.clojars.number23.commons-lib.io)
 (def host (prompt-re "Please choose host (dev or prd)" #"dev|prd"))
 (def user (prompt-read "User"))
 ```

File project.clj

View file
-(defproject org.clojars.number23_cn/commons-lib "0.2.1"
+(defproject org.clojars.number23/commons-lib "0.2.2"
   :description "my clojure commons lib"
   :url "https://github.com/number23/commons-lib"
   :license {:name "Eclipse Public License - v 1.0"
             [lein-pprint "1.1.1"]]
 
   :warn-on-reflection true
-  :main de.no.number23.commons-lib.core
+  :main org.clojars.number23.commons-lib.core
   :aot :all
   :jvm-opts ["-Xmx1g"])

File src/org/clojars/number23/commons_lib/core.clj

View file
+(ns org.clojars.number23.commons-lib.core)
+
+(defn -main
+  "Hello Clojure, I Love U"
+  [& args]
+  (println "Hello Clojure"))

File src/org/clojars/number23/commons_lib/date.clj

View file
+(ns org.clojars.number23.commons-lib.date
+  (:import (java.util Calendar Date)))
+
+(defn get-Monday
+  "as name, return Monday"
+  [^Date d]
+  (let [cal (Calendar/getInstance)]
+    (.setTime cal d)
+    (let [dt (- (.get cal Calendar/DAY_OF_WEEK) 2)]
+      (.add cal Calendar/DATE (- dt))
+      (.getTime cal))))
+
+(defn cdts
+  "return current datetime string: yyyy-MM-dd HH:mm:ss"
+  []
+  (format "%1$tF %1$tT" (Date.)))

File src/org/clojars/number23/commons_lib/io.clj

View file
+(ns org.clojars.number23.commons-lib.io
+  (:require [clojure.java.io :as io]))
+
+(defn ^String prompt-read
+  "return String
+  from http://thinkrelevance.com/blog/2008/09/16/pcl-clojure-chapter-3.html"
+  [^String prompt]
+  (print (format "%s: " prompt))
+  (flush)
+  (read-line))
+
+(defn y-or-n
+  "return true if input y, n return false
+  from http://thinkrelevance.com/blog/2008/09/16/pcl-clojure-chapter-3.html"
+  [^String prompt]
+  (= "y"
+     (loop []
+       (or
+        (re-matches #"[yn]" (.toLowerCase (prompt-read prompt)))
+        (recur)))))
+
+(defn prompt-re
+  "re is Pattern, return the match"
+  [^String prompt ^java.util.regex.Pattern re]
+  (loop []
+    (or
+     (re-matches re (prompt-read prompt))
+     (recur))))
+
+(defn processing-file
+  "process a file by line with func"
+  [file func]
+  (with-open [rdr (io/reader file)]
+    (doseq [line (line-seq rdr)]
+      (func line))))
+
+(defmacro with-err-str
+  "Evaluates exprs in a context in which *err* is bound to a fresh
+  StringWriter.  Returns the string created by any nested printing
+  calls."
+  [& body]
+  `(let [s# (new java.io.StringWriter)]
+     (binding [*err* s#]
+       ~@body
+       (str s#))))

File src/org/clojars/number23/commons_lib/mail.clj

View file
+(ns org.clojars.number23.commons-lib.mail)
+
+(defn sendmail
+  "simple sendmail function by smtp protocol,
+  base on javax.mail, keys:
+  host, port, user, password,
+  auth, ssl,
+  debug,
+  from, to, cc, bcc,
+  subject, text, content
+
+  if debug is true, debug output, send to bcc only,
+  from is String, to, cc, and bcc is vec,
+  if text is setup, send text/plan msg
+  content is javax.mail.Multipart
+
+  usag:
+
+  (sendmail
+    :host \"smtp.gmail.com\"
+    :user \"number23.cn@gmail.com\"
+    :password \"secret_password\"
+    :port \"587\"
+    :auth true
+    :ssl true
+    :debug false
+    :from \"number23.cn@gmail.com\"
+    :to [\"number23.cn@gmail.com\"]
+    :subject \"Sendmail by Clojure\"
+    :text \"Test\")
+
+  with Multipart:
+
+  (import 'javax.mail.internet.MimeMultipart)
+  (import 'javax.mail.internet.MimeBodyPart)
+
+  (let [mp (MimeMultipart.)
+        hp (MimeBodyPart.)]
+    (.setContent hp \"<H1>Hello Clojure</H1>\" \"text/html\")
+    (.addBodyPart mp hp)
+
+    (sendmail
+      :content mp
+      ...))"
+
+  [& m]
+  (let [mail (apply hash-map m)
+        props (java.util.Properties.)]
+
+    (doto props
+      (.put "mail.smtp.host" (:host mail))
+      (.put "mail.smtp.port" (:port mail))
+      (.put "mail.smtp.user" (:user mail ""))
+      (.put "mail.smtp.socketFactory.port"  (:port mail)))
+
+    (if (= (:auth mail false) true)
+      (do
+        (.put props "mail.smtp.auth" "true")
+        (if (= (:ssl mail) true)
+          (doto props
+            (.put "mail.smtp.starttls.enable" "true")
+            (.put "mail.smtp.socketFactory.fallback" "false")))))
+
+
+    (let [authenticator (proxy [javax.mail.Authenticator] []
+                          (getPasswordAuthentication
+                            []
+                            (javax.mail.PasswordAuthentication.
+                             (:user mail "") (:password mail ""))))
+
+          to (if (:to mail) (reduce #(str % "," %2) (:to mail)) nil)
+          cc (if (:cc mail) (reduce #(str % "," %2) (:cc mail)) nil)
+          bcc (if (:bcc mail) (reduce #(str % "," %2) (:bcc mail)) nil)
+
+          session (javax.mail.Session/getInstance props authenticator)
+          msg     (javax.mail.internet.MimeMessage. session)]
+
+      (if (= (:debug mail) true) (.setDebug session true))
+      (.setFrom msg (javax.mail.internet.InternetAddress. (:from mail)))
+
+      (if (= (:debug mail) true)
+        (.setRecipients msg
+                        (javax.mail.Message$RecipientType/TO)
+                        (javax.mail.internet.InternetAddress/parse bcc))
+        (do
+          (.setRecipients msg
+                          (javax.mail.Message$RecipientType/TO)
+                          (javax.mail.internet.InternetAddress/parse to))
+          (if cc (.setRecipients msg
+                                 (javax.mail.Message$RecipientType/CC)
+                                 (javax.mail.internet.InternetAddress/parse cc)))
+          (if bcc (.setRecipients msg
+                                  (javax.mail.Message$RecipientType/BCC)
+                                  (javax.mail.internet.InternetAddress/parse bcc)))))
+
+      (.setSubject msg (:subject mail))
+      (if (:text mail nil)
+        (.setText msg (:text mail))
+        (.setContent msg (:content mail)))
+      (javax.mail.Transport/send msg))))
+
+(defn fill-msg-content
+  "fill message content with text and files,
+  return java.mail.internet.MimeMultipart"
+
+  [^String text & files]
+  (let [mmp (javax.mail.internet.MimeMultipart.)
+        mbp (javax.mail.internet.MimeBodyPart.)
+        sbuf (StringBuilder.)]
+    (-> sbuf
+        (.append "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><pre>")
+        (.append text)
+        (.append "</pre></body></html>"))
+    (.setContent mbp (.toString sbuf) "text/html; charset=utf-8")
+    (.setHeader mbp "Content-Transfer-Encoding" "base64")
+    (.addBodyPart mmp mbp)
+
+    (letfn [(add-part [^String f]
+              (let [part (javax.mail.internet.MimeBodyPart.)]
+                (.attachFile part f)
+                (.setHeader part "Content-Transfer-Encoding" "base64")
+                (.addBodyPart mmp part)))]
+      (doseq [file files]
+        (when-let [x file]
+          (if (sequential? x)
+            (doseq [f x] (add-part f))
+            (add-part x)))))
+    mmp))

File src/org/clojars/number23/commons_lib/stacktrace.clj

View file
+(ns org.clojars.number23.commons-lib.stacktrace
+  (:use [clojure.repl :only (root-cause stack-element-str)]))
+
+(defn pst12
+  "Deprecated.  use with-err-str to get pst output
+
+  return a stack trace of the exception, to the depth requested.
+  If none supplied, uses the root cause of the most recent repl exception (*e),
+  and a depth of 12.
+
+  source code copy from clojure.repl.pst
+  "
+
+  ([] (pst12 12))
+  ([e-or-depth]
+     (if (instance? Throwable e-or-depth)
+       (pst12 e-or-depth 12)
+       (when-let [e *e]
+         (pst12 (root-cause e) e-or-depth))))
+  ([^Throwable e depth]
+     (let [s (StringBuilder.)]
+       (.append s (str (-> e class .getSimpleName) " "
+                       (.getMessage e)
+                       (when-let [info (ex-data e)] (str " " (pr-str info))) "\n"))
+       (let [st (.getStackTrace e)
+             cause (.getCause e)]
+         (doseq [el (take depth
+                          (remove #(#{"clojure.lang.RestFn" "clojure.lang.AFn"} (.getClassName %))
+                                  st))]
+           (.append s (str \tab (stack-element-str el) "\n")))
+         (when cause
+           (-> s
+               (.append "Caused by:\n")
+               (.append (pst12 cause (min depth
+                                          (+ 2 (- (count (.getStackTrace cause))
+                                                  (count st)))))))))
+       (str s))))

File src/org/clojars/number23/commons_lib/util.clj

View file
+(ns org.clojars.number23.commons-lib.util)
+
+(defn exit
+  "exit the program"
+  ([] (System/exit 0))
+  ([^Long code] (System/exit code)))
+
+(defn quit
+  "exit the program"
+  ([] (System/exit 0))
+  ([^Long code] (System/exit code)))

File src/org/clojars/number23_cn/commons_lib/core.clj

-(ns org.clojars.number23_cn.commons-lib.core)
-
-(defn -main
-  "Hello Clojure, I Love U"
-  [& args]
-  (println "Hello Clojure"))

File src/org/clojars/number23_cn/commons_lib/date.clj

-(ns org.clojars.number23_cn.commons-lib.date
-  (:import (java.util Calendar Date)))
-
-(defn get-Monday
-  "as name, return Monday"
-  [^Date d]
-  (let [cal (Calendar/getInstance)]
-    (.setTime cal d)
-    (let [dt (- (.get cal Calendar/DAY_OF_WEEK) 2)]
-      (.add cal Calendar/DATE (- dt))
-      (.getTime cal))))
-
-(defn cdts
-  "return current datetime string: yyyy-MM-dd HH:mm:ss"
-  []
-  (format "%1$tF %1$tT" (Date.)))

File src/org/clojars/number23_cn/commons_lib/io.clj

-(ns org.clojars.number23_cn.commons-lib.io
-  (:require [clojure.java.io :as io]))
-
-(defn ^String prompt-read
-  "return String
-  from http://thinkrelevance.com/blog/2008/09/16/pcl-clojure-chapter-3.html"
-  [^String prompt]
-  (print (format "%s: " prompt))
-  (flush)
-  (read-line))
-
-(defn y-or-n
-  "return true if input y, n return false
-  from http://thinkrelevance.com/blog/2008/09/16/pcl-clojure-chapter-3.html"
-  [^String prompt]
-  (= "y"
-     (loop []
-       (or
-        (re-matches #"[yn]" (.toLowerCase (prompt-read prompt)))
-        (recur)))))
-
-(defn prompt-re
-  "re is Pattern, return the match"
-  [^String prompt ^java.util.regex.Pattern re]
-  (loop []
-    (or
-     (re-matches re (prompt-read prompt))
-     (recur))))
-
-(defn processing-file
-  "process a file by line with func"
-  [file func]
-  (with-open [rdr (io/reader file)]
-    (doseq [line (line-seq rdr)]
-      (func line))))
-
-(defmacro with-err-str
-  "Evaluates exprs in a context in which *err* is bound to a fresh
-  StringWriter.  Returns the string created by any nested printing
-  calls."
-  [& body]
-  `(let [s# (new java.io.StringWriter)]
-     (binding [*err* s#]
-       ~@body
-       (str s#))))

File src/org/clojars/number23_cn/commons_lib/mail.clj

-(ns org.clojars.number23_cn.commons-lib.mail)
-
-(defn sendmail
-  "simple sendmail function by smtp protocol,
-  base on javax.mail, keys:
-  host, port, user, password,
-  auth, ssl,
-  debug,
-  from, to, cc, bcc,
-  subject, text, content
-
-  if debug is true, debug output, send to bcc only,
-  from is String, to, cc, and bcc is vec,
-  if text is setup, send text/plan msg
-  content is javax.mail.Multipart
-
-  usag:
-
-  (sendmail
-    :host \"smtp.gmail.com\"
-    :user \"number23.cn@gmail.com\"
-    :password \"secret_password\"
-    :port \"587\"
-    :auth true
-    :ssl true
-    :debug false
-    :from \"number23.cn@gmail.com\"
-    :to [\"number23.cn@gmail.com\"]
-    :subject \"Sendmail by Clojure\"
-    :text \"Test\")
-
-  with Multipart:
-
-  (import 'javax.mail.internet.MimeMultipart)
-  (import 'javax.mail.internet.MimeBodyPart)
-
-  (let [mp (MimeMultipart.)
-        hp (MimeBodyPart.)]
-    (.setContent hp \"<H1>Hello Clojure</H1>\" \"text/html\")
-    (.addBodyPart mp hp)
-
-    (sendmail
-      :content mp
-      ...))"
-
-  [& m]
-  (let [mail (apply hash-map m)
-        props (java.util.Properties.)]
-
-    (doto props
-      (.put "mail.smtp.host" (:host mail))
-      (.put "mail.smtp.port" (:port mail))
-      (.put "mail.smtp.user" (:user mail ""))
-      (.put "mail.smtp.socketFactory.port"  (:port mail)))
-
-    (if (= (:auth mail false) true)
-      (do
-        (.put props "mail.smtp.auth" "true")
-        (if (= (:ssl mail) true)
-          (doto props
-            (.put "mail.smtp.starttls.enable" "true")
-            (.put "mail.smtp.socketFactory.fallback" "false")))))
-
-
-    (let [authenticator (proxy [javax.mail.Authenticator] []
-                          (getPasswordAuthentication
-                            []
-                            (javax.mail.PasswordAuthentication.
-                             (:user mail "") (:password mail ""))))
-
-          to (if (:to mail) (reduce #(str % "," %2) (:to mail)) nil)
-          cc (if (:cc mail) (reduce #(str % "," %2) (:cc mail)) nil)
-          bcc (if (:bcc mail) (reduce #(str % "," %2) (:bcc mail)) nil)
-
-          session (javax.mail.Session/getInstance props authenticator)
-          msg     (javax.mail.internet.MimeMessage. session)]
-
-      (if (= (:debug mail) true) (.setDebug session true))
-      (.setFrom msg (javax.mail.internet.InternetAddress. (:from mail)))
-
-      (if (= (:debug mail) true)
-        (.setRecipients msg
-                        (javax.mail.Message$RecipientType/TO)
-                        (javax.mail.internet.InternetAddress/parse bcc))
-        (do
-          (.setRecipients msg
-                          (javax.mail.Message$RecipientType/TO)
-                          (javax.mail.internet.InternetAddress/parse to))
-          (if cc (.setRecipients msg
-                                 (javax.mail.Message$RecipientType/CC)
-                                 (javax.mail.internet.InternetAddress/parse cc)))
-          (if bcc (.setRecipients msg
-                                  (javax.mail.Message$RecipientType/BCC)
-                                  (javax.mail.internet.InternetAddress/parse bcc)))))
-
-      (.setSubject msg (:subject mail))
-      (if (:text mail nil)
-        (.setText msg (:text mail))
-        (.setContent msg (:content mail)))
-      (javax.mail.Transport/send msg))))
-
-(defn fill-msg-content
-  "fill message content with text and files,
-  return java.mail.internet.MimeMultipart"
-
-  [^String text & files]
-  (let [mmp (javax.mail.internet.MimeMultipart.)
-        mbp (javax.mail.internet.MimeBodyPart.)
-        sbuf (StringBuilder.)]
-    (-> sbuf
-        (.append "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><pre>")
-        (.append text)
-        (.append "</pre></body></html>"))
-    (.setContent mbp (.toString sbuf) "text/html; charset=utf-8")
-    (.setHeader mbp "Content-Transfer-Encoding" "base64")
-    (.addBodyPart mmp mbp)
-
-    (letfn [(add-part [^String f]
-              (let [part (javax.mail.internet.MimeBodyPart.)]
-                (.attachFile part f)
-                (.setHeader part "Content-Transfer-Encoding" "base64")
-                (.addBodyPart mmp part)))]
-      (doseq [file files]
-        (when-let [x file]
-          (if (sequential? x)
-            (doseq [f x] (add-part f))
-            (add-part x)))))
-    mmp))

File src/org/clojars/number23_cn/commons_lib/stacktrace.clj

-(ns org.clojars.number23_cn.commons-lib.stacktrace
-  (:use [clojure.repl :only (root-cause stack-element-str)]))
-
-(defn pst12
-  "Deprecated.  use with-err-str to get pst output
-
-  return a stack trace of the exception, to the depth requested.
-  If none supplied, uses the root cause of the most recent repl exception (*e),
-  and a depth of 12.
-
-  source code copy from clojure.repl.pst
-  "
-
-  ([] (pst12 12))
-  ([e-or-depth]
-     (if (instance? Throwable e-or-depth)
-       (pst12 e-or-depth 12)
-       (when-let [e *e]
-         (pst12 (root-cause e) e-or-depth))))
-  ([^Throwable e depth]
-     (let [s (StringBuilder.)]
-       (.append s (str (-> e class .getSimpleName) " "
-                       (.getMessage e)
-                       (when-let [info (ex-data e)] (str " " (pr-str info))) "\n"))
-       (let [st (.getStackTrace e)
-             cause (.getCause e)]
-         (doseq [el (take depth
-                          (remove #(#{"clojure.lang.RestFn" "clojure.lang.AFn"} (.getClassName %))
-                                  st))]
-           (.append s (str \tab (stack-element-str el) "\n")))
-         (when cause
-           (-> s
-               (.append "Caused by:\n")
-               (.append (pst12 cause (min depth
-                                          (+ 2 (- (count (.getStackTrace cause))
-                                                  (count st)))))))))
-       (str s))))

File src/org/clojars/number23_cn/commons_lib/util.clj

-(ns org.clojars.number23_cn.commons-lib.util)
-
-(defn exit
-  "exit the program"
-  ([] (System/exit 0))
-  ([^Long code] (System/exit code)))
-
-(defn quit
-  "exit the program"
-  ([] (System/exit 0))
-  ([^Long code] (System/exit code)))