Skip to content

Instantly share code, notes, and snippets.

: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"]])
struct edge {
vertex_t target;
weight_t weight;
edge(vertex_t arg_target, weight_t arg_weight)
: target(arg_target), weight(arg_weight) { }
};
@viksit
viksit / clojure-font-lock-setup.el
Created April 1, 2010 21:23 — forked from michalmarczyk/clojure-font-lock-setup.el
Integrating clojure-mode indentation and colors into slime
;;; 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)
#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 << "{ ";
;; 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"
(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)]
(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
(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)
"""
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]]
@viksit
viksit / uuid.js
Created March 22, 2011 18:06
Javscript generate UUID/GUID
'xxyxxyxyx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});