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
:dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"] | |
[org.clojure/clojure-contrib "1.2.0-SNAPSHOT"] | |
[clj-oauth "1.1.0-SNAPSHOT"] | |
[com.twinql.clojure/clj-apache-http "2.0.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
struct edge { | |
vertex_t target; | |
weight_t weight; | |
edge(vertex_t arg_target, weight_t arg_weight) | |
: target(arg_target), weight(arg_weight) { } | |
}; |
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
;;; all code in this function lifted from the clojure-mode function | |
;;; from clojure-mode.el | |
(defun clojure-font-lock-setup () | |
(interactive) | |
(set (make-local-variable 'lisp-indent-function) | |
'clojure-indent-function) | |
(set (make-local-variable 'lisp-doc-string-elt-property) | |
'clojure-doc-string-elt) | |
(set (make-local-variable 'font-lock-multiline) t) |
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
#include <iostream> | |
#include <string> | |
#include <map> | |
using namespace std; | |
template <typename K, typename V, class C, class A> | |
ostream &operator<< (ostream &os, map<K,V,C,A> const& m) | |
{ | |
os << "{ "; |
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
;; Thanks to user alanlcode on StackOverflow | |
;; http://stackoverflow.com/questions/1341154/building-a-clojure-app-with-a-command-line-interface | |
(ns cmd-line-demo | |
(:gen-class) | |
(:use clojure.contrib.command-line)) | |
(defn -main [& args] | |
(with-command-line args | |
"Command line demo" |
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 bt {:left {:value 3} | |
:value 5 | |
:right {:left {:value 2} | |
:value :foo | |
:right {:left {:value :bar} | |
:value :quux | |
:right {:value 10}}}}) | |
(loop [bt bt | |
q (clojure.lang.PersistentQueue/EMPTY)] |
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 level-order [f tree] | |
(loop [to-do [tree]] | |
(if (empty? to-do) | |
:done | |
(do (dorun (map (comp f :value) to-do)) | |
(recur (mapcat (fn [{:keys [left right]}] (remove nil? [left right])) | |
to-do)))))) | |
(level-order println | |
{:value 1 |
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 file (File. "/tmp/outfile.dat")) | |
(def dos (-> file java.io.FileOutputStream. java.io.DataOutputStream.)) | |
(defn write-seqs [#^java.io.DataOutputStream dos] | |
(for [i (range 0 10)] | |
(.writeInt dos i))) | |
(write-seqs dos) |
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
""" | |
Given a sequence of stock prices, what are the 2 values to buy and sell such that loss is maximized? | |
""" | |
prices = [[1,6,0,4,9,0,10], | |
[1,2,3,4,5,6,7,8], | |
[15,1,2,3,4,5,6,7,0], | |
[7,3,9,5,2,1,4,14,16,17], | |
[291, 592, 116, 480, 861, 438, 333, 541, 505, 272], | |
[25, 679, 1, 493, 593, 579, 943, 258, 104, 997]] |
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
'xxyxxyxyx'.replace(/[xy]/g, function(c) { | |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | |
return v.toString(16); | |
}); |
OlderNewer