There is nothing noble the human mind has ever hoped for or dreamed of that will not be fulfilled.
Tuesday, January 25, 2011
Splitting sentence with tags in Python and Clojure
I tried to have all my code here, however I was not able to get syntax-highlighting
right. I guess I would be needing help.
My Clojure code uses cons and lazy-seq ... and it is pretty easy to follow. The Python side is not complete... I leave that to you.
Wednesday, May 19, 2010
The New Nigeria
We are about entering into a dawn where power would not be controlled by the North or South but by the so-called minorities. And this new beginning may bring a lasting peace in some quarters. However, I see my country stumbling again because we have failed to address the fundamental problems facing this country: poverty and corruption. From what I have heard and gleaned from the press, our political class differs only in the color of their attire, and they don't mean well for this country. They have never articulated any sound program; on implementation that word has not entered their thought system. We are not prepared to live in the 21st century and we are not even disturbed that we are living in the stone age ....this is the fault of the led. They have never wielded the power in them because of mere tribal and religious differences. Those differences should instead unite us because we all share in poverty. We live it out every day and night.
When shall this land see the Promised Land, when shall we see beyond Iba and Suja? When shall we behave like other countries? I pray God that we would start today to make amend. Amen.
Tuesday, September 22, 2009
Managing Clojure project files
When I started off with clojure I had a difficult time figuring out how to use namespace in my applications. What I did was to create a little code that would be doing the dirt job for me while I concentrate my time in learning and practicing the real thing. It is more of interop thus imperative but it still has Clojure spirit.
(defn get-path [project-name]
(let [user-name (System/getProperty "user.name")
user-home (System/getProperty "user.dir")]
(str user-home "\\src\\" user-name "\\" project-name)))
;;make-folder: string -> true
;;consumes string , creates files and folders and return true.
(defn make-folder [project-name]
(let [ project-path (get-path project-name)
file (java.io.File. project-path)
user-home (System/getProperty "user.dir")
class-path (java.io.File. user-home "\\class")]
(when (and (.mkdirs file)(.mkdirs class-path))
(.createNewFile (java.io.File. (str file "\\" project-name ".clj") ))
(.createNewFile (java.io.File. (str file "\\" project-name "_utils.clj" )))
(.createNewFile (java.io.File. (str file "\\" project-name "_extra.clj" )))
)
)
)
;;write-extra: string file -> nil
;; write the string to the file
(defn write-extra [str file]
(with-open [write (java.io.PrintWriter. (java.io.FileWriter. file))]
(. write println str)))
;;process-path:vector -> nil
;;reads vectors and process path and words to be written to files.
(defn process-path [[file-name file-path]]
(let [goof (subs file-name 0 ( - (count file-name) 4))
count-char (count goof)
last-five-char (if ( < 5 count-char) goof (subs goof (- count-char 5) count-char ))
last-index (.lastIndexOf file-path "src")
extract (subs file-path (+ last-index 4) (count file-path))
extract (subs extract 0 (- (count extract) 4))
remake-extract (.replace extract \\ \.)]
(if (or (= "_utils" last-five-char)(= "_extra" last-five-char))
(write-extra (str "(ns\t" (.replace remake-extract \_ \-) ")") file-path) (write-extra (str "( ns " remake-extract "\n" "( :use\t" remake-extract "-extra" "\n\t" remake-extract "-utils ) )" ) file-path) )))
(defn make-proper [mcoll]
(doseq [file-vec mcoll]
(process-path [ (str (file-vec 0)) (str (file-vec 1))] )))
;; make-project: string -> nil
;; it consumes the name of your project, it should be more than five letters word
;;
(defn make-project [project-name]
(when (make-folder project-name)
(make-proper (apply hash-map (apply concat (map (fn [n] [ (.getName n) n])
(seq (.listFiles (java.io.File. (get-path project-name))))))))
))