Skip to content

Instantly share code, notes, and snippets.

View jneira's full-sized avatar
:octocat:

Javier Neira jneira

:octocat:
View GitHub Profile
(defn backtracking [solution? explore node]
(if (solution? node) [node]
(mapcat
#(backtracking solution? explore %1)
(explore node))))
(defn in-range? [vec coords]
(boolean
(reduce #(and
(vector? %1)
(> (count %1) %2)
(%1 %2))
vec coords)))
(defprotocol TradeTax
(trade-tax [trade logic]))
(defprotocol Commission
(commission [trade logic]))
(defrecord Trade [ref-no account instrument principal tax-fees
unit-price quantity])
(defn calculate-tax [{:keys [principal]} logic]
(ns com.freiheit.clojure.appengine.appengine-local
(:use
[compojure.http routes servlet helpers]
clojure.contrib.test-is
compojure.server.jetty
[clojure.contrib def str-utils duck-streams])
(:require
[clojure.contrib.logging :as log])
(:import
[com.google.appengine.api.labs.taskqueue.dev LocalTaskQueue]
(ns mygae.core
(:gen-class :extends javax.servlet.http.HttpServlet)
(:use compojure.core
ring.util.servlet
ring.adapter.jetty)
(:require [compojure.route :as route]))
(defroutes example
(GET "/" [] "<h1>Hello World Wide Web</h1>")
(route/not-found "Page not found"))
(ns local-dev
"Tools for local development.
Enables the use of the App Engine APIs on the REPL and in a local Jetty instance."
(:use ring.adapter.jetty
[ring.middleware file file-info])
(:import [java.io File]
[java.util HashMap]
[com.google.apphosting.api ApiProxy ApiProxy$Environment]
[com.google.appengine.tools.development
ApiProxyLocalFactory
(ns alien-nums
(:require (clojure.contrib [combinatorics :as comb :only cartesian-product]
[seq-utils :as seq-utils :only indexed])))
(defn leading-zero? [lang num]
(= (first num) (first lang)))
(defn generate-nums [lang]
(when-let [lst (map list lang)]
(let [fcp #(map flatten
(define (member-of-2? a lst1 lst2)
(if (or (null? lst1) (null? lst2)) #f
(or
(and (eq? a (car lst1))
(or (eq? a (car lst2))
(member-of-2? a (list a) (cdr lst2))))
(member-of-2? a (cdr lst1) lst2))))
def ifM[B](t: => M[B], f: => M[B])(implicit a: Monad[M], b: A <:< Boolean): M[B] =
>>= ((x: A) => if (x) t else f)
type Instrument = String
type Account = String
type Quantity = BigDecimal
type Money = BigDecimal
import java.util.{Calendar, Date}
val today = Calendar.getInstance.getTime
case class Trade(ref: String, ins: Instrument, account: Account, unitPrice: Money,
quantity: Quantity, tradeDate: Date = today) {