Skip to content

Instantly share code, notes, and snippets.

@davidvhill
davidvhill / decisionmodel.md
Last active April 18, 2021 15:24
Decision Model

My Decision Model

Goals

  1. Eliminate Decision Fatigue
  2. Increase Productivity

Strategies

  1. Offload routine decisions onto habits
  2. Offload non-routine decisions onto if/then rules
  3. Offload unclear decisions onto a timebox
@davidvhill
davidvhill / gist:c71ec05730994e5f1fb1f39b2dd57dd6
Last active September 21, 2020 14:45
Function with Retry
;; Returns a function with retries.
;; retries: num of retries
;; delay: delay between retries in milliseconds
;; f: function to apply
;; ef: error function, determines if f should be retried
;; f and ef should not throw Exceptions
(defn with-retry
[retries delay f ef]
(fn [& args]
@davidvhill
davidvhill / core.clj
Last active February 20, 2020 18:12
Clojure yield-on-cost report
(ns compound.core
(:gen-class))
;; items is :label, dividend rate, dividend growth rate
(def items [[:abbv 0.0504 0.209]
[:mo 0.07 0.10]
[:pru 0.0472 0.13]
[:abc 0.0178 0.10]
[:amp 0.0219 0.11]
[:cm 0.0521 0.036]
@davidvhill
davidvhill / numberize.clj
Created December 6, 2019 19:11
Numerizing Made Simple
(require '[clojure.edn :as edn])
;; props to didibus https://clojuredocs.org/clojure.core/num
(defn numberize
[value]
(edn/read-string value))
@davidvhill
davidvhill / davidvhill.clj
Last active May 20, 2019 20:51
Determine if all sequences are the same length
(ns davidvhill)
(defn same-length?
[seqs]
(->> seqs (map count)
(into #{})
count
(= 1)))
@davidvhill
davidvhill / changedetection.clj
Last active May 21, 2019 13:50
Spec'd beginning of Clojure based change detection
(ns tmpclj.changedetection
(:require [clojure.spec.alpha :as s])
(:gen-class))
(s/def ::dates (s/coll-of int?))
(s/def ::reds (s/coll-of float?))
(s/def ::greens (s/coll-of float?))
(s/def ::blues (s/coll-of float?))
(s/def ::nirs (s/coll-of float?))
(s/def ::swir1s (s/coll-of float?))
@davidvhill
davidvhill / compounding.py
Last active September 11, 2018 20:01
Compound interest function
""" Compute compound interest given a rate, period and periodic rate increase
Args:
start: starting number
periods: compounding period
rate_growth: compounding rate growth rate
rate: starting compounding rate
Returns:
Final compounded value
@davidvhill
davidvhill / firebird.py
Last active March 16, 2018 20:23
A Function I Am Proud Of
@entrypoint.command()
@click.option('--x', '-x', required=True)
@click.option('--y', '-y', required=True)
@click.option('--acquired', '-a', required=True)
@click.option('--number', '-n', required=False, default=2500)
def changedetection(x, y, acquired, number=2500):
"""Run change detection for a tile over a time range and save results to Cassandra.
Args:
x (int): tile x coordinate
@davidvhill
davidvhill / ants.clj
Created February 2, 2018 00:41 — forked from michiakig/ants.clj
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
@davidvhill
davidvhill / apply.py
Last active September 6, 2017 06:55
Some structure.
from datetime import datetime
import d2d.user
import d2d.user.search
import d2d.notifications.send
####################################################################
# Method 1, detach interface from implementation
# Indirectly reference dependencies from vals
####################################################################