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 bbalanced? [s] | |
"Is the provided string bracket balanced?" | |
(zero? (count (reduce (fn [v ch] | |
(if (= ch \[) | |
(conj v ch) | |
(if (= ch \]) | |
(if (= \[ (peek v)) | |
(pop v) | |
(conj v ch)) | |
v))) |
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 b-reduction | |
"Reduces a string to un-balanced left and right enclosing characters." | |
[s & {:keys [ls rs] :or {ls \[ rs \]}}] | |
(reduce (fn [v ch] | |
(if (= ch ls) | |
(conj v ch) | |
(if (= ch rs) | |
(if (= ls (peek v)) | |
(pop v) | |
(conj v ch)) |
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 b-balanced? [s] | |
"Is the provided string bracket balanced?" | |
(empty? (b-reduction s))))) |
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 b-closers | |
"Provides the 'brackets' necessary to close the given string." | |
[s & {:keys [ls rs] :or {ls \[ rs \]}}] | |
(map #(if (= ls %) rs ls) (b-reduction s))) |
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 str-b-balance | |
"Naive bracket balance in the provided string." | |
[s & {:keys [ls rs] :or {ls \[ rs \]}}] | |
(let [bc (b-closers s)] | |
(reduce (fn [st ch] | |
(if (= ls ch) (str ch st) (str st ch))) | |
s | |
bc))) |
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 cur-bpm | |
"Returns the BPM of the provided metronome 'm'. | |
The difference between two consecutive beats divided by 1000 to find the | |
number of seconds. 60 divided by this number to find the beats per minute." | |
[m] (Math/round (/ 60 (/ (- (m 2) (m 1)) 1000)))) | |
(def metro (metronome 89)) | |
(cur-bpm metro) | |
;;=> 89 |
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 overtone-clj-toys.binaural | |
(:use [overtone.live])) | |
;; | |
;; Binaural Beat Synthesis: | |
;; Generates binaural beats given the provided carrier and desired | |
;; frequency. Brown noise is used to soften the background and | |
;; block out outside noise. | |
;; freq effect |
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
;; for a key, return a list of values | |
(defn sc-values | |
"For a given seq of maps, returns all of the values associated with | |
the given key 'k'. " | |
[k maps] | |
(map (fn [x] (k x)) maps)) | |
(defn m-inverto | |
"invert maps, based on entries of first map, assumes uniform. | |
(m-inverto [{:a 1 :b 4 :c 3} {:a 2 :b 5} {:a 3 :b 6}]) |
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 locate-point | |
"Given a map of shapes see (process-shape-file), locate the entry that | |
contains the given lat/long, optionally filtered by keys." | |
([shapes long lat] (locate-point shapes lat long nil)) | |
([shapes long lat keys] | |
(let [locs (if keys (select-keys shapes keys) shapes) | |
point (.. JTSFactoryFinder (getGeometryFactory) | |
(createPoint (Coordinate. long lat))) | |
flocs (first | |
(filter (fn [x] |
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 geoloader.core | |
(:require [clojure.java.io :as io]) | |
(:import [com.vividsolutions.jts.geom Point Coordinate MultiPolygon] | |
[org.geotools.data.simple SimpleFeatureCollection SimpleFeatureIterator SimpleFeatureSource] | |
[org.geotools.data FileDataStore FileDataStoreFinder] | |
[org.geotools.geometry.jts JTSFactoryFinder] | |
[org.opengis.feature.simple SimpleFeature SimpleFeatureType] | |
[org.opengis.feature.type AttributeDescriptor AttributeType])) | |
OlderNewer