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
divs1210 / extrapolate.clj
Last active Aug 3, 2018
extrapolate: like iterate, but different
View extrapolate.clj
(defn extrapolate
"Returns a lazy seq produced by extrapolating `coll` with given rules.
On each iteration,
`gen-next` is called with the entire seq generated till this iteration
`shrink` is called with the extrapolated seq (`identity` by default)"
([gen-next coll]
(extrapolate gen-next identity coll))
([gen-next shrink coll]
(concat coll
(let [curr (volatile! (seq coll))]
divs1210 / ratios.clj
Last active Jul 29, 2018
Clojure ratios
View ratios.clj
;; clojure solution for
;; HN:
(defn rec [y z]
(- 108
(/ (- 815
(/ 1500 z))
(defn rec-list [N]
divs1210 / history.clj
Last active Feb 13, 2018
An Excercise in Time Travel
View history.clj
(ns history)
;; ===========================
(defn hatom
"Atom that remembers previous states."
(atom {:value x
:history ()}))
divs1210 /
Last active Dec 1, 2017
coroutines.js walkthrough


Channels & go

var c = chan();

go(function() {
  // async block
divs1210 / functional-core-async-bench.clj
Last active Nov 16, 2017
Benchmark for functional-core-async
View functional-core-async-bench.clj
(defn event [env type val]
(let [rc (chan)]
(>! (:queue @env)
{:type type :val val :rc rc :time (:now @env)})
(<! rc)))
(defn bench []
(let [n 100000
divs1210 /
Last active Jul 3, 2017
Dynamic Functional Control Flow Structures for Java
import java.util.*;
import java.util.concurrent.Callable;
import java.util.function.Function;
class SLIP {
* Keywords
public static final Object
_IF = new Object(),
divs1210 /
Last active Oct 27, 2019
helps escape the Python's clutch
import types
# Helpers
# =======
def _obj():
'''Dummy object'''
return lambda: None
_FILLER = _obj()
divs1210 / hmap.clj
Last active Feb 5, 2018
Immutable hashmap implemented as a Clojure macro
View hmap.clj
(ns hmap)
(defmacro hmap [& kvs]
"Returns an immutable hashmap.
Keys must be compile-time constants."
(if (even? (count kvs))
(let [tups (partition 2 kvs)
keys (mapv first tups)
kvs+ (concat kvs [::keys keys])]
`(fn [k#]
divs1210 / protocols.clj
Last active Apr 6, 2016
This works fine for some time, but then I start getting an exception saying: "No implementation of method: :search of protocol: #'some.thing/ISearchEngine found for class: some.thing.SearchEngine"
View protocols.clj
(defprotocol ISearchEngine
"Search the web"
(search [engine term] "Search the web for a single (one-word) term."))
(defrecord SearchEngine [url]
(search [this term]
(-> (str (:url this) term)
http/get deref :body)))
View day6.clj
(ns aoc.day6
(:require [clojure.core.reducers :as r]
[clojure.set :as cset]
[clojure.string :as s]))
(defn part-1-input []
(.trim (slurp "resources/day6-part1-input")))
(defn str->point
"(str->point \"0,0\") => [0 0]"
You can’t perform that action at this time.