Skip to content

Instantly share code, notes, and snippets.

samedhi /
Created Nov 22, 2020
Evidently the most common question asked by google (reference Leetcode). I can only figure out a N^3 solution... :/
class Solution:
def __init__(self):
self.memoized = {}
self.call_count = 0
def areaPoints(self, point1, point2):
self.call_count += 1
i1, j1 = point1
i2, j2 = point2
offsets = [(r, c) for r in range(1 + i2 - i1)
samedhi / index.html
Created Sep 9, 2020
Failing case with core.async & klipse
View index.html
<!doctype html>
<html lang="en">
<meta charset='utf-8'>
<link rel="stylesheet"
<code class="language-klipse">
View run.clj
#!/usr/bin/env bb
;; --- CONSTANTS --
(def projects-directory "/home/samedhi/")
(def commit-to-video-config-filename ".commit-to-video.edn")
samedhi / finalizing-buffer.cljs
Created Jul 14, 2019
A buffer that will take a side effect when the channel containing it is closed.
View finalizing-buffer.cljs
(deftype FinalizingBuffer [buf n opts]
(full? [this]
(== (.-length buf) n))
(remove! [this]
(.pop buf))
(add!* [this itm]
(.unbounded-unshift buf itm)
View push.cljs
(ns io.github.samedhi.push
[clojure.string :as string]
[ :as shell]))
(def input-blog "/Users/stephencagle/blog")
(def output-blog "/Users/stephencagle/")
(def now (:out (shell/sh "date" "-u" "+%FT%T%z")))
samedhi / download-conversion-issues.cljs
Last active Jan 25, 2019
I am having trouble converting the string returned by (ajax/text-response-format) into a js Blob
View download-conversion-issues.cljs
[db [_ document-id filename]]
(let [{:keys [active-project-id]} db
uri (endpoint db "projects" "ddd5f5ae1a2b4c839b1665997b9a3628" "documents" document-id)]
{:http-xhrio {:method :get
:uri uri
:headers (auth-header db)
:response-format (ajax/text-response-format)
samedhi /
Last active Jan 7, 2019
LRU Cache (Leetcode) [Python 3]
class LRUCache:
def __init__(self, capacity):
:type capacity: int
assert(capacity >= 1)
self.d = {}
self.first_node = self.last_node = current_node = {}
for i in range(capacity-1):
View test_utils.clj
(ns example.test-utils
[clojure.spec.test.alpha :as spec.test]
[cljs.test :as test :include-macros true]))
(defmacro deftest-fdef [sym]
`(test/deftest ~(-> sym name (str "-test") symbol)
(let [[res#] (spec.test/check (quote ~sym))
{{result# :result :as ret#} :clojure.spec.test.check/ret} res#]
(-> ret#
View silly.cljs
(ns example.silly
[clojure.spec.alpha :as spec]))
(spec/def ::integer int?)
(defn adder [a b]
(+ a b))
(spec/fdef adder
samedhi / gist:84a66d3c5a16d6a5e5381179b745e8b8
Last active Sep 4, 2018
How do I call with the proper testing library (clojure.test for clj and cljs.test for cljs)
View gist:84a66d3c5a16d6a5e5381179b745e8b8
;; test-utils.cljc
(ns inferno.test-utils
[clojure.spec.test.alpha :as spec.test]
#?(:clj [clojure.test :as test]
:cljs [cljs.test :as test :include-macros true])))
(defmacro deftest-fdef [sym]
`(test/deftest ~(-> sym name (str "-test") symbol)
(let [[res#] (spec.test/check (quote ~sym))