Skip to content

Instantly share code, notes, and snippets.

Divyansh Prakash divs1210

Block or report user

Report or block divs1210

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View pascal.clj
(ns pascal)
(defn step [row]
(let [parents (partition 2 1 row)
new-row-middle (map (fn [[x y]]
(+ x y))
(concat [1] new-row-middle [1])))
(defonce pascals-triangle
View ordered_infix.rb
def ordered_infix(*nums_and_ops)
initial_val = nums_and_ops[0]
op_num_pairs = nums_and_ops.drop(1).each_slice(2).to_a
op_num_pairs.reduce(initial_val) do |accumulator, op_num_pair|
op, num = op_num_pair
accumulator.send(op, num)
ordered_infix 10, '/', 2, '-', 1, '*', 2
divs1210 / watch_db.cljs
Created Dec 14, 2018
Lightweight logging of db state changes for reagent/re-frame
View watch_db.cljs
(defn watch-db []
(add-watch re-frame.db/app-db :watcher
(fn [_ _ old-state new-state]
(let [[removed added] ( old-state new-state)]
(when (or removed added)
(println "=====\nRemoved:")
(cljs.pprint/pprint removed)
(println "Added:")
(cljs.pprint/pprint added))))))
divs1210 / data.edn
Created Nov 24, 2018
sample edn data
View data.edn
{:result 1}
divs1210 / lazy.rb
Last active Nov 13, 2018
Lazy Seqs in Ruby
View lazy.rb
# Abstract Class
# ==============
class ISeq
def first
def rest
def [](idx)
divs1210 /
Last active Nov 3, 2018
Dead Simple Multiline Lambdas for Python
def do(*body):
return body[-1]
# Example (Python 2)
# =======
map(lambda x: do(
print('x =', x),
x * x),
divs1210 / calculus.clj
Last active Sep 20, 2019
Calculus in Clojure
View calculus.clj
(ns calculus)
(defonce ^:const dx 0.00001M)
(defn df
"Returns the derivative of f."
(fn [x]
(/ (- (f (+ x dx)) (f x))
divs1210 / fork-join-recur.clj
Created Oct 11, 2018
Clojure fork-join example
View fork-join-recur.clj
(ns fork-join-recur
(:import [java.util.concurrent ForkJoinPool
ForkJoinWorkerThread ForkJoinTask RecursiveTask]))
;; API
;; ===
(def ^:dynamic ^ForkJoinPool *pool* (ForkJoinPool/commonPool))
(defmacro fork [& body]
`(let [^ForkJoinTask task# (proxy [RecursiveTask] []
You can’t perform that action at this time.