Created
March 12, 2015 03:15
-
-
Save LispyAriaro/fe86cb76eb60002ac53b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn my-tokenize [sentence delimiters] | |
(let [the-regex (re-pattern | |
(clojure.string/join "|" delimiters))] | |
(clojure.string/split sentence the-regex))) | |
;;; C:\\Users\\ARIAROO\\Documents\\Projects\\Blackberry_OS6\\gidimoblackberry | |
(def proj-dir "C:\\Users\\ARIAROO\\Documents\\Projects\\Blackberry_OS6\\gidimoblackberry") | |
(defn my-file-lines-counter | |
([dir-path] | |
(my-file-lines-counter dir-path 0)) | |
([dir-path so-far] | |
(let [dir-contents (fs/list-dir dir-path) | |
full-dir-contents (map #(str dir-path File/separator %) | |
dir-contents) | |
the-files (filter #(fs/file? %) full-dir-contents) | |
the-dirs (filter #(fs/directory? %) full-dir-contents) | |
total-lines-in-files (reduce + (map get-file-num-lines the-files))] | |
(reduce #(if (fs/file? %2) | |
(+ so-far (get-file-num-lines %2)) | |
(my-file-lines-counter %2 so-far)) so-far | |
full-dir-contents)))) | |
;;; Get all the dirs and files | |
;;; add the total lines in all files in the dir | |
;;; if the num of dirs is > than zero | |
;;; go through all the dirs and recur | |
;;; else return the total num files | |
(defn get-file-num-lines [file-path] | |
(count (clojure.string/split (slurp file-path) #"[\r\n]+"))) | |
(def test-file "C:\\Users\\ARIAROO\\Documents\\Projects\\Blackberry_OS6\\gidimoblackberry\\CommunicationManager.java") | |
(defn get-first-sames [the-word] | |
(for [i (range 0 (.length the-word)) | |
:let [current (.charAt the-word i) | |
next (.charAt the-word (inc i))] | |
:while (or (== i 0) | |
(and (> (inc i) 0) | |
(= next current)))] | |
(.charAt the-word i))) | |
(defn my-shorten | |
([the-word] | |
(my-shorten the-word "")) | |
([what-left so-far] | |
(if (empty? what-left) | |
so-far | |
(let [what-left-indices (range 0 (count what-left)) | |
get-first-sames (fn [the-word] | |
(for [i what-left-indices | |
:while (or (== i 0) | |
(and (> (inc i) 0) | |
(== (nth (inc i) what-left) | |
(nth i what-left))))] | |
(str i))) | |
the-sames (clojure.string/join "" | |
(get-first-sames what-left)) | |
count-of-sames (.length the-sames)] | |
(if (== count-of-sames 1) | |
(recur (.substring 1 what-left) | |
(str so-far the-sames)) | |
(recur (.substring count-of-sames) | |
(str so-far (.substring the-sames 0 1) | |
count-of-sames))))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment