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 lcs [xr yr] | |
((fn inner-lcs [x y] | |
(cond | |
(or (zero? (count x)) (zero? (count y))) nil | |
(= (first x) (first y)) (cons (first x) (inner-lcs (rest x) (rest y))) | |
:else (let [xx (inner-lcs (rest x) y) | |
yy (inner-lcs x (rest y))] | |
(if (> (count xx) (count yy)) xx yy)))) xr yr)) | |
> (print "result:" (lcs "Stathis Georgiou Sideris" "Stathis Sideris") "\n") |
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
package test; | |
import java.util.HashMap; | |
public class HashOfHashes { | |
public static void main(String[] args) { | |
//deep's type is a HashMap with String keys. Its values are Hashes with String keys and values | |
//Notice how you have to say all that twice, just to be sure :-/ | |
HashMap<String, HashMap<String, String>> deep = new HashMap<String, HashMap<String, String>>(); |
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
;; Here is a spike of a lightweight in-process pubsub mechanism that allows pure ;; functional consumers, both blocking and asynchronous. | |
;; This defines the event stream, in this case just a series of numbers, | |
;; a new one produced each second | |
(defn timer [] | |
(lazy-seq | |
(do | |
(Thread/sleep 1000) | |
(cons (System/nanoTime) (timer))))) |
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 lcs.core) | |
;(def a [:a :b :b :c :d :e :f :z]) | |
;(def b [:a :b :b :d :e :f :g :a]) | |
(def a "abcabba") | |
(def b "cbabac") | |
(defn indexed [coll] (map vector (iterate inc 1) coll)) |
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
(require '[clojure.string :as string]) | |
(defn gget [grid [x y]] | |
(get-in grid [y x] \space)) | |
(defn gassoc [grid [x y] v] | |
(assoc-in grid [y x] v)) | |
(defn dimensions [grid] | |
[(apply max (map count grid)) (count grid)]) |
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 seq!! | |
"Returns a (blocking!) lazy sequence read from a channel." | |
[c] | |
(lazy-seq | |
(when-let [v (<!! c)] | |
(cons v (seq!! c))))) | |
(comment | |
(def stream (chan)) | |
(go (dotimes [x 16] |
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 binary.core | |
(:require [org.clojars.smee.binary.core :as b] | |
[clojure.java.io :as io] | |
[clojure.core.match :as m]) | |
(:import org.clojars.smee.binary.core.BinaryIO | |
java.io.DataInput)) | |
(defn fixed-string [len] | |
(b/string "ISO-8859-1" :length len)) |
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
;;see http://stackoverflow.com/questions/16215169/clojure-csv-with-escaped-comma | |
(require '[instaparse.core :as insta]) | |
((insta/parser | |
"quoted-field = <'\\\"'> (#'[^\"\\\\]+' | escaped-char)* <'\\\"'> | |
<escaped-char> = #'\\\\.'") "\"hello\\\" world\"") | |
;;and to parse comments like /** this is a test */ | |
;;http://stackoverflow.com/questions/11125459/java-regex-negative-lookahead |
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
alias ipext='curl -s http://checkip.dyndns.org/ | grep -o [0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*.[0-9]*' |
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 prewalkseq | |
"Like prewalk but only for seqs and uses zippers." | |
[f s] | |
(loop [z (zip/seq-zip s)] | |
(if (zip/end? z) | |
(zip/root z) | |
(recur (zip/next (zip/replace z (f (zip/node z)))))))) | |
;;replace zip/seq-zip with zip/vector-zip for vectors |
OlderNewer