Skip to content

Instantly share code, notes, and snippets.

View mdelaurentis's full-sized avatar

Mike DeLaurentis mdelaurentis

View GitHub Profile
@mdelaurentis
mdelaurentis / memotest.clj
Created March 7, 2018 15:51
Does clojure.core.memoize cache exceptions?
(ns memotest
(:require [clojure.core.memoize :as memo]) │
(:import [java.util Date])) │
(defn memo-test-impl [] │
(when (< 0.5 (rand))
;; Good
(try
(insert-a-batch …)
(publish-message {:type “redshift-connection”, :state “ok”, :client_id 3, :connection_id 123, :created-at “…”})
(catch DiskFullError e
(publish-message {”redshift-connection”, :state “error”, :client_id 3, “error-type “disk full”, :created-at "..."}))
(catch ConnectionError e
(publish-message {”redshift-connection”, :state “error”, :client_id 3, “error-type “connection error”, :created-at "..."})))
;; Bad
(defn make-user [first-name last-name email]
(cond-> {}
first-name (assoc :first-name first-name)
last-name (assoc :last-name last-name)
email (assoc :email email)))
EXPLAIN UPDATE
"25"
SET
"556" = "555",
"654" = "653",
"655" = "651",
"656" = "652",
"533" = "347"
FROM
"24"
(defprotocol Ageable
(age [this]))
(defprotocol Nameable
(get-name [this]))
(defrecord Person [first-name last-name birthday]
Ageable
(age [this]
@mdelaurentis
mdelaurentis / layout.py
Created March 14, 2013 19:37
Here are snippets from two files for the code review. A few things to note: PADE uses a Python library called numpy extensively to do fast computation on arrays (http://www.numpy.org/). I use a lot of vectorized functions, which means that functions and operators that look like they're working on scalars can also work on n-dimensional arrays. Fo…
"""Code for grouping samples together.
A layout is simply a list of collections of numbers. Each number
represents a a column number in the (feature x sample) table. Each of
the inner collections represents a group of samples that share the
same value of some attribute. So the whole layout represents some
grouping of samples.
For example, this layout represents four groups, each with three columns::
(let [total 1000
period 100
progress (lang/make-periodic-invoker
period
#(printf "So far we did %d, we are %3.2f%% complete.\n" % (* 100.0 (/ % 1.0 total))))]
(dotimes [ii total]
;; do some work / processing here
(progress))
(println "I'm all done"))
package com.whatever
import org.apache.commons.logging.LogFactory
class Foo {
private static final def LOG = LogFactory.getLog("com.whatever.Foo")
def var() {
LOG.debug("Some message")
if(table[i][k].contains(p.tail.substring(0,1)) &&
table[k+1][j].contains(p.tail.substring(1, 2))){
table[i][j] += p.head;
}
(ns your.programs.namespace
;; ...
(:use [swank/swank :as swank])
(defn main [& args]
;; ...
(swank/start-repl))