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
(def urls (array "http://a.tile.openstreetmap.org/${z}/${x}/${y}.png" | |
"http://b.tile.openstreetmap.org/${z}/${x}/${y}.png" | |
"http://c.tile.openstreetmap.org/${z}/${x}/${y}.png")) | |
(def OSM (js/OpenLayers.Layer.XYZ. "OSM (with buffer)" urls (extend-object! (js-obj) {"transitionEffect" "resize" | |
"buffer" 2 | |
"wrapDateLine" true | |
"sphericalMercator" true}))) | |
(def plot (js/OpenLayers.Map. (extend-object! (js-obj) {"div" "plot" |
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
(ns cljs-minimal.core | |
(:require [cljs.core.async :as async :refer [put! <! >! <!! >!! chan]]) | |
(:require-macros [cljs.core.async.macros :as m :refer [go]])) | |
(defn get-position [] | |
(let [out (chan) | |
geo (.-geolocation js/navigator)] | |
(.getCurrentPosition geo (fn [pos] (put! out pos))) | |
out)) |
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
;;;puttin letfn to work | |
;;;reverse without the 'reverse' function | |
(fn[lst] | |
(letfn [(my-fun [lst so-far] | |
(if (empty? lst) | |
so-far | |
(recur (butlast lst) | |
(conj so-far (last lst)))))] | |
(println (my-fun lst [])))) |
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 calculate-pi | |
"Calculates Pi using the approximation 4 * (1 - 1/3 + 1/5 - 1/7 + ...)" | |
[iterations] | |
(let [odd-numbers (filter odd? (iterate inc 1))] | |
(* 4.0 | |
(apply + (map / (cycle [1 -1]) (take iterations odd-numbers)))))) | |
(println "calculated pi =" (calculate-pi 100000)) | |
(println "Math/PI =" Math/PI) |
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
;;; (a1)xb1 + (a2)xb2 + (a3)xb3 ......(an)xbn | |
; Enter your code here. Read input from STDIN. Print output to STDOUT | |
; | |
(defn my-round | |
[the-num num-dec-places] | |
(let [factor (Math/pow 10 num-dec-places)] | |
(/ (Math/round (* the-num factor)) factor))) |
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-fac [num] | |
(if (zero? num) | |
1 | |
(reduce * (range 1 (inc num))))) | |
(defn get-input [] | |
(let [num-tests (read-line) | |
num-tests-as-num (Integer/parseInt num-tests) | |
the-test-cases-as-num (for [a-case (range 0 num-tests-as-num)] | |
(Double/parseDouble (read-line))) |
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
(fn [lst] | |
(letfn [(my-fn [lst so-far] | |
(if (empty? lst) | |
so-far | |
(recur (rest lst) (inc so-far))))] | |
(my-fn lst 0))) |
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)) |
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
; Gotten from http://pages.cs.wisc.edu/~andrzeje/research/loc.clj | |
; Calculate lines of code contained in a given directory | |
; -ignores empty lines | |
; -ignores comment-only lines | |
; -does *not* ignore block comments | |
; | |
; David Andrzejewski ([email protected]) | |
; | |
; Command-line arguments |
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
;How to count all occurrences of 42? | |
(count (filter #{42} coll)) | |
;How to express count using reduce? | |
(defn my-count [coll] (reduce (fn [n _] (inc n)) 0 coll)) | |
;How to count all occurrences of 42 using reduce? | |
(reduce (fn [n _] (inc n)) 0 (filter #{42} coll)) | |
;Can you get rid of the filter? |
OlderNewer