Skip to content

Instantly share code, notes, and snippets.

@clifford
clifford / engine.c
Created October 30, 2019 10:06
Quant cup contest for fastest matching engine.
/*****************************************************************************
* QuantCup 1: Price-Time Matching Engine
*
* Submitted by: voyager
*
* Design Overview:
* In this implementation, the limit order book is represented using
* a flat linear array (pricePoints), indexed by the numeric price value.
* Each entry in this array corresponds to a specific price point and holds
* an instance of struct pricePoint. This data structure maintains a list
(ns reagent-test.core
(:require [reagent.core :as reagent :refer [atom]]
[datascript :as d]
[cljs-uuid-utils :as uuid]))
(enable-console-print!)
(defn bind
([conn q]
(bind conn q (atom nil)))
(def msgs [ {"a" {:stat1 1 :stat2 10} "b" {:stat1 1}} {"a" {:stat1 1}}])
(def merged (apply merge-with (partial merge-with +) msgs))
;; {"a" {:stat1 2, :stat2 10}, "b" {:stat1 1}}
(prn merged)
;; {"a" {:stat1 2, :stat2 10}, "b" {:stat1 1}}
(= (-> merged first second :stat1) 2)
;; true
(ns test.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :refer [<! chan put!]]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(def app-state (atom {:projects
[{:id 1 :title "proj 1"}
{:id 2 :title "proj 2"}
{:id 3 :title "proj 3"}
(ns test.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :refer [<! chan put!]]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(def aidc (chan))
;; Datomic example code
;; Demonstrates using datalog with Clojure defrecords
(use '[datomic.api :only [q db] :as d])
;;; http://www.lshift.net/blog/2010/08/21/some-relational-algebra-with-datatypes-in-clojure-12
(defrecord Supplier [number name status city])
(defrecord Part [number name colour weight city])
(defrecord Shipment [supplier part quantity])
;; sample data
@clifford
clifford / core.clj
Created October 2, 2012 18:05 — forked from ejackson/core.clj
Attempt at the problem
(ns timetable.core2
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]
[clojure.tools.macro]))
;; --------------------------------------------------------
;; Useful goals
(defne rembero
"Succeeds if out is the list l with the first instance of element x removed"
[x l out]
@clifford
clifford / gist:3486272
Created August 27, 2012 06:34 — forked from swannodette/gist:3217582
sudoku_compact.clj
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
@clifford
clifford / upsert-auto.clj
Created August 4, 2012 08:17 — forked from terjesb/upsert-auto.clj
Upserting in Datomic
(use '[datomic.api :only (q db) :as d])
(def initial-data
[{:sku "1" :price 0.95M :qty 1}
{:sku "2" :price 1.99M :qty 0}
{:sku "3" :price 1.99M :qty 0}
{:sku "4" :price 5.99M :qty 3}
{:sku "5" :price 9.99M :qty 2}
{:sku "6" :price 2.99M :qty 3}
{:sku "7" :price 2.99M :qty 2}])
@clifford
clifford / gist:3218713
Created July 31, 2012 17:25 — forked from swannodette/gist:3217582
sudoku_compact.clj
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [grid x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in grid [x y])))
(defn init [grid [pos value]]