Skip to content

Instantly share code, notes, and snippets.

@samedhi
samedhi / maximalRectangle.py
Created November 22, 2020 17:28
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
samedhi / index.html
Created September 9, 2020 03:54
Failing case with core.async & klipse
<!doctype html>
<html lang="en">
<head>
<meta charset='utf-8'>
<link rel="stylesheet"
type="text/css"
href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
</head>
<pre>
<code class="language-klipse">
#!/usr/bin/env bb
;; --- CONSTANTS --
(def projects-directory "/home/samedhi/")
(def commit-to-video-config-filename ".commit-to-video.edn")
;; -- FILESYSTEM --
@samedhi
samedhi / finalizing-buffer.cljs
Created July 14, 2019 02:14
A buffer that will take a side effect when the channel containing it is closed.
(deftype FinalizingBuffer [buf n opts]
cljs.core.async.impl.protocols/Buffer
(full? [this]
(== (.-length buf) n))
(remove! [this]
(.pop buf))
(add!* [this itm]
(.unbounded-unshift buf itm)
this)
(ns io.github.samedhi.push
(:require
[clojure.string :as string]
[planck.shell :as shell]))
(def input-blog "/Users/stephencagle/blog")
(def output-blog "/Users/stephencagle/samedhi.github.io/")
(def now (:out (shell/sh "date" "-u" "+%FT%T%z")))
@samedhi
samedhi / download-conversion-issues.cljs
Last active January 25, 2019 16:22
I am having trouble converting the string returned by (ajax/text-response-format) into a js Blob
(re-frame/reg-event-fx
:download-file
(fn-traced
[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
samedhi / lru_cache.py
Last active January 7, 2019 05:16
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):
(ns example.test-utils
(:require
[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#
(ns example.silly
(:require
[clojure.spec.alpha :as spec]))
(spec/def ::integer int?)
(defn adder [a b]
(+ a b))
(spec/fdef adder
@samedhi
samedhi / gist:84a66d3c5a16d6a5e5381179b745e8b8
Last active September 4, 2018 15:24
How do I call with the proper testing library (clojure.test for clj and cljs.test for cljs)
;; test-utils.cljc
(ns inferno.test-utils
(:require
[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))