This file contains hidden or 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
| (def var-pattern #"\$\{(.+?)\}") | |
| (defn compile-var-subst-only-template-fn | |
| ([template data-symbol] | |
| (compile-var-subst-only-template-fn template data-symbol 0 (gensym))) | |
| ([template data-symbol start-pos sb-symbol] | |
| `(let [~sb-symbol (StringBuilder. )] | |
| ~@(loop [m (re-matcher var-pattern template) | |
| last-pos 0 | |
| expr-list []] |
This file contains hidden or 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
| ;; http://projecteuler.net/problem=2 | |
| (def fib | |
| (memoize | |
| (fn [n] | |
| (cond | |
| (= n 0) 1 | |
| (= n 1) 2 | |
| true (+ (fib (- n 1)) (fib (- n 2))))))) |
This file contains hidden or 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
| (def sqrt [n] | |
| (Math/sqrt n)) | |
| (defn find-max-factor [n] | |
| (let [max-range (long (Math/ceil (sqrt n)))] | |
| (loop [i max-range] | |
| (if (= 0 (mod n i)) | |
| (max i (/ n i)) | |
| (recur (- i 1)))))) |
This file contains hidden or 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 palindromic? [n] | |
| (let [straight (seq (str n)) | |
| reversed (reverse straight)] | |
| (= straight reversed))) | |
| (palindromic? 9009) ; true | |
| (palindromic? 909) ; true | |
| (palindromic? 1023) ; false |
This file contains hidden or 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
| ;;; First version | |
| (defmacro -<> [subject & body] | |
| `(let [~'<> ~subject] | |
| ~(if (empty? body) | |
| '<> | |
| `(-<> ~(first body) | |
| ~@(rest body))))) | |
| (-<> "asdf" | |
| (.length <>) |
This file contains hidden or 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
| (def var-pattern #"\$\{(.+?)\}") | |
| (def section-pattern #"@\{(\w+)(.*?)\}") | |
| (def section-tokens #"\S+") | |
| (def template-section-definitions (atom {})) | |
| (defn get-template-generator [name] | |
| (get @template-section-definitions name)) | |
| (defn def-template-section [section-name body-generator] |
This file contains hidden or 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
| $ -> | |
| $pref = $('#preference') | |
| $prefList = $('#preference_list') | |
| $favs = $('#favorites') | |
| $rank = $('#ranking') | |
| $rankList = $('#ranking_list') | |
| answers = {} | |
| favorites = [] | |
This file contains hidden or 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
| global = @ | |
| $ -> | |
| # γ’γγ« | |
| model = | |
| golds: 0 | |
| products: [] | |
| events: {} | |
| greeting: '' | |
| cart: {} |
This file contains hidden or 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
| $givenValue = 10 | |
| function testIfSupportingClosure(){ | |
| $givenValue = 4 | |
| { | |
| $givenValue = $givenValue + 1 | |
| echo "The givenValue is ${givenValue}." | |
| } | |
| } |
This file contains hidden or 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
| dupStr = (str, n) -> (str for _ in [1..n]).join('') | |
| testRegexp = (r, str, cnt) -> | |
| startTime = + new Date() | |
| for _ in [1..cnt] | |
| throw new Error("#{r} has matched!!") if str.match r | |
| finishTime = + new Date() | |
| finishTime - startTime |