Skip to content

Instantly share code, notes, and snippets.

View danlentz's full-sized avatar

Dan Lentz danlentz

View GitHub Profile
@ichimal
ichimal / gist:3703328
Created September 12, 2012 00:44
self update map
(defun map-update (fun src &rest lists)
(funcall
(reduce (lambda (cont list-elms)
(lambda ()
(apply fun (funcall cont) list-elms) ))
(apply #'mapcar #'list lists)
:initial-value (constantly src) )))
(defun subst-all (to-list from-list src)
(map-update
@vaughnd
vaughnd / gist:3705861
Created September 12, 2012 10:40
Datomic user -> group memberships with extra data using many-to-many
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://user-groups3")
(d/create-database uri)
(def conn (d/connect uri))
(d/transact
conn
[{:db.install/_attribute :db.part/db
:db/id #db/id[:db.part/db]
:db/ident :user/name
@danlentz
danlentz / iterate.org
Created October 4, 2012 06:12
Iterate Clauses

Iterate Reference

ClauseOptionsDesc
INITIALLYLisp forms to execute before loop starts
AFTER-EACHLisp
@jaeschliman
jaeschliman / include.lisp
Created October 4, 2012 15:34
include an external file in a binary for later use, with shell transcript
;;
;; in the directory /tmp/include-binary/
;; containing a file foo.jpg, this file, and product.lisp
;;
;;
;; $ ls -la
;; total 768
;; drwxr-xr-x 5 user wheel 170 Oct 4 08:28 .
;; drwxrwxrwt 19 root wheel 646 Oct 4 08:25 ..
@guilespi
guilespi / run.clj
Created October 29, 2012 03:02
Running the QSTK tutorial in clojure
(defn run
[]
(let [symbols ["AAPL","GLD","GOOG","$SPX","XOM"]
start-day (date-time 2012 1 1)
end-day (date-time 2012 12 31)
time-of-day (hours 16)
timestamps (get-NYSE-days start-day end-day time-of-day)
symbols-data (read-symbols-data "Yahoo" symbols)
adj-close-data (incanter.core/to-dataset
(get-data timestamps symbols (keyword "Adj Close") symbols-data time-of-day))]
@guilespi
guilespi / qstk-tutorial1.clj
Created October 29, 2012 03:05
QSTK Tutorial 1 in Clojure
(ns qstk.tutorial1
(:use [clj-time.core :exclude 'extend])
(:use clj-time.format)
(:use clj-time.coerce)
(:require incanter.io)
(:require incanter.core))
(def ^{:dynamic true} *QS* (get (System/getenv) "QS"))
(defn get-NYSE-days
;; -*- mode:common-lisp -*-
(defun map-file (filename &rest flags)
"Maps FILENAME, returns the opened stream, base aligned address and length."
(let ((s (apply #'open filename :mapped t flags)))
(values s (slot-value s 'excl::buffer) (file-length s))))
;; Read unaligned little-endian numbers
(defun read-u8 (base off)
(sys:memref base off 0 :unsigned-byte))
(let [[message-seq put] (pipe)]
(letfn [(message-handler [ch msg-meta payload])
(put {:ch ch :msg-meta msg-meta :payload payload})]
(lc/subscribe ch qname message-handler :auto-ack true))
message-seq)
@vseloved
vseloved / listcomp.lisp
Last active May 30, 2020 04:27
List comprehensions with a syntax very close to set-theoretic notation
(defun read-listcomp (stream char)
(declare (ignore char))
(let (rezs srcs conds state)
(dolist (item (read-delimited-list #\} stream))
(if (eql '|| item)
(setf state (if state :cond :src))
(case state
(:src (push item srcs))
(:cond (push item conds))
(otherwise (push item rezs)))))
@danlentz
danlentz / actor.lisp
Created January 4, 2013 10:03 — forked from sile/actor.lisp
actor lib by quek
(in-package :actor)
(defparameter *current-process* (make-process :background nil))
(define-symbol-macro self *current-process*)
;; fork
(defun fork-impl (fn)
(let ((proc (make-process)))
(execute-fork-fn fn proc) ; forkしたプロセスを実行する
proc))