Skip to content

Instantly share code, notes, and snippets.

View lildata's full-sized avatar

Programming is fun lildata

View GitHub Profile
(ns async-tut1.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [goog.dom :as dom]
[goog.events :as events]
[cljs.core.async :refer [<! put! chan]])
(:import [goog.net Jsonp]
[goog Uri]))
(def wiki-search-url
"http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=")
@lildata
lildata / mapdb.clj
Created October 8, 2015 09:17 — forked from hideshi/mapdb.clj
This is hash map database written in Clojure. See also: http://d.hatena.ne.jp/hideshi_o/20121123/1353698397
;mapdb.clj
(ns db.mapdb
(:use
[clojure.contrib.duck-streams :only (reader)]
[clojure.java.io :only (writer)]
[clojure.string :only (split)]
[clojure.contrib.server-socket :only (create-server close-server)]))
(def database-file "/Users/hideshi/Dev/Clojure/db/dbfile")
def usd(amount) = Scale(Const(amount),One("USD"))
def stock(symbol) = Scale(Lookup(symbol),One("USD"))
def buy(contract, amount) = And(contract,Give(usd(amount)))
def sell(contract, amount) = And(Give(contract),usd(amount))
def zcb(maturity, notional, currency) = When(maturity, Scale(Const(notional),One(currency)))
def option(contract) = Or(contract,Zero())
def europeanCallOption(at, c1, strike) = When(at, option(buy(c1,strike)))
def europeanPutOption(at, c1, strike) = When(at, option(sell(c1,strike)))
def americanCallOption(at, c1, strike) = Anytime(at, option(buy(c1,strike)))
def americanPutOption(at, c1, strike) = Anytime(at, option(sell(c1,strike)))
@lildata
lildata / busy-cursor.clj
Created October 26, 2015 21:48 — forked from daveray/busy-cursor.clj
Clojure/Seesaw busy cursor example
(ns busy-cursor.core
(:use seesaw.core))
(defn long-running-task
[]
(Thread/sleep 5000)
"The result")
(defn run-task-with-busy-cursor
[c]
@lildata
lildata / table-test.clj
Created October 26, 2015 21:48 — forked from daveray/table-test.clj
Highlighting table rows with Seesaw
(ns table-test.core
(:use [seesaw core table swingx]))
; A predicate that decides whether a row should be highlighted
; adapter is an instance of JXTable.TableAdapter
; http://projects.joshy.org/projects/painterreview/swingx/org/jdesktop/swingx/JXTable.TableAdapter.html
(defn hl-predicate [renderer adapter]
; Highligh all rows where :age is over thirty
(> (.getValueAt adapter (.row adapter) 0) 30))
@lildata
lildata / jvm.md
Last active November 11, 2015 13:21

The JVM is a virtual stack machine

**BTW A stack computer is programmed with a reverse Polish notation instruction set.

All the bytecode is typed in the JVM

@lildata
lildata / gist:ae9dbe13b95dd228b580
Created November 11, 2015 18:17 — forked from daveray/gist:1055523
Async Workflows in Seesaw
(ns seesaw.async
(:use [seesaw core]))
; see http://dotnetslackers.com/articles/net/Programming-user-interfaces-using-f-sharp-workflows.aspx#1478
(defmacro async
"Macro that executes an async call (the first form), ignores its result, and the
executes the body normally."
[async-call & body]
`(~@(apply list (first async-call) `(fn [& args#] ~@body) (rest async-call))))
@lildata
lildata / fill-print-array.clj
Last active December 3, 2015 15:55
Fill & Print an array in clojure (is there a better way to do ??)
(def array (take 3 (partition 3 (partition 3 (iterate inc 1)))))
(doall (map #(doall (map println %)) array))
@lildata
lildata / clojure.core.comp.md
Last active December 12, 2015 21:58
clojure fn
(def strinc (comp str inc))
(strinc 3)
; => "4"