Skip to content

Instantly share code, notes, and snippets.

View LispyAriaro's full-sized avatar

Efe Ariaroo LispyAriaro

  • London, United Kingdom
View GitHub Profile
(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"
(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))
@LispyAriaro
LispyAriaro / reverse-without-reverse.clj
Last active August 29, 2015 14:15
Reversing a list without using the reverse function
;;;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 []))))
@LispyAriaro
LispyAriaro / pi.clj
Last active August 29, 2015 14:15 — forked from bmabey/pi.clj
(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)
;;; (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)))
(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)))
(fn [lst]
(letfn [(my-fn [lst so-far]
(if (empty? lst)
so-far
(recur (rest lst) (inc so-far))))]
(my-fn lst 0)))
(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))
; 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 (andrzeje@cs.wisc.edu)
;
; Command-line arguments
;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?