Skip to content

Instantly share code, notes, and snippets.

@samedhi
samedhi / maximalRectangle.py
Created Nov 22, 2020
Evidently the most common question asked by google (reference Leetcode). I can only figure out a N^3 solution... :/
View maximalRectangle.py
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 Sep 9, 2020
Failing case with core.async & klipse
View index.html
<!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">
View run.clj
#!/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 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]
cljs.core.async.impl.protocols/Buffer
(full? [this]
(== (.-length buf) n))
(remove! [this]
(.pop buf))
(add!* [this itm]
(.unbounded-unshift buf itm)
this)
View push.cljs
(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 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
(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 Jan 7, 2019
LRU Cache (Leetcode) [Python 3]
View lru_cache.py
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
(: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#
View silly.cljs
(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 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
(: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))